nec码红外遥控完整编码
红外遥控编码程序如下:
NEC .SECTION 'DATA'
a_REM_CODE DB ? ;KEY DATA CODE
a_CUSTOMER_1 DB ? ;遥控器头码(客户码)低八位
a_CUSTOMER_2 DB ? ;遥控器头码(客户码)高八位
#define CUS_6221_1 00110100b ;1234H
#define CUS_6221_2 00010010b ;@------------------------------------------------
NEC_CODE .SECTION 'CODE'
;@************* SUBROUTINE[xx]: Send Remote Code ************
;;遥控码发送:
SEND_REMOTE_CODE:
clr WDT ;清除进位标志,检测遥控发送的有效的按
键
SZ fg_SendActive ;SZ表示以0结尾的字符串
JMP READY_SEND ;跳转到READY_SEND模块
ret
READY_SEND:
NEC_CODE:
mov A,a_KEY_NUM ;将数值发送到寄存器A中,直接寻址
mov M_TBLP,A
TABRDL a_REM_CODE ;查表专用指令
;读取遥控头码(客户码)低八位数值 MOV A,CUS_6221_1
MOV a_CUSTOMER_1,A
MOV A,CUS_6221_2
MOV a_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引导码发送并开始编译:
;;--- Starting send NEC Remote code --- SEND_NEC: ;Check No Key Code ffH
SIZA a_REM_CODE ;取出变量的大小
JMP LEADNEC_CODE ;跳转指令
Ret ;返回地址出栈,从而实现转移到返回地址
处
LEADNEC_CODE: ; 1 Instruction Cycle = 8.79us
clr pn_IR ;High Level 9 ms (455KHz:1023 Cycle)
mov A,002d ; [(3*168)+5]*2 = 1018
mov a_SR13,A
LEADIND_CODE_00:
mov A,168d
mov M_ACC,A
LEADIND_CODE_01:
SDZ M_ACC ; 结果为零,则跳过下一条指令 JMP LEADIND_CODE_01
SDZ a_SR13
JMP LEADIND_CODE_00
NOP2
NOP2
NOP ;空操作指令,占用一个机器周期,用于延时或程序指令的对齐
set pn_IR ;置位标志,即将某一位 置1 clr wdt
mov A,001d ;LOW Level 2.5ms (284Cycle)
mov a_SR13,A ; [(4*69)+5]*1 = 281
LEAD_CODE_04:
mov A,70d
mov M_ACC,A
LEAD_CODE_05:
NOP
SDZ M_ACC
JMP LEAD_CODE_05
SDZ a_SR13
JMP LEAD_CODE_04
clr wdt
SZ fg_REPEAT ;CHECK REPEAT KEY JMP REPEAT_CODE
mov A,001d ;LOW Level 2.0ms (227Cycle)
mov a_SR13,A ; [(4*55)+5]*1 = 225
LEAD_CODE_06:
mov A,53d
mov M_ACC,A
LEAD_CODE_07:
NOP
SDZ M_ACC
JMP LEAD_CODE_07
SDZ a_SR13
JMP LEAD_CODE_06
clr wdt
nop2
;------------------------
;;客户码编译:
CUSNEC_CODE:
mov A,002d
mov a_SR13,A
MOV A,OFFSET a_CUSTOMER_1 MOV M_MP0,A
CUSTOM_PRO:
mov A,008d
mov a_SR11,A ; 8 data bit nop
CUSTOM_BIT_BL ;0.56ms->63 Cycle
clr pn_IR ;[(3*20)+2]=62
mov A,20d
CUSTOM_BIT_BL_1:
SDZ M_ACC
JMP CUSTOM_BIT_BL_1
clr wdt
Nop
CUSTOM_BIT_BH: ;'0' 0.56ms->63 Cycle
set pn_IR ;'1' 1.68ms->191 Cycle
nop
rr M_INDIRECT1 ;
mov A,18d
SZ M_INDIRECT1.7 ;
mov A,61d
CUSTOM_BIT_BH_0:
SDZ M_ACC
JMP CUSTOM_BIT_BH_0
clr wdt
SDZ a_SR11
JMP CUSTOM_BIT_BL
INC M_MP0
SDZ a_SR13
JMP CUSTOM_PRO
;;--------------------------- ;;数据码编译:
DATA6NEC_BIT:
mov A,002d
mov a_SR13,A
DATA_PRO:
mov A,008d
mov a_SR11,A ; 8 data bit
nop
DATA_BIT_BL: ;0.53ms->60 Cycle
clr pn_IR ;[(3*19)+2]=59
mov A,20d
DATA_BIT_BL_1:
SDZ M_ACC
JMP DATA_BIT_BL_1
clr wdt
nop
DATA_BIT_BH: ;'0' 0.53ms->60 Cycle
set pn_IR ;'1' 1.58ms->179 Cycle
nop
rr a_REM_CODE ;
mov A,18d
SZ a_REM_CODE.7
mov A,61d
DATA_BIT_BH_0:
SDZ M_ACC
JMP DATA_BIT_BH_0
clr wdt
SDZ a_SR11
JMP DATA_BIT_BL
CPL A_REM_CODE
SDZ a_SR13
JMP DATA_PRO
;0.53ms->60 Cycle
clr pn_IR ;[(3*19)+2]=59
mov A,20d
DATA_BIT_BL_2:
SDZ M_ACC
JMP DATA_BIT_BL_2
clr wdt
set pn_IR
;--- Frame Delay Time Process ---
mov A,004d ;Repetition time=108ms (12286 Cycle)
mov a_SR13,A ;Scan Key = 2471 Cycle
;Send Code = 7349 Cycle
FDTP_LOOP_01: ;12286-2471-7349=2466
mov A,152d ;[(4*152)+5]*4=2452
mov M_ACC,A
FDTP_LOOP_02:
nop
SDZ M_ACC
JMP FDTP_LOOP_02
clr wdt
SDZ a_SR13
JMP FDTP_LOOP_01
mov A,3d
mov M_ACC,A
FDTP_LOOP_03:
SDZ M_ACC
JMP FDTP_LOOP_03
NOP2
ret
;-------------------------------- ;;重复码编译:
REPEAT_CODE:
;0.56ms->63 Cycle
clr pn_IR ;[(3*20)+2]=62
mov A,19d
REP_BIT_BL_3:
SDZ M_ACC
JMP REP_BIT_BL_3
clr wdt
set pn_IR
;--- Repeat Frame Delay Time Process ---
mov A,016d ;Repetition time=108ms (12286 Cycle)
mov a_SR13,A ;Scan Key = 2471 Cycle
nd Repeat Code = 1390 Cycle ;Se
REP_DELAY_02: ;12286-2471-1390=8425
mov A,130d ;[(4*130)+5]*16=8400
mov M_ACC,A
REP_DELAY_03:
nop
SDZ M_ACC
JMP REP_DELAY_03
clr wdt
SDZ a_SR13
JMP REP_DELAY_02
mov A,07d
mov M_ACC,A
REP_DELAY_04:
SDZ M_ACC
JMP REP_DELAY_04
NOP2
ret
%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%
Remote Table Array
org 300h
DW 00ffh ;; Key 00 : --- :00 DW 0000h ;; Key 1 : --- :01 DW 0001h ;; Key 2 : :02
DW 0002h ;; Key 3 : :03 DW 0003h ;; Key 4 : :04 DW 0004h ;; Key 5 : :05 DW 0005h ;; Key 6 : :06 DW 0006h ;; Key 7 : :07 DW 0007h ;; Key 8 : :08 DW 0008h ;; Key 9 : :09 DW 0009h ;; Key 10 : :10 DW 000ah ;; Key 11 : :11 DW 000bh ;; Key 12 : :12 DW 000ch ;; Key 13 : :13 DW 000dh ;; Key 14 : :14 DW 000eh ;; Key 15 : :15 DW 000fh ;; Key 16 : :16 DW 0010h ;; Key 17 : :17 DW 0011h ;; Key 18 : :18 DW 0012h ;; Key 19 : :19 DW 0013h ;; Key 20 : :20 DW 0014h ;; Key 21 : :21 DW 0015h ;; Key 22 : :22 DW 0016h ;; Key 23 : :23 DW 0017h ;; Key 24 : :24 DW 0018h ;; Key 25 : :25 DW 0019h ;; Key 26 : :26
DW 001ah ;; Key 27 : :27 DW 001bh ;; Key 28 : :28
001ch ;; Key 29 : :29 DW
DW 001dh ;; Key 30 : :30 DW 001eh ;; Key 31 : :31 DW 001fh ;; Key 32 : :32 DW 0020h ;; Key 33 : :33 DW 0021h ;; Key 34 : :34 DW 0022h ;; Key 35 : :35 DW 0023h ;; Key 36 : :36 DW 0024h ;; Key 37 : :37 DW 0025h ;; Key 38 : :38 DW 0026h ;; Key 39 : :39 DW 0027h ;; Key 40 : :40 DW 0028h ;; Key 41 : :41 DW 0029h ;; Key 42 : :42 DW 002ah ;; Key 43 : :43 DW 002bh ;; Key 44 : :44 DW 002ch ;; Key 45 : :45 DW 002dh ;; Key 46 : :46 DW 002eh ;; Key 47 : :47 DW 002fh ;; Key 48 : :48
0030h ;; Key 49 : :49 DW
DW 0031h ;; Key 50 : :50 DW 0032h ;; Key 51 : :51 DW 0033h ;; Key 52 : :52
DW 0034h ;; Key 53 : :53 DW 0035h ;; Key 54 : :54 DW 0036h ;; Key 55 : :55 DW 0037h ;; Key 56 : :56 DW 0038h ;; Key 57 : :57 DW 0039h ;; Key 58 : :58 DW 003ah ;; Key 59 : :59 DW 003bh ;; Key 60 : :60 DW 003ch ;; Key 61 : :61 DW 003dh ;; Key 62 : :62 DW 003eh ;; Key 63 : :63 DW 003fh ;; Key 64 : :64 END
因篇幅问题不能全部显示,请点此查看更多更全内容