新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STC單片機(jī)學(xué)習(xí)型遙控器程序

STC單片機(jī)學(xué)習(xí)型遙控器程序

作者: 時(shí)間:2013-05-11 來(lái)源:網(wǎng)絡(luò) 收藏

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

KEY5: MOV P3,#11111101B ;第二行
JB P3.4,KEY6
JB KEY_SIGN,KEYWRONG2
MOV KEY_WORD,#5
SETB KEY_SIGN
KEY6: JB P3.5,KEY7
JB KEY_SIGN,KEYWRONG2
MOV KEY_WORD,#6
SETB KEY_SIGN
KEY7: JB P3.6,KEY8
JB KEY_SIGN,KEYWRONG2
MOV KEY_WORD,#7
SETB KEY_SIGN
KEY8: JB P3.7,KEY9
JB KEY_SIGN,KEYWRONG2
MOV KEY_WORD,#8
SETB KEY_SIGN
LJMP KEY9

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 ;接收紅外信號(hào),存入外部擴(kuò)展寄存器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 ;取反轉(zhuǎn)換重新存入外部擴(kuò)展寄存器
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

紅外遙控器相關(guān)文章:紅外遙控器原理

萬(wàn)能遙控器相關(guān)文章:萬(wàn)能遙控器代碼




評(píng)論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