📄 necdecode.s
字号:
.module necdecode.c
.area text(rom, con, rel)
.dbfile G:\McuControl\necdecode.c
.dbfunc e Head_Reset_Nec_receive _Head_Reset_Nec_receive fV
.even
_Head_Reset_Nec_receive::
.dbline -1
.dbline 96
; //ICC-AVR application builder : 2006-9-20 14:49:40
; // Target : M16
; // Crystal: 7.3728Mhz
; #include <iom16v.h>
; #include <macros.h>
; #include <eeprom.h>
; #include "hptvstruct.h"
; //#include "necdecode.h"
; // time2的中断周期为102us
; //接收NEC码起始位最小时间 118*102us=12.036ms
; //接收NEC码起始位最大时间 147*102us=14.994ms
; //接收逻辑0最小时长 10*102us=1.02ms
; //接收逻辑0最大时长 13*102us=1.326ms
; //接收逻辑1最小时长 20*102us=2.04ms
; //接收逻辑1最大时长 25*102us=2.55ms
; //重复码与上位的最小时长 980*102us=99.96ms
; //重复码的最大时长 1176*102us=120.36ms
; //当NEC开始接收还未接收完成同时又不是重复码时超过TimeNecOutoftime的时间将视为不是NEC码
;
;
; #define NecStartBitMin 118
; #define NecStartBitMax 147
; #define NecBit0Min 10
; #define NecBit0Max 13
; #define NecBit1Min 20
; #define NecBit1Max 25
; #define BTvState 1
; #define NecRepeatBitMin 103
; #define NecRepeatBitMax 115
; #define TimeNecRepeatMin 880
; #define TimeNecRepeatMax 1180
; #define TimeNecRepeatMins 372
; #define TimeNecRepeatMaxs 450
; #define TimeNecOutoftime 40
;
;
; unsigned char BTheFirstFallEdge; //为0时说明为接收到第一个下降沿或接受到第一个;为1时认为已接收到了第一个或大于1个下降沿;做为起始时间基准
; unsigned char BReceiveStart; //开始接收数据标志
; unsigned char BNecFallEdge; //是否有下降边沿
; unsigned char TimeNecFallEdge; //下降边沿时间长度
; unsigned char RTimeNecFallEdge; //下降边沿时间长度结果保存
; unsigned char BNecStartBit; //是否有起始位
; unsigned char NecData[4]; //红外数据
; unsigned int NecDecodeNum; //红外数据位个数指针
; unsigned int i;
; unsigned char BHasReceiveNec; //已收到一个NEC码 为进行接收重复码做准备
; unsigned char BPowerButton; //有开机按键
; unsigned int NecRepeatCodeNum; //重复码与上一个NEC码时间间隔计数变量和重复码本身长度计数变量
; unsigned int RNecRepeatCodeNum;//重复码计数结果保存
;
; unsigned char BNecRepeat; //重复码标志,置1为收到重复码
; unsigned char ResultNec;
; unsigned char RepeatCountFlag; //为0时为还已收到了一个NEC码还未收到一次重复码,为1时为收到至少一个重复码
; unsigned char BRepeatStar; //Repeat开始标志
; unsigned char NecData_Map;
;
; //加入的开关机控制变量和I2C变量
; unsigned char power_key_open_enable;//
; unsigned char power_on_close_enable;//
; unsigned char tv_state; //机器状态位
; unsigned char irda_num,irda_b;
; unsigned char i2c_public; //i2c使用权检测
; unsigned char irda_data; //预发送数据
; //Add end
;
; extern unsigned char close_machine_enable,open_machine_enable;
; unsigned char RepeatControl;
; volatile unsigned char Powerdown_signal;
; unsigned char Fac_mode;
; unsigned char Fac_aging;
;
; extern unsigned char Open_Panel_flag;
; /*
; typedef enum _TVstate
; {
; standby,
; booting,
; delaying,
; working,
; halting
; }TVstate_t;
; */
;
; extern volatile TVstate_t System_State;
;
;
;
; //test
; union NecTime
; {
; unsigned int NecRepeatNum;
; unsigned char a[2];
; }NecTimeTest;
;
; void Head_Reset_Nec_receive()
; {
.dbline 97
; BReceiveStart=0;
clr R2
sts _BReceiveStart,R2
.dbline 98
; TimeNecFallEdge=0;
sts _TimeNecFallEdge,R2
.dbline 99
; RTimeNecFallEdge=0;
sts _RTimeNecFallEdge,R2
.dbline 100
; BNecStartBit=0;
sts _BNecStartBit,R2
.dbline 101
; NecData[0]=0;
sts _NecData,R2
.dbline 102
; NecData[1]=0;
sts _NecData+1,R2
.dbline 103
; NecData[2]=0;
sts _NecData+2,R2
.dbline 104
; NecData[3]=0;
sts _NecData+3,R2
.dbline 105
; NecDecodeNum=0;
clr R3
sts _NecDecodeNum+1,R3
sts _NecDecodeNum,R2
.dbline 106
; BPowerButton=0;
sts _BPowerButton,R2
.dbline 107
; i=0;
sts _i+1,R3
sts _i,R2
.dbline 108
; RepeatControl=0;
sts _RepeatControl,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e HasR_Head_Reset_Nec_receive _HasR_Head_Reset_Nec_receive fV
.even
_HasR_Head_Reset_Nec_receive::
.dbline -1
.dbline 112
; }
;
; void HasR_Head_Reset_Nec_receive()
; {
.dbline 113
; BReceiveStart=0;
clr R2
sts _BReceiveStart,R2
.dbline 114
; TimeNecFallEdge=0;
sts _TimeNecFallEdge,R2
.dbline 115
; RTimeNecFallEdge=0;
sts _RTimeNecFallEdge,R2
.dbline 116
; BNecStartBit=0;
sts _BNecStartBit,R2
.dbline 117
; NecDecodeNum=0;
clr R3
sts _NecDecodeNum+1,R3
sts _NecDecodeNum,R2
.dbline 118
; BPowerButton=0;
sts _BPowerButton,R2
.dbline 119
; i=0;
sts _i+1,R3
sts _i,R2
.dbline -2
L5:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Nec_data_deal_fun _Nec_data_deal_fun fV
.even
_Nec_data_deal_fun::
xcall push_gset1
.dbline -1
.dbline 124
; }
;
;
; void Nec_data_deal_fun(void)
; {
.dbline 126
; //UDR=ResultNec;
; switch(ResultNec)
lds R20,_ResultNec
clr R21
cpi R20,15
ldi R30,0
cpc R21,R30
breq L10
cpi R20,15
ldi R30,0
cpc R21,R30
brge X1
xjmp L7
X1:
L40:
cpi R20,50
ldi R30,0
cpc R21,R30
breq L17
cpi R20,51
ldi R30,0
cpc R21,R30
brne X2
xjmp L24
X2:
cpi R20,52
ldi R30,0
cpc R21,R30
brne X3
xjmp L31
X3:
xjmp L7
X0:
.dbline 127
; {
L10:
.dbline 131
; case 15:
; //
;
; if(System_State==working)
lds R24,_System_State
cpi R24,3
brne L11
.dbline 132
; {
.dbline 134
; // UDR=0x90;
; if(close_machine_enable==1) //加入System_State后这个条件其实无用处了
lds R24,_close_machine_enable
cpi R24,1
breq X4
xjmp L8
X4:
.dbline 135
; {
.dbline 137
; // UDR=0x91;
; Powerdown_signal=1;
ldi R24,1
sts _Powerdown_signal,R24
.dbline 138
; i2c_public|=1<<7;
lds R24,_i2c_public
ori R24,128
sts _i2c_public,R24
.dbline 139
; irda_data=ResultNec|(1<<7); //发送键码最高位置1
lds R24,_ResultNec
ori R24,128
sts _irda_data,R24
.dbline 140
; }
.dbline 141
; }
xjmp L8
L11:
.dbline 143
; else
; {
.dbline 145
; // infrared_open_enable=1;////开机
; if(open_machine_enable==1)
lds R24,_open_machine_enable
cpi R24,1
breq X5
xjmp L8
X5:
.dbline 146
; {
.dbline 147
; power_key_open_enable=1;
ldi R24,1
sts _power_key_open_enable,R24
.dbline 148
; Open_Panel_flag=1;
sts _Open_Panel_flag,R24
.dbline 149
; }
.dbline 150
; }
.dbline 151
; break;
xjmp L8
L17:
.dbline 157
;
; case 50: //工厂遥控器开关机
; //
;
;
; if(System_State==working)
lds R24,_System_State
cpi R24,3
brne L18
.dbline 158
; {
.dbline 160
; // UDR=0x90;
; if(close_machine_enable==1)
lds R24,_close_machine_enable
cpi R24,1
breq X6
xjmp L8
X6:
.dbline 161
; {
.dbline 163
; // UDR=0x91;
; Powerdown_signal=1;
ldi R24,1
sts _Powerdown_signal,R24
.dbline 164
; i2c_public|=1<<7;
lds R24,_i2c_public
ori R24,128
sts _i2c_public,R24
.dbline 165
; irda_data=ResultNec|(1<<7); //发送键码最高位置1
lds R24,_ResultNec
ori R24,128
sts _irda_data,R24
.dbline 166
; }
.dbline 167
; }
xjmp L8
L18:
.dbline 169
; else
; {
.dbline 171
; // infrared_open_enable=1;////开机
; if(open_machine_enable==1)
lds R24,_open_machine_enable
cpi R24,1
breq X7
xjmp L8
X7:
.dbline 172
; {
.dbline 173
; power_key_open_enable=1;
ldi R24,1
sts _power_key_open_enable,R24
.dbline 174
; }
.dbline 175
; }
.dbline 176
; break;
xjmp L8
L24:
.dbline 179
;
; case 51:
; if(System_State==working)
lds R24,_System_State
cpi R24,3
breq X8
xjmp L8
X8:
.dbline 180
; {
.dbline 181
; if(Fac_aging==0xff)
lds R24,_Fac_aging
cpi R24,255
brne L27
.dbline 182
; {
.dbline 183
; if(Fac_mode==0xff)
lds R24,_Fac_mode
cpi R24,255
brne L29
.dbline 184
; {
.dbline 185
; Fac_mode=0;
clr R2
sts _Fac_mode,R2
.dbline 186
; EEPROMwrite(0x90,0x00);
clr R18
ldi R16,144
ldi R17,0
xcall _EEPROMwrite
.dbline 187
; }
xjmp L30
L29:
.dbline 189
; else
; {
.dbline 190
; Fac_mode=0xff;
ldi R24,255
sts _Fac_mode,R24
.dbline 191
; EEPROMwrite(0x90,0xff);
ldi R18,255
ldi R16,144
ldi R17,0
xcall _EEPROMwrite
.dbline 192
; }
L30:
.dbline 193
; }
L27:
.dbline 195
;
; i2c_public|=1<<7;
lds R24,_i2c_public
ori R24,128
sts _i2c_public,R24
.dbline 196
; irda_data=ResultNec|(1<<7);
lds R24,_ResultNec
ori R24,128
sts _irda_data,R24
.dbline 197
; }
.dbline 199
;
; break;
xjmp L8
L31:
.dbline 202
;
; case 52:
; if(System_State==working)
lds R24,_System_State
cpi R24,3
brne L8
.dbline 203
; {
.dbline 204
; if(Fac_mode==0)
lds R2,_Fac_mode
tst R2
brne L34
.dbline 205
; {
.dbline 206
; Fac_aging=EEPROMread(0x80);
ldi R16,128
ldi R17,0
xcall _EEPROMread
sts _Fac_aging,R16
.dbline 207
; if(Fac_aging==0)
tst R16
brne L36
.dbline 208
; {
.dbline 209
; EEPROMwrite(0x80,0xff);
ldi R18,255
ldi R16,128
ldi R17,0
xcall _EEPROMwrite
.dbline 210
; }
xjmp L37
L36:
.dbline 212
; else
; {
.dbline 213
; EEPROMwrite(0x80,0x00);
clr R18
ldi R16,128
ldi R17,0
xcall _EEPROMwrite
.dbline 214
; }
L37:
.dbline 215
; }
L34:
.dbline 216
; i2c_public|=1<<7;
lds R24,_i2c_public
ori R24,128
sts _i2c_public,R24
.dbline 217
; irda_data=ResultNec|(1<<7);
lds R24,_ResultNec
ori R24,128
sts _irda_data,R24
.dbline 218
; }
.dbline 219
; break;
xjmp L8
L7:
.dbline 223
lds R24,_System_State
cpi R24,3
brne L8
.dbline 224
.dbline 225
lds R24,_i2c_public
ori R24,128
sts _i2c_public,R24
.dbline 227
lds R24,_ResultNec
ori R24,128
sts _irda_data,R24
.dbline 229
.dbline 230
L8:
.dbline -2
L6:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbend
.dbfunc e Nec_consumer_map _Nec_consumer_map fV
.area func_lit(rom, con, rel)
L54:
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L46
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L43
.word `L47
.word `L53
.word `L48
.word `L49
.word `L50
.word `L43
.word `L43
.word `L43
.word `L51
.word `L52
.area text(rom, con, rel)
.dbfile G:\McuControl\necdecode.c
.even
_Nec_consumer_map::
xcall push_gset1
.dbline -1
.dbline 236
;
;
; default: //开关机键不申请i2c通讯
; if(System_State==working)
; {
; i2c_public|=1<<7; //红外键码i2c发送申请
; //UDR=rc5_data_cmd;
; irda_data=ResultNec|(1<<7); //发送键码最高位置1
; // UDR=irda_data;
; }
; break;
;
; }
; }
;
; void Nec_consumer_map()
; {
.dbline 237
; NecData_Map=NecData[2];
lds R2,_NecData+2
sts _NecData_Map,R2
.dbline 238
; switch(NecData_Map)
mov R20,R2
clr R21
cpi R20,0
ldi R30,0
cpc R21,R30
brge X10
xjmp L43
X10:
ldi R24,73
ldi R25,0
cp R24,R20
cpc R25,R21
brge X11
xjmp L43
X11:
ldi R16,2
ldi R17,0
movw R18,R20
xcall empy16s
movw R30,R16
ldi R24,<L54
ldi R25,>L54
add R30,R24
adc R31,R25
lpm R0,Z+
lpm R1,Z
movw R30,R0
ijmp
X9:
.dbline 239
; {
L46:
.dbline 270
; case 0:
; case 1:
; case 2:
; case 3:
; case 4:
; case 5:
; case 6:
; case 7:
; case 8:
; case 9:
; case 10:
; case 11:
; case 12:
; case 13:
; case 14:
; case 15:
; case 16:
; case 17:
; case 18:
; case 19:
; case 20:
; case 21:
; case 22:
; case 23:
; case 24:
; case 25:
; case 26:
; case 27:
; case 28:
; case 29:
; ResultNec=NecData_Map;
lds R2,_NecData_Map
sts _ResultNec,R2
.dbline 271
; break;
xjmp L44
L47:
.dbline 273
; case 64:
; ResultNec=30;
ldi R24,30
sts _ResultNec,R24
.dbline 274
; break;
xjmp L44
L48:
.dbline 276
; case 66:
; ResultNec=31;
ldi R24,31
sts _ResultNec,R24
.dbline 277
; break;
xjmp L44
L49:
.dbline 279
; case 67:
; ResultNec=32;
ldi R24,32
sts _ResultNec,R24
.dbline 280
; break;
xjmp L44
L50:
.dbline 282
; case 68:
; ResultNec=33;
ldi R24,33
sts _ResultNec,R24
.dbline 283
; break;
xjmp L44
L51:
.dbline 285
; case 72:
; ResultNec=34;
ldi R24,34
sts _ResultNec,R24
.dbline 286
; break;
xjmp L44
L52:
.dbline 288
; case 73:
; ResultNec=35;
ldi R24,35
sts _ResultNec,R24
.dbline 289
; break;
xjmp L44
L53:
.dbline 291
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -