微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > AT89C2051单片机红外遥控学习器源程序

AT89C2051单片机红外遥控学习器源程序

时间:03-12 来源:互联网 点击:

源程序

ORG 0000H
AJMP MAIN
ORG 0003H
AJMP KEYPRESS
ORG 000BH
AJMP TIMEOUT
ORG 001BH
AJMP TIMEOUT

SENDDUAN BIT P3.0
JIEDUAN BIT P3.1
INTRPO BIT P3.2
JIEXUAN BIT P3.3
SENDLIGHT BIT P3.4
JIELIGHT BIT P3.5
CS BIT P3.7
DATADUAN BIT P1.6
CLK BIT P1.7
JIANWEI EQU R5
JIANMA EQU R6
SHANGJIAN EQU 07H;R7
OPENKEY EQU 81H
CLOSEKEY EQU 00H
CHUT0 EQU 11H
CHUT1 EQU 11H
BUFBEGIN EQU 18H
OPENT1 EQU 88H
CLOSET1 EQU 00H
OPENT0 EQU 82H
CLOSET0 EQU 00H
DATABEG1 EQU 0AAH
DATABEG2 EQU 33H

ORG 0030H
MAIN: MOV IE,#80H
MOV IP,#00H
MOV P3,#0FFH
CLR CS
SETB P1.0
SETB P1.1
SETB P1.2
CLR P1.3
CLR P1.4
CLR P1.5
CLR P1.6
CLR P1.7

MOV R3,#80H
MOV R0,00H
CYCLE1: MOV @R0,#00H
INC R0
DJNZ R3,CYCLE1

MOV PSW,#00H
MOV SP,#07H

MOV TMOD,#11H
MOV TCON,#00H

START: MOV SP,#07H
SETB SENDDUAN
CLR F0
SETB EXO
WAITKEY: MOV C,F0
JNC WAITKEY
CJNC JIANMA,#1BH,SEND
LCALL LEARNP
LJMP START
SEND: LCALL SENDP
LJMP START

SENDP: SETB SENDDUAN
CLR F0
MOV TMOD,#CHUT1
CLR SENDLIGHT
MOV A,JIANMA
CJNE A,SHANGJIAN,SAME
SAME: MOV R0,#BUFBEGIN
CLR TR1
LJMP NEXT3
RETURN: CLR ET1
SETB SENDDUAN
SETB SENDLIGHT
CLR F0
LCALL DELAY
RET
NEXT3: CPL F0
JB F0,SEND1
SEND0: CLR C ;1
MOV A,#0FFH
SUBB A,@R0
MOV R2,A ;1
INC R0 ;1
MOV A,#0FFH ;1
SUBB A,@R0 ;1
MOV R3,A
INC R0
CLR C
MOV A,#4FH
ADDC A,R2
MOV R2,A
MOV A,R3
ADDC A,#00H
MOV R3,A
MOV TL1,R2
MOV TH1,R3
SETB TR1 ;1
SETB ET1 ;1
SEND1: CLR C
MOV A,#0FFH
SUBB A,@RO
MOV TL1,A
INC R0
MOV A,#0FFH
SUBB A,@R0
MOV TH1,A
INC R0
SETB TR1
SETB ET1
NEXT6: CLR SENGGUAN
MOV R3,#03H
NEXT4: DJNZ R3,NEXT4
SETB SENDDUAN
MOV R3,#07H
NEXT5: DJNZ R3,#NEXT5
SJMP NEXT6

