STC單片機學習型遙控器程序
STC89C52學習型遙控器,可存八個紅外遙控信息,只要再把按鍵用定時器中斷2完成就可以用于商業(yè)生產(chǎn).
RXIN BIT P2.0
TXZAI BIT P2.2
TXOUT BIT P2.1
KEY_SIGN BIT 20H ;為0按鍵錯誤,為1按鍵正確
RXTX_SIGN BIT 21H ;為0是為發(fā)射狀態(tài),為1是為接收狀態(tài)
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 ;操作數(shù)
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 ;執(zhí)行相應的程式
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 ;接收發(fā)送鍵設(shè)定鍵,P1燈亮為接收存儲狀態(tài),燈滅是為發(fā)射狀態(tài)
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
紅外遙控器相關(guān)文章:紅外遙控器原理
萬能遙控器相關(guān)文章:萬能遙控器代碼
評論