设置部分:
LDI T2_MODEN,1111B ;定义时钟源为8/4M=2us,上升沿触发。
LDI T2_CON,1011B ;定义成脉冲宽度测量模式,T2GO=1,在触发沿来到时候开始计数
; LDI T2_MODEN,1111B ;定义时钟源为8/4M=2us,上升沿触发。
ORIM IE,0010B ;开T2中断
中断处理部分:
;*********************************
; T2中断处理
;*********************************
T2_INT:
STA ACC_BUF,00H
LDI IRQ,00H
; BA1 ?ENDINT
ANDIM IE,1011B ;关T1中断,防止在解码过程中出现错误。
LDA T2HH,07H
STA T2HH_BUF,00H
LDA T2HL,07H
STA T2HL_BUF,00H
LDA T2LH,07H
STA T2LH_BUF,00H
LDA T2LL,07H
STA T2LL_BUF,00H ;读起脉宽数值
SBI T2LL_BUF,08H ;判断时间是否在0.4ms~0.7ms之间,即00C8H-015EH之间
LDI TEMP2,0CH
SBC T2LH_BUF,00H
LDI TEMP2,00H
SBC T2HL_BUF,00H
LDI TEMP2,00H
SBC T2HH_BUF,00H
BNC ?ENDINT ;<0.4ms
SBI T2LL_BUF,0EH ;>0.4ms
LDI TEMP2,05H
SBC T2LH_BUF,00H
LDI TEMP2,01H
SBC T2HL_BUF,00H
LDI TEMP2,00H
SBC T2HH_BUF,00H
BNC ?BIT0 ;<0.7ms
SBI T2LL_BUF,07H ;判断时间是否在1.55ms~1.85ms之间,即0307H-039DH之间
LDI TEMP2,00H
SBC T2LH_BUF,00H
LDI TEMP2,03H
SBC T2HL_BUF,00H
LDI TEMP2,00H
SBC T2HH_BUF,00H
BNC ?ENDINT ;<1.55ms
SBI T2LL_BUF,0DH ;>1.55ms
LDI TEMP2,09H
SBC T2LH_BUF,00H
LDI TEMP2,03H
SBC T2HL_BUF,00H
LDI TEMP2,00H
SBC T2HH_BUF,00H
BNC ?BIT1 ;<1.85ms
; LDI IR0L,00H ;非0,非1,则清code
; LDI IR0H,00H
; LDI IR1L,00H
; LDI IR1H,00H
; LDI IR2L,00H
; LDI IR2H,00H
; LDI IR3L,00H
; LDI IR3H,00H
JMP ?ENDINT
?BIT0:
; LDI TEMP3,00H
; ADI TEMP3,00H ;清除C值
LDA IR0L,00H
ADDM IR0L,00H
LDA IR0H,00H
ADCM IR0H,00H
LDA IR1L,00H
ADCM IR1L,00H
LDA IR1H,00H
ADCM IR1H,00H
LDA IR2L,00H
ADCM IR2L,00H
LDA IR2H,00H
ADCM IR2H,00H
LDA IR3L,00H
ADCM IR3L,00H
LDA IR3H,00H
ADCM IR3H,00H
ANDIM IR0L,1110B
JMP ?JDDATA
?BIT1:
; LDI TEMP3,00H
; ADI TEMP3,00H ;清除C值
LDA IR0L,00H
ADDM IR0L,00H
LDA IR0H,00H
ADCM IR0H,00H
LDA IR1L,00H
ADCM IR1L,00H
LDA IR1H,00H
ADCM IR1H,00H
LDA IR2L,00H
ADCM IR2L,00H
LDA IR2H,00H
ADCM IR2H,00H
LDA IR3L,00H
ADCM IR3L,00H
LDA IR3H,00H
ADCM IR3H,00H
ORIM IR0L,0001B
JMP ?JDDATA
?JDDATA:
LDA IR0L,00H
STA TEMP2,00H
EORIM TEMP2,1111B
SUB IR1L,00H
BNZ ?ENDINT
LDA IR0H,00H
STA TEMP2,00H
EORIM TEMP2,1111B
SUB IR1H,00H
BNZ $+2
JMP ?GETIRCODE
; LDI IR0L,00H ;非0,非1,则清code
; LDI IR0H,00H
; LDI IR1L,00H
; LDI IR1H,00H
; LDI IR2L,00H
; LDI IR2H,00H
; LDI IR3L,00H
; LDI IR3H,00H
; JMP ?ENDINT ;GET IRCODE
?GETIRCODE:
LDA IR1L,00H
STA IRCODEL,00H
LDA IR1H,00H
STA IRCODEH,00H
ORIM FLAG,0001B ;FLAG,0, REMOTE ok
JMP ?ENDINT
?ENDINT:
ANDIM IRQ,1101B
ORIM IE,0100B
ORIM IE,0010B ;开T2,开T1
; ORIM T2_CON,1000B
LDA ACC_BUF,00H
RTNI
这个就是相关部分的代码的。
帮我看看怎么回事? |