新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > STC单片机学习型遥控器程序

STC单片机学习型遥控器程序

作者:时间:2013-05-11来源:网络收藏

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

红外遥控器相关文章:红外遥控器原理

万能遥控器相关文章:万能遥控器代码



上一页 1 2 3 下一页

评论


相关推荐

技术专区

关闭