STC单片机学习型遥控器程序
STC89C52学习型遥控器,可存八个红外遥控信息,只要再把按键用定时器中断2完成就可以用于商业生产.
RXIN BIT P2.0
TXZAI BIT P2.2
TXOUT BIT P2.1
KEY_SIGN BIT 20H ;为0按键错误,为1按键正确
RXTX_SIGN BIT 21H ;为0是为发射状态,为1是为接收状态
ISP_DATA DATA 0E2H ;ISP功能寄存器定义
ISP_ADDRH DATA 0E3H
ISP_ADDRL DATA 0E4H
ISP_CMD DATA 0E5H
ISP_TRIG DATA 0E6H
ISP_CONTR DATA 0E7H
ISP_CMD_NO EQU 0 ;操作数
ISP_CMD_READ EQU 1
ISP_CMD_PROGRAM EQU 2
ISP_CMD_ERASE EQU 3
WAIT_TIME EQU 1 ;等待时间
ZHIL EQU 30H
ZHIH EQU 31H
GESHU EQU 32H
JISHU EQU 33H
KEY_WORD EQU 34H
KEY_VALUE EQU 35H
ADDRH EQU 36H
ADDRL EQU 37H
TX_GESHU EQU 38H
ORG 0000H
LJMP START
ORG 000BH
LJMP T0IN
ORG 001BH
LJMP T1IN
ORG 0100H
START: MOV SP,#10H
CLR RXTX_SIGN
LJMP KEY_MAIN
KEY_MAIN:LCALL SCAN_KEY ;检测有没有单个按键按下
MOV A,KEY_WORD
CJNE A,#00H,NEXT1
LJMP KEY_MAIN
NEXT1: JNB KEY_SIGN,KEY_MAIN
MOV KEY_VALUE,A
LCALL RE_DELAY ;消抖时间20ms
LCALL SCAN_KEY ;是否依然是按下的
MOV A,KEY_WORD
CJNE A,#00H,NEXT2
LJMP KEY_MAIN
NEXT2: JNB KEY_SIGN,KEY_MAIN
CJNE A,KEY_VALUE,KEY_MAIN
RELEASE: LCALL SCAN_KEY ;查看是否放开按键了
MOV A,KEY_WORD
CJNE A,#00H,RELEASE
MOV DPTR,#TAB ;执行相应的程式
CLR C
MOV A,KEY_VALUE
ADD A,KEY_VALUE
JMP @A+DPTR
TAB: AJMP KEY_0
AJMP KEY_1
AJMP KEY_2
AJMP KEY_3
AJMP KEY_4
AJMP KEY_5
AJMP KEY_6
AJMP KEY_7
AJMP KEY_8
AJMP KEY_9
AJMP KEY_10
AJMP KEY_11
AJMP KEY_12
AJMP KEY_13
AJMP KEY_14
AJMP KEY_15
AJMP KEY_16
KEY_0: LJMP KEY_MAIN ;无效的按健值
KEY_1: JNB RXTX_SIGN,T1RX ;接收发送键设定键,P1灯亮为接收存储状态,灯灭是为发射状态
T1TX: CLR RXTX_SIGN
MOV P1,#0FFH
LJMP KEY_MAIN
T1RX: SETB RXTX_SIGN
MOV P1,#00H
LJMP KEY_MAIN
KEY_2: MOV ADDRH,#20H
MOV ADDRL,#00H
JB RXTX_SIGN,KEY2_RX
KEY2_TX:LJMP TX_START
KEY2_RX:LJMP RX_START
KEY_3: MOV ADDRH,#22H
MOV ADDRL,#00H
JB RXTX_SIGN,KEY3_RX
KEY3_TX:LJMP TX_START
KEY3_RX:LJMP RX_START
KEY_4: MOV ADDRH,#24H
MOV ADDRL,#00H
JB RXTX_SIGN,KEY4_RX
KEY4_TX:LJMP TX_START
KEY4_RX:LJMP RX_START
KEY_5: MOV ADDRH,#26H
MOV ADDRL,#00H
JB RXTX_SIGN,KEY5_RX
KEY5_TX:LJMP TX_START
KEY5_RX:LJMP RX_START
KEY_6: MOV ADDRH,#28H
MOV ADDRL,#00H
JB RXTX_SIGN,KEY6_RX
KEY6_TX:LJMP TX_START
KEY6_RX:LJMP RX_START
KEY_7: MOV ADDRH,#2AH
MOV ADDRL,#00H
JB RXTX_SIGN,KEY7_RX
KEY7_TX:LJMP TX_START
KEY7_RX:LJMP RX_START
KEY_8: MOV ADDRH,#2CH
MOV ADDRL,#00H
JB RXTX_SIGN,KEY8_RX
KEY8_TX:LJMP TX_START
KEY8_RX:LJMP RX_START
KEY_9: MOV ADDRH,#2EH
MOV ADDRL,#00H
JB RXTX_SIGN,KEY9_RX
KEY9_TX:LJMP TX_START
KEY9_RX:LJMP RX_START
KEY_10: MOV ADDRH,#2EH
MOV ADDRL,#00H
JB RXTX_SIGN,KEY10_RX
KEY10_TX:LJMP TX_START
KEY10_RX:LJMP RX_START
KEY_11: MOV ADDRH,#2EH
MOV ADDRL,#00H
JB RXTX_SIGN,KEY11_RX
KEY11_TX:LJMP TX_START
KEY11_RX:LJMP RX_START
KEY_12: MOV ADDRH,#2EH
MOV ADDRL,#00H
JB RXTX_SIGN,KEY12_RX
KEY12_TX:LJMP TX_START
KEY12_RX:LJMP RX_START
KEY_13: MOV ADDRH,#2EH
MOV ADDRL,#00H
JB RXTX_SIGN,KEY13_RX
KEY13_TX:LJMP TX_START
KEY13_RX:LJMP RX_START
KEY_14: MOV ADDRH,#2EH
MOV ADDRL,#00H
JB RXTX_SIGN,KEY14_RX
KEY14_TX:LJMP TX_START
KEY14_RX:LJMP RX_START
KEY_15: MOV ADDRH,#2EH
MOV ADDRL,#00H
JB RXTX_SIGN,KEY15_RX
KEY15_TX:LJMP TX_START
KEY15_RX:LJMP RX_START
KEY_16: MOV ADDRH,#2EH
MOV ADDRL,#00H
JB RXTX_SIGN,KEY16_RX
KEY16_TX:LJMP TX_START
KEY16_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,#1
SETB KEY_SIGN
KEY2: JB P3.5,KEY3
JB KEY_SIGN,KEYWRONG1
MOV KEY_WORD,#2
SETB KEY_SIGN
KEY3: JB P3.6,KEY4
JB KEY_SIGN,KEYWRONG1
MOV KEY_WORD,#3
SETB KEY_SIGN
KEY4: JB P3.7,KEY5
JB KEY_SIGN,KEYWRONG1
MOV KEY_WORD,#4
SETB KEY_SIGN
LJMP KEY5
KEYWRONG1: LJMP KEYWRONG
- STC单片机内部EEPROM程序(12-02)
- STC单片机 EEPROM/IAP 功能测试程序演示(12-01)
- stc单片机IO配置与PWM(12-01)
- STC单片机I/O口控制程序(两个不同的跑马灯效果)(12-01)
- STC单片机实现水滴效果程序(12-01)
- STC单片机8个LED闪烁程序(12-01)