竭诚为您提供优质文档/双击可除
nec,ir,协议
篇一:nec码红外遥控完整编码
红外遥控编码程序如下:
nec.sectiondata
a_Rem_codedb;keydatacode
a_customeR_1db;遥控器头码(客户码)低八位
a_customeR_2db;遥控器头码(客户码)高八位
#definecus_6221_100110100b;1234h
#definecus_6221_200010010b
;@------------------------------------------------
nec_code.sectioncode
;@*************subRoutine[xx]:sendRemotecode*** *********;;遥控码发送:
send_Remote_code:
clrwdt;清除进位标志,检测遥控发送的有效的按键
szfg_sendactive;sz表示以0结尾的字符串
jmpReady_send;跳转到Ready_send模块
ret
Ready_send:
nec_code:
mova,a_key_num;将数值发送到寄存器a中,直接寻址movm_tblp,a
tabRdla_Rem_code;查表专用指令
moVa,cus_6221_1;读取遥控头码(客户码)低八位数值moVa_customeR_1,a
moVa,cus_6221_2
moVa_customeR_2,a
以上为Ready_send运行模块,同时是为后面nec码发送的准备;首先将一个按键的数值已以直接寻址方式发送到寄存器a中,将寄存器a的是发送到m_tblp中,然后查表a_Rem_code,将cus_6221_1的值发送到寄存器中,在赋值给遥控器头码(客户码)低八位a_customeR_1,同理,将cus_6221_2赋值给遥控器头码(客户码)低八位
a_customeR_2,随后即开始发送nec遥控码。nec引导码发送并开始编译:
;;---startingsendnecRemotecode---
send_nec:;checknokeycodeffh
sizaa_Rem_code;取出变量的大小
jmpleadnec_code;跳转指令
Ret;返回地址出栈,从而实现转移到返回地址处
leadnec_code:;1instructioncycle=8.79us
clrpn_iR;highlevel9ms(455khz:1023cycle)mova,002d;[( 3*168)+5]*2=1018
mova_sR13,a
leadind_code_00:
mova,168d
movm_acc,a
leadind_code_01:
sdzm_acc;结果为零,则跳过下一条指令
jmpleadind_code_01
sdza_sR13
jmpleadind_code_00
nop2
nop2
nop;空操作指令,占用一个机器周期,用于延时或程序指令的对齐setpn_iR;置位标志,即将某一位置1 clrwdt
mova,001d;lowlevel2.5ms(284cycle)
mova_sR13,a;[(4*69)+5]*1=281
lead_code_04:
mova,70d
movm_acc,a
lead_code_05:
nop
sdzm_acc
jmplead_code_05
sdza_sR13
jmplead_code_04
clrwdt
szfg_Repeat;checkRepeatkey jmpRepeat_code
mova,001d;lowlevel2.0ms(227cycle) mova_sR13,a;[(4*55)+5]*1=225
lead_code_06:
mova,53d
movm_acc,a
lead_code_07:
nop
sdzm_acc
jmplead_code_07
sdza_sR13
jmplead_code_06
clrwdt
nop2
;------------------------ ;;客户码编译:
cusnec_code:
mova,002d
mova_sR13,a
moVa,oFFseta_customeR_1 moVm_mp0,a
custom_pRo:
mova,008d
mova_sR11,a;8databit
nop
custom_bit_bl
clrpn_iR
mova,20d
custom_bit_bl_1:
sdzm_acc
jmpcustom_bit_bl_1
clrwdt
nop
custom_bit_bh:
setpn_iR;0.56ms->63cycle;[(3*20)+2]=62;00.56ms->63c ycle;11.68ms->191cycle
nop
rrm_indiRect1;
mova,18d
szm_indiRect1.7;
mova,61d
custom_bit_bh_0:
sdzm_acc
jmpcustom_bit_bh_0
clrwdt
sdza_sR11
jmpcustom_bit_bl
incm_mp0
sdza_sR13
jmpcustom_pRo
;;---------------------------
;;数据码编译:
data6nec_bit: