list p=16f876
#include
;--------------------------
;定时计数单元
HW_TIME EQU 0X40
;-----------------------------
;定时常数
HW_TIMECT0 EQU 0XDF;TMR0定时器时间常数,载波信号频率37.88KHz(13.2us)
HW_TIMECT1 EQU 0X64;发送信号位间隔,*(1.32ms)
HW_TIMECT3 EQU 0X31;
;-------------------------------------
ORG 0X00
GOTO HW_RECEIVE
;------------------------------------
ORG 0X04
GOTO INT
;---------------------------------------
bcf INTCON,GIE
BCF INTCON,T0IF ;(T0IF)定时器溢出标志位清零
BCF INTCON,T0IE ;关TMR0中断(T0IE)位清零
BANKSEL OPTION_REG
CLRF OPTION_REG
BANKSEL HW_TIME
MOVLW HW_TIMECT3
MOVWF HW_TIME
MOVLW HW_TIMECT0
MOVWF TMR0
BANKSEL INTCON
BSF INTCON,T0IE
BSF INTCON,GIE
INT;中断
movwf W_TEMP
movf STATUS,0
bcf STATUS,RP0;working in bank0
movwf STATUS_TEMP
MOVLW HW_TIMECT0
MOVWF TMR0 ;重装定时常数
BCF INTCON,T0IF ;清除中断溢出标志位(T0IF)
;----------------------------------------------------------------------
DECFSZ HW_TIME,1 ;为零,间跳,定时时间到
GOTO HW_LEAVE1
MOVLW HW_TIMECT1 ;重装时间常数
MOVWF HW_TIME
BSF HW_Sign,1
HW_LEAVE1
BANKSEL STATUS_TEMP
MOVF STATUS_TEMP,0
MOVWF STATUS
MOVF W_TEMP
RETFIE