éä½ ä¸ä¸ªæç¼åçé¥æ§å¨æ§å¶çæµæ°´çè±æ ·,ä½ è¦çè±æ ·é½æ,è¿ææ´å¤å°.
IRCOM EQU 20H ;20H-23H IRä½¿ç¨ IRIN EQU P3.2
D1 EQU 30H ;æµæ°´ç¯ç§»ä½æ°ç¼å
D2 EQU 31H
;--------------------------------------------------------------------------------
ORG 0000H
AJMP MAIN
ORG 0003H ;å¤é¨ä¸æINT0å
¥å£å°å
AJMP IR_IN
;--------------------------------------------------------------------------------
MAIN:
MOV SP,#60H
MOV PSW,#00H
MOV A,#00H
MOV 20H,#00H
MOV 21H,#00H
MOV 22H,#00H
MOV 23H,#00H
mov 30h,#00h
mov 31h,#00h
MOV IE,#81H ;å
许æ»ä¸æä¸æ,ä½¿è½ INT0 å¤é¨ä¸æ
MOV TCON,#01H ;触åæ¹å¼ä¸ºèå²è´è¾¹æ²¿è§¦å
SETB IRIN
loop1: mov p0,#00h
loop:
MOV A,b
JZ loop1 ;å¼æºæ é¥æ§æé®æä¸ç¹äº®ææäºæ管
RL A ;å®ç°1~8åä¹(å1å2,2å4....)
MOV DPTR,#TAB_KEY
NOP
JMP @A+DPTR ;æ£è½¬
TAB_KEY: AJMP LOOP
AJMP TAPE1
AJMP TAPE2
AJMP TAPE3
AJMP TAPE4
AJMP TAPE5
AJMP TAPE6
AJMP TAPE7
AJMP TAPE8
;------------------以ä¸ä¸ºè±æ ·ç¯æ¾ç¤ºæ ·å¼--------------------TAPE1: MOV D1,#08H ;åç¯ç¹äº®å³ç§»
MOV A,#0FEH
QQ0: MOV P0,A
ACALL YS
RL A
DJNZ D1,QQ0
ajmp loop
TAPE2: MOV D1,#08H ;åç¯ç¹äº®å·¦ç§»
MOV A,#7FH
QQ1: MOV P0,A
ACALL YS
RR A
DJNZ D1,QQ1
ajmp loop
TAPE3: MOV D1,#08H ;æç¹å³ç§»
MOV A,#01H
QQ2: MOV P0,A
ACALL YS
RL A
DJNZ D1,QQ2
ajmp loop
TAPE4: MOV D1,#08H ;æç¹å³ç§»
MOV A,#80H
QQ3: MOV P0,A
ACALL YS
RR A
DJNZ D1,QQ3
ajmp loop
TAPE5: MOV D1,#08H ;亮ç¹å³å·¦å¾è¿æµå¨
MOV D2,#08H
MOV A,#0FEH
QQ4: MOV P0,A
ACALL YS
RL A
DJNZ D1,QQ4
AJMP NBA
NBA: RR A
MOV P0,A
ACALL YS
DJNZ D2,NBA
ajmp loop
TAPE6: MOV R5,#00H ;å
¨äº®ååå³æª«é¤,åå·¦ç¹äº®
QQ5: INC R5
MOV A,R5
MOV DPTR, #NU_TAB1
MOVC A,@A+DPTR
MOV P0,A
ACALL YS
ACALL YS
CJNE R5,#11H,QQ5
ajmp loop
NU_TAB1: DB 00H
DB 00H,01H,03H,07H,0FH,1FH,3FH,7FH,0FFH
DB 7FH,3FH,1FH,0FH,07H,03H,01H,00h
TAPE7: MOV R5,#00H ;模æéååå·¦ç»è¿æ¾ç¤ºçªå£
QQ7: INC R5
MOV A,R5
MOV DPTR, #NU_TAB2
MOVC A,@A+DPTR
MOV P0,A
ACALL YS
CJNE R5,#0FH,QQ7
ajmp loop
NU_TAB2: DB 00H
DB 7FH,0BFH,5FH,0AFH,57H,0ABH,55H,0AAH,0D5H
DB 0EAH,0F5H,0FAH,0FDH,0FEH,0FFH
TAPE8: MOV R5,#00H ;å
¨äº®åä»ä¸¤ç«¯å¾ä¸é´æ¦,åä»ä¸¤ç«¯å¾ä¸é´ç¹äº®
QQ9: INC R5
MOV A,R5
MOV DPTR, #NU_TAB3
MOVC A,@A+DPTR
MOV P0,A
ACALL YS
CJNE R5,#10H,QQ9
ajmp loop
NU_TAB3: DB 00H
DB 00H,81H,0C3H,0E7H,0FFH,0E7H,0C3H,81H,00H
DB 81H,0C3H,0E7H,0FFH,0E7H,0C3H,81H
;----------------------------ç¯ç¹äº®å»¶æ¶---------------------
YS: MOV R7,#250 CBA: MOV R6,#250
DJNZ R6,$
DJNZ R7,CBA
RET
; IR è¯ç åç¨åº
;--------------------------------------------------------------------------------
IR_IN:
CLR EA ;ææ¶å
³éCPUçææä¸æ请æ±
PUSH ACC
PUSH PSW
SETB PSW.3 ;éæ©å·¥ä½å¯åå¨ç»1
CLR PSW.4
MOV R2,#04H
MOV R0,#IRCOM
I1: JNB IRIN,I2 ;çå¾
IR ä¿¡å·åºç°
DJNZ R2,I1
JMP IR_OUT ;IRä¿¡å·æ²¡åºç°ï¼éåºã
I2: MOV R4,#20
I20: CALL DEL
DJNZ R4,I20
JB IRIN,I1 ;确认IRä¿¡å·åºç°
I21: JB IRIN,I3 ;循ç¯çIRå为é«çµå¹³ ;åé«å°±è¿äº9MSä½çµå¹³å¼å¯¼åº
CALL DEL
JMP I21
I3: MOV R3,#0 ;8ä½æ°æ¸
为0
LL: JNB IRIN,I4 ;çIRå为ä½çµå¹³,åä½å°±è¿äº4.5MSç»æç
CALL DEL
JMP LL
I4: JB IRIN,I5 ;ç IR å为é«çµå¹³ï¼è¿äº0æ1ç0.56MSä½çµå¹³åº
CALL DEL
JMP I4
I5: MOV R2,#0 ;0.14ms 计æ°
L1: CALL DEL ;çé«çµå¹³ä¿ææ¶é´,å³å 个0.14MS
;"0"ä¸è¶
è¿(1.125-0.56)/0.14=4个
;"1"è³å°æ(2.25-0.56)/0.14=12个
JB IRIN, N1 ;ç IR å为é«çµå¹³
;IR=0ï¼æ£æ¥R2ä¸ç计æ°å¼
MOV A,#8
CLR C
SUBB A,R2 ;å¤æé«ä½ä½,R2å°äº8,C=0,R2大äº8,C=1
;å5,6,7,8,9,10,11é½å¯,ä¸é´æ°æä¿é©
;è¥C=0说æR2å°äº8,说ææ¶å°çæ¯"0"ä½
;è¥C=1说æR2大äº8,说ææ¶å°çæ¯"1"ä½
MOV A,@R0 ;R0=20H已被æ¸
0,åA=0
RRC A ;RRCåAå
被ä¸ä½ä¸ä½Cæ¿ä»£äº,ä½ä½æ¯ç¬¬ä¸ä¸ªCçå¼
MOV @R0,A ;å¤çå®ä¸ä½,ææ¶åå°20H
INC R3
CJNE R3,#8,LL ;éå¤çå®8ä½,1,2,3,4,5,6,7,8ä½æ¾å
¥20H,第8ä½æ¯æé«ä½
MOV R3,#0
INC R0 ;æ¢ç¼å21H,22H,23H,ä¸ä¸ªç¼åå8ä½0,1ç»å
CJNE R0,#24H,LL ;æ¶éå°4åèäºå¦(ç¨æ·åç =21H,é®ç =22H,é®åç =23H)
JMP IR_COMP ;è·³åºåå¤å¤ççº é
N1: INC R2
CJNE R2,#30,L1 ;0.14ms计æ°è¿é¿åæ¶é´å°èªå¨ç¦»å¼
IR_OUT: POP PSW POP ACC
SETB EA
RETI
;--------------------------------------------------------------------------------
;é®å¼æ¯è¾ä¸é®å¼æ°æ®å¤ç
;22Håå
¥é®ç ï¼23Håå
¥é®ç çåç
;--------------------------------------------------------------------------------
IR_COMP:
;MOV A,20H
;XRL A,#00H ;ä¸åé¥æ§å¨ç¨æ·ç ä¸åç,å ä¸æ¯è¾é¥æ§å°±ä¸ç¨äº
;JNZ,IR_OUT
;MOV A,21H
;XRL A,#0DFH ;åä¸,åä¿é©
;JNZ IR_OUT
MOV A,22H
CPL A
XRL A,23H ;å°22Håååå23Hæ¯è¾
JNZ IR_OUT ;å¦æä¸ç表示æ¥æ¶æ°æ®åçé误,æ¾å¼
MOV R1,#08H ;åªç¨é¥æ§ç8个æé®,çæä¸çæé®æ¯ç¬¬å 个
MOV DPTR,#TAB_REMOT ;æéæåé¥æ§é®å¼è¡¨
LOOKUP:
MOV A,R1
MOVC A,@A+DPTR
XRL A,22H
JZ REMBAK
DJNZ R1,LOOKUP
REMBAK:
MOV b,R1
nop
sjmp ir_out
;-------------------------é¥æ§é®å¼è¡¨---------------------------------------------
TAB_REMOT: ;å
¶ä»6221/6222é¥æ§å¨è¦å
æµç 建ç«æ¤è¡¨
DB 00H
DB 10H,03H,01H,06H
DB 09H,1DH,1FH,0DH ;åªç¨é¥æ§ä¸æ8个æé®
;================================
;DT9122D é¥æ§å¨ï¼ä¼çº³çµåï¼
;****** 红å¤é¥æ§å¨é®å¼è¡¨ ******
; 10 03 01 06; 09 1D 1F 0D
; 19 1B 11 15
; 17 12 16 4C
; 40 48 04 00
; 02 05 54 4D
; 0A 1E 0E 1A
; 1C 14 0F 0C
;================================
;--------------------------------------------------------------------------------
; DELAY R5*0.14MS
DEL:
MOV R5,#1 ;IR解ç 使ç¨
DEL0: MOV R6,#2
DEL1: MOV R7,#32
DEL2: DJNZ R7,DEL2
DJNZ R6,DEL1
DJNZ R5,DEL0
RET
;--------------------------------------------------------------------------------
DELAY1: ;æ°ç 管延æ¶4MS
MOV R6,#20 DL2: MOV R7,#100
DJNZ R7,$
DJNZ R6,DL2
RET
温馨提示:内容为网友见解,仅供参考