TIMA1OUT: CLR ET1 ;2
CLR TR1 ;2
SETB SENDDUAN ;1
CJNE@R0,#DATABEG2,TIM1NT2
MOV DPTR,#RETURN ;2
MOV R1,SP ;2
MOV @R1,DPH ;2
DEC R1 ;1
MOV @R1,DPL ;2
RETI ;2
TIM1NET2: DEC R0
TIM1NET1: CPL F0 ;1
JB F0,SEND11 ;2
SEND00: MOV DPTR,#SENDO ;11
MOV R1,SP
MOV @R1,DPH
DEC R1
MOV @R1,DPL
RETI
SEND11: MOV DPTR,#SEND1 ;11
MOV R1,SP
MOV @R1,DPH
DEC R1
MOV @R1,DPL
RETI
LEARNP: MOV R2,#02H
NEXT91: MOV R3,#0FFH
NEXT81: MOV R4,#0FFH
NEXT71: DJNZ R4,NEXT71
DJNZ R3,NEXT81
GJNZ R2,NEXT91
CLR F0
SETB EX0
MOV R2,#0AH
MEXT9: MOV R3,#0FFH
NEXT8: MOV R4,#0FFH
NEXT7: JB F0,NEXT10
DJNZ R4,NEXT7
DJNZ R3,MEXT8
DJNZ R2,NEXT9
CLR EX0
RET
NEXT10: CJNE JIANMA,#1BH,NEXT11
LJMP NEXT111
NEXT11: RET
NEXT111: CLR JIELIGHT
CLR JIEXUAN
CLR F0
MOV R0,#BUFBEGIN
SETB ET0
MOV TCON,#00H
MOV TMOD,#CHUT0
MOV TL0,#00H
MOV TH0,#00H
MOV R2,#02H
NEXT92: MOV R3,#0FFH
NEXT82: MOV R4,#0FFH
NEXT72: DJNZ R4,NEXT72
DJNZ R3,NEXT82
DJNZ R2,NEXT92
CLR TR0
L1: MOV C,JIEDUAN
JC L1
L4: SETB TR0
L2: MOV C,JIEDUAN
CLR TR0
MOV @R0,TL0
INC R0
MOV TH0,#00H
MOV TL0,#00H
L6: SETB TR0
L3: MOV C,JIEDUAN
JC L3
CLR TR0
CLR C
MOV A,TL0
ADDC A,#13H
MOV @R0,A
INC R0
MOV TH0,#00H
MOV TL0,#00H
SETB TR0
L5: MOV C,JIEDUAN
JNC L5
CLR TR0
CLR C ;1
MOV A,TL0 ;1
ADDC A,#13H ;1
MOV @R0,A ;2
INC R0
MOV A,TH0
ADDC A,#00H
MOV @R0,A
INC R0
MOV TH0,#00H
MOV TL0,#00H
SJMP L6
SHUJIAN: SETB JIEXUAN
MOV @R0,#DATABEG1
INC R0
MOV @R0,#DATABEG2
SETB EX0
CLR F0
NEXT13: JB F0,NEXT12
LJMP NEXT13
NEXT12: LCALL WRITEP
SETB JIELIGHT
RET
TIME0OUT CLR ET0
CLR TR0
MOV DPTR,#SHUJIAN
MOV @R1,DPH
DEC R1
MOV @R1,DPL
RETI
KEYPRESS: CLR EX0
MOV R3,#0DH
CYCLE3: MOV R4,#0FFH
CYCLE2: DJNZ R4,CYCLE2
DJNZ R3,CYCLE3
MOV C,INTRPO
JNC NEXT1
RETI
NEXT1: SETB F0
MOV C,P1.0
MOV ACC.0,C
MOV C,P1.1
MOV ACC.1,C
MOV C,P1.2
MOV ACC.2,C
CLR P1.0
CLR P1.1
CLR P1.2
SETB P1.3
SETB P1.4
SETB P1.5
MOV C,P1.3
MOV ACC.3,C
MOV C,P1.4
MOV ACC.4,C
MOV C,P1.5
MOV ACC.5,C
ANL A,300111111B
MOV JIANMA,A
SETB P1.0
SETB P1.1
SETB P1.2
CLR P1.3
CLR P1.4
CLR P1.5
LCALL JIANWEIP
RETI
JIANWEIP: CJNE JIANMA,#36H,NEXT14
MOV JIANWEI,#01H
LJMP LAST
NEXT14: CJNE JIANMA,#35H,NEXT15
MOV JIANWEI,#02H
LJMP LAST
NEXT15: CJNE JIANMA,#35H,NEXT16
MOV JIANWEI,#03H
LJMP LAST
NEXT16: CJNE JIANMA,#2EH,NEXT17
MOV JIANWEI,#04H
LJMP LAST
NEXT17: CJNE JIANMA,#2DH NEXT18
MOV JIANWEI, #05H
LJMP LAST
NEXT18: CJNE JIANMA,#2BH,NEXT19
MOV JIANWEL,#06H
LJMP LAST
NEXT19: CJNE JIANMA,#1EH,NEXT20
MOV JIANWEI,#07H
LJMP LAST
NEXT20: CJNE JIANMA,#1DH,NEXT21
MOV JIANWEL,#09H
LJMP LAST
NEXT21: CJNE JIANMA,#1BH,NEXT22
MOV JIANWEI,#09H
LJMP LAST
NEXT22: CLR FO
LAST: RET
READP: MOV RO,BUFBEGIN
MOV A,JIANWEI
MOV B,50
MUL AB
MOV R3,A
SHU JU DI ZHI
INC R3
LCALL READCOM
READNET2: MOV A,R3
LCALL WRITEADRESS
LCALL READBYTE
CJNE ,#DATABEG1,READNET1
MOV A R3
INC A
LACLL WRITEADRESS
LCALL READBYTE
CJNE A,#DATABEG2,READNET1
CLR CS
RET
READNET1: MOV @RO,A
INC RO
INC R3
LJMP READNET2
WRITEP: MOV RO,BUFBEGIN
MOV A,JIAWEI
MOV B,50
MUL AB
MOV R3,A ;KAI SHI SHU
JU DI ZHI
INC R3
LCALL EWEN
WRITNET1: LACLL WRITECOM
MOV,R3
LCALL WRITEADRESS
MOV A,@RO
CJNE A,#DATABEG1,WRITNET2
INC RO
MOV A,@RO
CJNE A,DATABEG2,WRITNET3
LCALL EWDS
CLR CS
RET
WRITNRT3: DEC RO
WRITNET2: LCALL WRITEBYTE
INC RO
INC R3
LJMP WRITNE1
RET
WRITBYTE: MOV R2,#08H
BOUT1: CLR CLK
RLC A
MOV DATADUAN,C
NOP
SETB CLK
NOPDJNZ R2,BOUT1
CLRDATADUAN
RET
READBYTE: SETB DATAUAN
MOV R2,#08H
BIN1: CLR CLK
NOP
SETB CLK
NOP
MOV C,DATADUAN
RLC A
DJNZ R2,BIN1
RET
READCOM: CLR CS
CLR CLK
SETB DATADUAN
SETB CS
NOP
SETB CLK ;1
NOP
CLR CLK
NOP
SETB CLK ;1
NOP
CLR DATAUAN
CLR CLK
NOP
SETB CLK ;0
RET
WRITECOM: CLR CS
NOP
CLR CLK
SETB DATADUAN
SETB CS
NOP
SETB CLK ;1
NOP
CLR DATADUAN
NOP
CLR CLK
NOP
SETB CLK ;0
NOP
SETB DATADUAN
NOP
CLR CLK
NOP
SETB CLK ;1
RET
WRITEADRESS: MOV R2,#07H
RLC A ;TIAO GUO
DI 7 WEI
BOUT2: CLR CLK
RLC A
MOV DATADUAN,C
NOP
DJNA R2,BOUT2
CLR DATAUAN
RET
EQEN: CLR CS
CLR CLK
SETB DATADUAN
SETB CS
SETB CLK ;1
NOP
CLR CLK
NOP
CLR DATADUAN
SETB CLK ;0
NOP
NOP
CLR CLK
NOP
SETB CLK ;0
NOP
NOP
SETB DATADUAN
CLR CLK
NOP
SETB CLK ;1
NOP
NOP
SETB CLK ;1
NOP
NOP
CLR CLK
NOP
NOP
CLR CS
RET
EWDS: CLR CS
CLR CLK
SETB DATADUAN
SETB CS
SETB CLK ;1
NOP
CLR CLK
NOP
CLR DATADUAN
SETB CLK ;0
NOP
NOP
CLR CLK
NOP
SETB CLK ;0
NOP
NOP
CLR CLK
NOP
NOP
RETB CLK ;0
NOP
NOP
SETB CLK ;0
NOP
NOP
CLR CLK
NOP
NOP
SETB CLK ;0
NOP
NOP
CLR CS
CLR CLK
RET
DELAY: MOV R3,#96H
DEL1: MOV R4,#OFFH
DEL2: DJNZ R4,DEL2
DJNZ R3,#DEL1
RET
END

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top