垃圾车厂家
免费服务热线

Free service

hotline

010-00000000
垃圾车厂家
热门搜索:
行业资讯
当前位置:首页 > 行业资讯

STC89C52学习型遥控器源程序

发布时间:2020-06-30 19:13:21 阅读: 来源:垃圾车厂家

STC89C52做的学习型遥控器,可存八个红外遥控信息,只要再把按键用定时器中断2完成就可以用于商业生产.

本文引用地址: BIT P2.0TXZAI BIT P2.2TXOUT BIT P2.1KEY_SIGN BIT 20H ;为0按键错误,为1按键正确RXTX_SIGN BIT 21H ;为0是为发射状态,为1是为接收状态

ISP_DATA DATA 0E2H ;ISP功能寄存器定义ISP_ADDRH DATA 0E3HISP_ADDRL DATA 0E4HISP_CMD DATA 0E5HISP_TRIG DATA 0E6HISP_CONTR DATA 0E7H

ISP_CMD_NO EQU 0 ;操作数ISP_CMD_READ EQU 1ISP_CMD_PROGRAM EQU 2ISP_CMD_ERASE EQU 3

WAIT_TIME EQU 1 ;等待时间

ZHIL EQU 30HZHIH EQU 31H GESHU EQU 32HJISHU EQU 33HKEY_WORD EQU 34HKEY_VALUE EQU 35HADDRH EQU 36HADDRL EQU 37HTX_GESHU EQU 38H

ORG 0000HLJMP STARTORG 000BHLJMP T0INORG 001BHLJMP T1IN

ORG 0100HSTART: MOV SP,#10H CLR RXTX_SIGN LJMP KEY_MAIN

KEY_MAIN:LCALL SCAN_KEY ;检测有没有单个按键按下 MOV A,KEY_WORDCJNE A,#00H,NEXT1LJMP KEY_MAINNEXT1: JNB KEY_SIGN,KEY_MAIN MOV KEY_VALUE,A LCALL RE_DELAY ;消抖时间20ms

LCALL SCAN_KEY ;是否依然是按下的MOV A,KEY_WORDCJNE A,#00H,NEXT2LJMP KEY_MAINNEXT2: JNB KEY_SIGN,KEY_MAIN CJNE A,KEY_VALUE,KEY_MAIN

RELEASE: LCALL SCAN_KEY ;查看是否放开按键了MOV A,KEY_WORDCJNE A,#00H,RELEASE

MOV DPTR,#TAB ;执行相应的程式CLR CMOV A,KEY_VALUEADD A,KEY_VALUE JMP @A+DPTR TAB: AJMP KEY_0 AJMP KEY_1 AJMP KEY_2AJMP KEY_3AJMP KEY_4AJMP KEY_5AJMP KEY_6AJMP KEY_7AJMP KEY_8AJMP KEY_9AJMP KEY_10AJMP KEY_11AJMP KEY_12AJMP KEY_13 AJMP KEY_14AJMP KEY_15AJMP KEY_16

KEY_0: LJMP KEY_MAIN ;无效的按健值

KEY_1: JNB RXTX_SIGN,T1RX ;接收发送键设定键,P1灯亮为接收存储状态,灯灭是为发射状态T1TX: CLR RXTX_SIGN MOV P1,#0FFH LJMP KEY_MAINT1RX: SETB RXTX_SIGN MOV P1,#00H LJMP KEY_MAIN

KEY_2: MOV ADDRH,#20H MOV ADDRL,#00H JB RXTX_SIGN,KEY2_RXKEY2_TX:LJMP TX_STARTKEY2_RX:LJMP RX_START

KEY_3: MOV ADDRH,#22H MOV ADDRL,#00H JB RXTX_SIGN,KEY3_RXKEY3_TX:LJMP TX_STARTKEY3_RX:LJMP RX_START

KEY_4: MOV ADDRH,#24H MOV ADDRL,#00H JB RXTX_SIGN,KEY4_RXKEY4_TX:LJMP TX_STARTKEY4_RX:LJMP RX_START

KEY_5: MOV ADDRH,#26H MOV ADDRL,#00H JB RXTX_SIGN,KEY5_RXKEY5_TX:LJMP TX_STARTKEY5_RX:LJMP RX_START

KEY_6: MOV ADDRH,#28H MOV ADDRL,#00H JB RXTX_SIGN,KEY6_RXKEY6_TX:LJMP TX_STARTKEY6_RX:LJMP RX_START

KEY_7: MOV ADDRH,#2AH MOV ADDRL,#00H JB RXTX_SIGN,KEY7_RXKEY7_TX:LJMP TX_STARTKEY7_RX:LJMP RX_START

KEY_8: MOV ADDRH,#2CH MOV ADDRL,#00H JB RXTX_SIGN,KEY8_RXKEY8_TX:LJMP TX_STARTKEY8_RX:LJMP RX_START

KEY_9: MOV ADDRH,#2EH MOV ADDRL,#00H JB RXTX_SIGN,KEY9_RXKEY9_TX:LJMP TX_STARTKEY9_RX:LJMP RX_START

KEY_10: MOV ADDRH,#2EH MOV ADDRL,#00H JB RXTX_SIGN,KEY10_RXKEY10_TX:LJMP TX_STARTKEY10_RX:LJMP RX_START

