|
单片机解码模块原代码
- R3 EQU 0X03
- PORT5 EQU 0X05
- PORT6 EQU 0X06
- R3 EQU 0X03
- KEY_STATUS EQU 0X10 ;低半字节为按键标志,高半字节为控制标志
- SIGNAL_LOW EQU 0X11 ;信号电平低计数器
- SIGNAL_HIGH EQU 0X12 ;信号电平高计数器
- DATA_RECORDER EQU 0X13 ;接收码数据字节
- CODE_RECORDER2 EQU 0X14 ;接收码地址高字节
- CODE_RECORDER1 EQU 0X15 ;接收码地址低字节
- CODE_TOTAL EQU 0X16 ;接收数据位计数器
- KEY_COUNTER EQU 0X17 ;两次按键检测计数器
- /**********************KEY_STATUS标志位定义***********************************/
- AUTORUN_KEY EQU 0 ;遥控键标志
- LOCK_KEY EQU 1 ;防盗键标志
- SEARCH_KEY EQU 2 ;寻车键标志
- OPEN_KEY EQU 3 ;解除键标志
- PRESS_FLAG EQU 4 ;有键按下标志
- CHECK_FLAG EQU 5 ;校验标志
- /***********************CONSTANT DEFINE*************************************/
- CODE_ADDRESS1 EQU 0B10001100 ;遥控器地址码,更改常数即可实现其他遥控器收码
- CODE_ADDRESS2 EQU 0B00101100
- AUTORUN_VALUE EQU 0B00000011 ;遥控器相应键值,改变相应数值即可更改其功能
- LOCK_VALUE EQU 0B00001100
- SEARCH_VALUE EQU 0B00110000
- OPEN_VALUE EQU 0B11000000
- /**********************当PORT6.2口电平为高时调用该程序收码******************/
- ;PORT6.2为信号输入口
- collect_2262:
- mov a,@0xf0
- And KEY_STATUS,a
- clr code_total
- clr signal_high
- collect1:
- inc signal_high
- MOV A,SIGNAL_HIGH
- SUB A,@30
- JBS R3,0
- RET
- clr signal_low
- call delay20us
- jbs port6,2
- jmp collect_low
- jmp collect1
- collect_low:
- mov a,signal_high ;信号高电平宽度<80US时滤除
- sub a,@4
- jbc r3,0
- ret
- mov a,@20 ;信号高电平宽度在80—400US时为采集为0
- sub a,signal_high ;信号高电平宽度在400US以上时为采集为1
- rrc data_recorder
- rrc code_recorder2
- rrc code_recorder1
- inc code_total
- clr signal_high
- mov a,@24
- xor a,code_total
- jbc r3,2
- jmp collect_end
- input_low:
- inc signal_low
- mov a,signal_low ;信号低电平宽度大于800US时滤除
- sub a,@40
- jbs r3,0
- ret
- call delay20us
- jbs port6,2;3
- jmp input_low
- jmp collect1
- collect_end:
- mov a,code_recorder1 ;校验低字节地址
- xor a,@code_address1
- jbs r3,2
- ret
- mov a,code_recorder2 ;校验高字节地址
- xor a,@code_address2
- jbs r3,2
- ret
- jbs KEY_STATUS,check_flag ;是否是第一串收码?
- jmp storage_data
- bc KEY_STATUS,check_flag
- mov a,com_data_rec
- xor a,data_recorder
- jbs r3,2
- jmp storage_data
- mov a,data_recorder
- xor a,@autorun_value ;是启动键?
- jbs r3,2
- jmp key1
- bs KEY_STATUS,autorun_key ;置启动键标志
- bs KEY_STATUS,press_flag ;置有键按下标志
- clr key_counter ;清除按键间隔计数器
- ret
- key1:
- mov a,data_recorder
- xor a,@open_value ;是解除键?
- jbs r3,2
- jmp key2
- bs KEY_STATUS,open_key
- bs KEY_STATUS,press_flag
- clr key_counter
- ret
- key2:
- mov a,data_recorder
- and a,@0x0c ;同时有两个键按下时不为0X30
- xor a,@lock_value ;是防盗键?
- jbs r3,2
- jmp key3
- bs KEY_STATUS,lock_key
- bs KEY_STATUS,press_flag
- clr key_counter
- key3:
- mov a,data_recorder
- and a,@0x30
- xor a,@search_value ;是寻车键?
- jbs r3,2
- ret
- bs KEY_STATUS,search_key
- bs KEY_STATUS,press_flag
- clr key_counter
- ret
- storage_data: ;第一次收码存储数据字节
- bs KEY_STATUS,check_flag
- mov a,data_recorder
- mov com_data_rec,a
- ret
- delay20us:
- wdtc
- mov a,@3;9
- mov delay1,a
- delay20us_1:
- nop
- djz delay1
- jmp delay20us_1
- ret
复制代码 |
|