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

STC89C52学习型遥控器源程序

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

KEYWRONG2:LJMP KEYWRONG

KEY9: MOV P3,#11111011B ;第三行
JB P3.4,KEY10
JB KEY_SIGN,KEYWRONG3
MOV KEY_WORD,#9
SETB KEY_SIGN
KEY10: JB P3.5,KEY11
JB KEY_SIGN,KEYWRONG3
MOV KEY_WORD,#10
SETB KEY_SIGN
KEY11: JB P3.6,KEY12
JB KEY_SIGN,KEYWRONG3
MOV KEY_WORD,#11
SETB KEY_SIGN
KEY12: JB P3.7,KEY13
JB KEY_SIGN,KEYWRONG3
MOV KEY_WORD,#12
SETB KEY_SIGN
LJMP KEY13

KEYWRONG3:LJMP KEYWRONG

KEY13: MOV P3,#11110111B ;第四行
JB P3.4,KEY14
JB KEY_SIGN,KEYWRONG4
MOV KEY_WORD,#13
SETB KEY_SIGN
KEY14: JB P3.5,KEY15
JB KEY_SIGN,KEYWRONG4
MOV KEY_WORD,#14
SETB KEY_SIGN
KEY15: JB P3.6,KEY16
JB KEY_SIGN,KEYWRONG4
MOV KEY_WORD,#15
SETB KEY_SIGN
KEY16: JB P3.7,SCAN_END
JB KEY_SIGN,KEYWRONG4
MOV KEY_WORD,#16
SETB KEY_SIGN
LJMP SCAN_END

KEYWRONG4: LJMP KEYWRONG

KEYWRONG:CLR KEY_SIGN
SCAN_END:RET

RE_DELAY:MOV R7,#5
DE2:MOV R6,#10
DE1:MOV R5,#200
DJNZ R5,$
DJNZ R6,DE1
DJNZ R7,DE2
RET

RX_START: CLR P2.4 ;接收红外信号,存入外部扩展寄存器0~256
CLR P2.6
CLR P2.7
CLR P2.2
CLR TXOUT
MOV R1,#00H
MOV R0,#00H
MOV TMOD,#00010001B
MOV TH0,#00H
MOV TL0,#00H
MOV TH1,#00H
MOV TL1,#00H
CLR ET0
CLR ET1
CLR EA
CLR TR0
CLR TR1
LJMP RX_MAIN

RX_MAIN: MOV R0,#00H
JB RXIN,$
SETB TR0

JUDGE1: JB TF0,RXEND
JNB RXIN,JUDGE1
CLR TR0
SETB TR1
MOV A,TL0
MOVX @R0,A
INC R0
MOV A,TH0
MOVX @R0,A
INC R0
MOV TL0,#00H
MOV TH0,#00H
INC R1
JUDGE2: JB TF1,RXEND
JB RXIN,JUDGE2
CLR TR1
SETB TR0
MOV A,TL1
MOVX @R0,A
INC R0
MOV A,TH1
MOVX @R0,A
INC R0
MOV TL1,#00H
MOV TH1,#00H
INC R1
AJMP JUDGE1

RXEND: CLR TR0
CLR TR1
CLR TF0
CLR TF1
MOV TL0,#00H
MOV TH0,#00H
MOV TL1,#00H
MOV TH1,#00H
MOV GESHU,R1

MOV R1,GESHU ;取反转换重新存入外部扩展寄存器
MOV R0,#00H
LOOP_CPL: MOVX A,@R0
CPL A
MOVX @R0,A
INC R0
MOVX A,@R0
CPL A
MOVX @R0,A
INC R0
DJNZ R1,LOOP_CPL
LJMP ISP_STORE

ISP_STORE: LCALL ISP_ERASE

MOV ISP_DATA,GESHU ;将个数输入到ISP_EEPROM的第一位
MOV ISP_ADDRH,ADDRH
MOV ISP_ADDRL,ADDRL
CLR EA
MOV ISP_CONTR,#WAIT_TIME
ORL ISP_CONTR,#10000000B
MOV ISP_CMD,#ISP_CMD_PROGRAM
MOV ISP_TRIG,#46H
MOV ISP_TRIG,#0B9H
NOP