KEY_11: MOV ADDRH,#2EH MOV ADDRL,#00H JB RXTX_SIGN,KEY11_RXKEY11_TX:LJMP TX_STARTKEY11_RX:LJMP RX_START

KEY_12: MOV ADDRH,#2EH MOV ADDRL,#00H JB RXTX_SIGN,KEY12_RXKEY12_TX:LJMP TX_STARTKEY12_RX:LJMP RX_START

KEY_13: MOV ADDRH,#2EH MOV ADDRL,#00H JB RXTX_SIGN,KEY13_RXKEY13_TX:LJMP TX_STARTKEY13_RX:LJMP RX_START

KEY_14: MOV ADDRH,#2EH MOV ADDRL,#00H JB RXTX_SIGN,KEY14_RXKEY14_TX:LJMP TX_STARTKEY14_RX:LJMP RX_START

KEY_15: MOV ADDRH,#2EH MOV ADDRL,#00H JB RXTX_SIGN,KEY15_RXKEY15_TX:LJMP TX_STARTKEY15_RX:LJMP RX_START

KEY_16: MOV ADDRH,#2EH MOV ADDRL,#00H JB RXTX_SIGN,KEY16_RXKEY16_TX:LJMP TX_STARTKEY16_RX:LJMP RX_START

SCAN_KEY:CLR KEY_SIGN MOV KEY_WORD,#00H

KEY1: MOV P3,#11111110B ;第一行 JB P3.4,KEY2 JB KEY_SIGN,KEYWRONG1 MOV KEY_WORD,#1SETB KEY_SIGNKEY2: JB P3.5,KEY3JB KEY_SIGN,KEYWRONG1MOV KEY_WORD,#2SETB KEY_SIGNKEY3: JB P3.6,KEY4 JB KEY_SIGN,KEYWRONG1MOV KEY_WORD,#3SETB KEY_SIGNKEY4: JB P3.7,KEY5 JB KEY_SIGN,KEYWRONG1MOV KEY_WORD,#4SETB KEY_SIGNLJMP KEY5KEYWRONG1: LJMP KEYWRONG

KEY5: MOV P3,#11111101B ;第二行 JB P3.4,KEY6JB KEY_SIGN,KEYWRONG2MOV KEY_WORD,#5SETB KEY_SIGNKEY6: JB P3.5,KEY7 JB KEY_SIGN,KEYWRONG2MOV KEY_WORD,#6SETB KEY_SIGNKEY7: JB P3.6,KEY8 JB KEY_SIGN,KEYWRONG2MOV KEY_WORD,#7SETB KEY_SIGNKEY8: JB P3.7,KEY9 JB KEY_SIGN,KEYWRONG2MOV KEY_WORD,#8SETB KEY_SIGNLJMP KEY9

KEYWRONG2:LJMP KEYWRONG KEY9: MOV P3,#11111011B ;第三行 JB P3.4,KEY10JB KEY_SIGN,KEYWRONG3MOV KEY_WORD,#9SETB KEY_SIGNKEY10: JB P3.5,KEY11 JB KEY_SIGN,KEYWRONG3MOV KEY_WORD,#10SETB KEY_SIGNKEY11: JB P3.6,KEY12 JB KEY_SIGN,KEYWRONG3MOV KEY_WORD,#11SETB KEY_SIGNKEY12: JB P3.7,KEY13 JB KEY_SIGN,KEYWRONG3MOV KEY_WORD,#12SETB KEY_SIGN LJMP KEY13

KEYWRONG3:LJMP KEYWRONG

KEY13: MOV P3,#11110111B ;第四行 JB P3.4,KEY14JB KEY_SIGN,KEYWRONG4MOV KEY_WORD,#13SETB KEY_SIGNKEY14: JB P3.5,KEY15 JB KEY_SIGN,KEYWRONG4MOV KEY_WORD,#14SETB KEY_SIGNKEY15: JB P3.6,KEY16 JB KEY_SIGN,KEYWRONG4MOV KEY_WORD,#15SETB KEY_SIGNKEY16: JB P3.7,SCAN_END JB KEY_SIGN,KEYWRONG4 MOV KEY_WORD,#16SETB KEY_SIGNLJMP SCAN_END

KEYWRONG4: LJMP KEYWRONG

KEYWRONG:CLR KEY_SIGNSCAN_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 R1JUDGE2: 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,#00HLOOP_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_STOREISP_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,#00HLOOP_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,#00HLOOP_READ: LCALL BYTE_READ INC R0LCALL BYTE_READINC R0DJNZ R1,LOOP_READLJMP 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 NEXTTNEXTT1:CLR TR0 CLR TXZAI

NEXTT:CPL TXOUT MOVX A,@R0 MOV ZHIL,A INC R0MOVX A,@R0 MOV ZHIH,A INC R0DJNZ R1,OUTTI CLR TR1 CLR TR0 CLR TXZAI CLR TXOUT OUTTI:RETI

DELAYXMS:MOV R7,#255 DEL1:MOV R6,#4 DEL2:MOV R5,#5DJNZ R5,$ DJNZ R6,DEL2DJNZ R7,DEL1RET

DELAYX2MS:MOV R7,#255 DEL12:MOV R6,#50 DEL22:MOV R5,#50DJNZ R5,$ DJNZ R6,DEL22DJNZ R7,DEL12RET

END

济宁工服定制

聊城职业装订制

淄博订做工作服

相关阅读