红外遥控编码程序如下: 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
clr pn_IR mov A,20d
CUSTOM_BIT_BL_1:
SDZ M_ACC
JMP CUSTOM_BIT_BL_1 clr wdt Nop
CUSTOM_BIT_BH:
set pn_IR ;0.56ms->63 Cycle ;[(3*20)+2]=62
;'0' 0.56ms->63 Cycle ;'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 nop
DATA_BIT_BL:
clr pn_IR mov A,20d
DATA_BIT_BL_1:
SDZ M_ACC
JMP DATA_BIT_BL_1 clr wdt nop
DATA_BIT_BH:
set pn_IR nop
rr a_REM_CODE ; mov A,18d
SZ a_REM_CODE.7 mov A,61d
DATA_BIT_BH_0:
; 8 data bit ;0.53ms->60 Cycle ;[(3*19)+2]=59
;'0' 0.53ms->60 Cycle ;'1' 1.58ms->179 Cycle
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 mov a_SR13,A
REP_DELAY_02:
mov A,130d 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
;Repetition time=108ms (12286 Cycle)
;Scan Key = 2471 Cycle
;Send Repeat Code = 1390 Cycle ;12286-2471-1390=8425 ;[(4*130)+5]*16=8400