MOV R1,GESHU
MOV R0,#00H
LOOP_WRITE: LCALL BYTE_WRITE ;将扩展寄存器中的计时值依次放入ISP_EEPROM第二位开始的存储器中
INC R0
LCALL BYTE_WRITE
INC R0
DJNZ R1,LOOP_WRITE

MOV ISP_CMD,#00H ;ISP指令清零,防止误触发
MOV ISP_TRIG,#00H
MOV ISP_ADDRH,#00H
MOV ISP_ADDRL,#00H
mov p1,geshu

LJMP KEY_MAIN

BYTE_WRITE: MOVX A,@R0
MOV ISP_DATA,A
MOV ISP_ADDRH,ADDRH
INC R0
MOV ISP_ADDRL,R0
DEC R0
CLR EA
MOV ISP_CONTR,#WAIT_TIME
ORL ISP_CONTR,#10000000B
MOV ISP_CMD,#ISP_CMD_PROGRAM
MOV ISP_TRIG,#46H
MOV ISP_TRIG,#0B9H
NOP
RET

ISP_ERASE: MOV ISP_ADDRH,ADDRH
MOV ISP_ADDRL,ADDRL
CLR EA
MOV ISP_CONTR,#WAIT_TIME
ORL ISP_CONTR,#10000000B
MOV ISP_CMD,#ISP_CMD_ERASE
MOV ISP_TRIG,#46H
MOV ISP_TRIG,#0B9H
NOP
RET

TX_START: MOV ISP_ADDRH,ADDRH ;取出第一位的个数
MOV ISP_ADDRL,ADDRL
CLR EA
MOV ISP_CONTR,#WAIT_TIME
ORL ISP_CONTR,#10000000B
MOV ISP_CMD,#ISP_CMD_READ
MOV ISP_TRIG,#46H
MOV ISP_TRIG,#0B9H
NOP
MOV ISP_CMD,#00H ;ISP指令清零,防止误触发
MOV ISP_TRIG,#00H
MOV ISP_ADDRH,#00H
MOV ISP_ADDRL,#00H

MOV A,ISP_DATA ;为0FF则是错误的,回去,不为0FF则继续
CJNE A,#0FFH,ISP_READ
LJMP KEY_MAIN

ISP_READ: MOV GESHU,ISP_DATA
MOV R1,GESHU
MOV R0,#00H
LOOP_READ: LCALL BYTE_READ
INC R0
LCALL BYTE_READ
INC R0
DJNZ R1,LOOP_READ
LJMP TX_EXROM

BYTE_READ: INC R0
MOV ISP_ADDRH,ADDRH
MOV ISP_ADDRL,R0
DEC R0
CLR EA
MOV ISP_CONTR,#WAIT_TIME
ORL ISP_CONTR,#10000000B
MOV ISP_CMD,#ISP_CMD_READ
MOV ISP_TRIG,#46H
MOV ISP_TRIG,#0B9H
NOP
MOV A,ISP_DATA
MOVX @R0,A
RET

TX_EXROM: MOV TMOD,#00010010B
MOV TH0,#0F4H
MOV TL0,#0F4H
MOV R1,GESHU
MOV R0,#00H
MOVX A,@R0
MOV TL1,A
INC R0
MOVX A,@R0
MOV TH1,A
INC R0
DEC R1
MOVX A,@R0
MOV ZHIL,A
INC R0
MOVX A,@R0
MOV ZHIH,A
INC R0
DEC R1

SETB ET1
SETB ET0
SETB EA
SETB TR1
SETB TR0
CLR TXOUT

MAIN2:CJNE R1,#00H,MAIN2
CLR TXOUT
mov p1,#55h
LJMP KEY_MAIN

T0IN:CPL TXZAI
RETI

T1IN: MOV TL1,ZHIL
MOV TH1,ZHIH
JB TR0,NEXTT1
SETB TR0
LJMP NEXTT
NEXTT1:CLR TR0
CLR TXZAI

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

网站地图

Top