?? lyj.s
字號:
.module LYJ.c
.area text(rom, con, rel)
.dbfile D:\IccAvr\Pei\LYJ\LYJ.c
.dbfunc e PortInit _PortInit fV
.even
_PortInit::
.dbline -1
.dbline 49
; //ICC-AVR application builder : 2006-2-26 21:26:27
; // Target : 電動晾衣架 DC電機+紅外
; // Crystal: 8Mhz
;
; /*紅外解碼的方法 NEC格式 upd6121
; 1、9Ms的高電平啟動頭,然后是4.5Ms的低電平,如果2.25Ms時就有高電平,是持續信號,不處理
; 2、然后以一個高電平和一個低電平為1Bit,高電平時間是0.5625Ms=562us,
; 高低電平時間比為1:1時是Bit1,比為1:3時是Bit0
; 3、Timer1中斷執行100us采樣周期,9Ms=90,4.5Ms=45,高電平=5,低電平最多15
; 4、共讀入4Byte共24bit,第1、2Byte是CustomCode碼和其反碼,第3、4Byte是DataCode和其反碼
; 5、CustomCode正確和DataCode效驗正確的話,執行
; 6、紅外接收器輸出是反相的
; */
; #include <eeprom.h>
; #include "config.h"
; #include <string.h>
;
; #define VERSION 10
;
; #define CT1H 0x94;//CA01=10ms 最小應答間隔
; #define CT1L 0x01;//BF34=12ms AF01=15ms 9401=20ms
;
; #define T0N 10
; #define LEDON CLR(PORTB,LED);
; #define LEDOFF SET(PORTB,LED);
;
; #define CSTOP 1
; #define CUP 2
; #define CDOWN 3
; #define CLAMP 4
; #define CDIS 5
;
; //紅外命令按鍵碼
; #define IRSTOP 10
; #define IRUP 11
; #define IRDOWN 7
; #define IRLAMP 2
; #define IRDIS 14
;
; bit b20ms,bTimer,bCmdOk,bIrCmdOk;
; uchar T0Cnt,iCmd;
; uchar iPreBit,iHight,iLow,iIrMode;
; uchar iBitCount,iIrData[4];
;
; void DelayMs(char);
; void DelayUs(uint);
;
; void PortInit(void)
; {
.dbline 50
; PORTB = 0xFD;
ldi R24,253
out 0x18,R24
.dbline 51
; DDRB = 0x02;
ldi R24,2
out 0x17,R24
.dbline 52
; PORTC = 0x00; //m103 output only
clr R2
out 0x15,R2
.dbline 53
; DDRC = 0x7F;
ldi R24,127
out 0x14,R24
.dbline 54
; PORTD = 0x9F;
ldi R24,159
out 0x12,R24
.dbline 55
; DDRD = 0x60;
ldi R24,96
out 0x11,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e WdtInit _WdtInit fV
.even
_WdtInit::
.dbline -1
.dbline 62
;
; }
;
; //Watchdog initialize
; // prescale: 2048K
; void WdtInit(void)
; {
.dbline 63
; WDR();
wdr
.dbline 64
; WDTCR=(1<<WDTOE)|(1<<WDE);//!!注意:M8的WDT修改要先WDTOE,WDE=1 P42
ldi R24,24
out 0x21,R24
.dbline 65
; WDTCR=(1<<WDE)|(1<<WDP2)|(1<<WDP1)|(1<<WDP0);//2.2s
ldi R24,15
out 0x21,R24
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Timer0Init _Timer0Init fV
.even
_Timer0Init::
.dbline -1
.dbline 69
; }
;
; void Timer0Init(void)
; {
.dbline 70
; TCCR0 = 0x00; //stop
clr R2
out 0x33,R2
.dbline 71
; TCNT0 = 0x64; //set count
ldi R24,100
out 0x32,R24
.dbline 72
; TCCR0 = 0x05; //start timer
ldi R24,5
out 0x33,R24
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 18
rjmp _Timer0
.area text(rom, con, rel)
.dbfile D:\IccAvr\Pei\LYJ\LYJ.c
.dbfunc e Timer0 _Timer0 fV
.even
_Timer0::
rcall push_lset
.dbline -1
.dbline 77
; }
;
; #pragma interrupt_handler Timer0:10
; void Timer0(void)
; {
.dbline 78
; TCNT0 = 0x64; //reload counter value 20ms
ldi R24,100
out 0x32,R24
.dbline 80
;
; b20ms=1;
ldi R24,1
sts _b20ms,R24
.dbline 81
; if (--T0Cnt==0)
lds R24,_T0Cnt
subi R24,1
mov R2,R24
sts _T0Cnt,R2
tst R24
brne L5
.dbline 82
; {T0Cnt=T0N;
.dbline 82
ldi R24,10
sts _T0Cnt,R24
.dbline 83
; bTimer=1;
ldi R24,1
sts _bTimer,R24
.dbline 84
; }
L5:
.dbline 86
;
; CheckStop();//判斷限位開關
rcall _CheckStop
.dbline -2
L4:
rcall pop_lset
.dbline 0 ; func end
reti
.dbend
.dbfunc e Timer1Init _Timer1Init fV
.even
_Timer1Init::
.dbline -1
.dbline 94
;
; }
; //TIMER1 initialize - prescale:8
; // WGM: 0) Normal, TOP=0xFFFF
; // desired value: 100uSec
; // actual value: 100.000uSec (0.0%)
; void Timer1Init(void)
; {
.dbline 95
; TCCR1B = 0x00; //stop
clr R2
out 0x2e,R2
.dbline 96
; TCNT1H = 0xFF; //setup
ldi R24,255
out 0x2d,R24
.dbline 97
; TCNT1L = 0x9C;
ldi R24,156
out 0x2c,R24
.dbline 98
; OCR1AH = 0x00;
out 0x2b,R2
.dbline 99
; OCR1AL = 0x64;
ldi R24,100
out 0x2a,R24
.dbline 100
; OCR1BH = 0x00;
out 0x29,R2
.dbline 101
; OCR1BL = 0x64;
out 0x28,R24
.dbline 102
; ICR1H = 0x00;
out 0x27,R2
.dbline 103
; ICR1L = 0x64;
out 0x26,R24
.dbline 104
; TCCR1A = 0x00;
out 0x2f,R2
.dbline 105
; TCCR1B = 0x02; //start Timer
ldi R24,2
out 0x2e,R24
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 16
rjmp _Timer1
.area text(rom, con, rel)
.dbfile D:\IccAvr\Pei\LYJ\LYJ.c
.dbfunc e Timer1 _Timer1 fV
.even
_Timer1::
rcall push_lset
.dbline -1
.dbline 110
; }
;
; #pragma interrupt_handler Timer1:9
; void Timer1(void)
; {
.dbline 112
; //TIMER1 has overflowed
; TCNT1H = 0xFF; //reload counter high value
ldi R24,255
out 0x2d,R24
.dbline 113
; TCNT1L = 0x9C; //reload counter low value
ldi R24,156
out 0x2c,R24
.dbline 115
;
; CheckIR();//紅外解碼
rcall _CheckIR
.dbline -2
L8:
rcall pop_lset
.dbline 0 ; func end
reti
.dbend
.dbfunc e IoInit _IoInit fV
.even
_IoInit::
.dbline -1
.dbline 120
; }
;
; //call this routine to initialize all peripherals
; void IoInit(void)
; {
.dbline 122
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 123
; PortInit();
rcall _PortInit
.dbline 124
; WdtInit();
rcall _WdtInit
.dbline 125
; Timer0Init();
rcall _Timer0Init
.dbline 126
; Timer1Init();
rcall _Timer1Init
.dbline 129
; //ADCSR&=~BIT(ADEN);
;
; MCUCR = 0x00;//int0 low level在掉電模式,低電平觸發才能喚醒,下跳沿不行
clr R2
out 0x35,R2
.dbline 130
; GICR = 0x00;//Int Mask,Int0 disable
out 0x3b,R2
.dbline 131
; TIMSK = 0x05; //timer interrupt Mask: Timer0,1 enable
ldi R24,5
out 0x39,R24
.dbline 132
; SEI(); //re-enable interrupts
sei
.dbline -2
L9:
.dbline 0 ; func end
ret
.dbend
.dbfunc e WdtOn _WdtOn fV
.even
_WdtOn::
.dbline -1
.dbline 138
; //all peripherals are now initialized
; }
;
;
; void WdtOn()
; {
.dbline 139
; WDR();
wdr
.dbline 140
; WDTCR=0x0f;
ldi R24,15
out 0x21,R24
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbend
.dbfunc e WdtOff _WdtOff fV
.even
_WdtOff::
.dbline -1
.dbline 145
;
; }
;
; void WdtOff()
; {
.dbline 146
; CLI();//!!必須,WDTOE置位后必須4個時鐘內清 WDE,才能真正關斷WDT
cli
.dbline 147
; WDR();
wdr
.dbline 148
; WDTCR |=(BIT(WDTOE)|(BIT(WDE)));
in R24,0x21
ori R24,24
out 0x21,R24
.dbline 150
; //WDTCR&=~BIT(WDE);//0;//off
; WDTCR=0x07;
ldi R24,7
out 0x21,R24
.dbline 151
; SEI();
sei
.dbline -2
L11:
.dbline 0 ; func end
ret
.dbend
.dbfunc e PwrIdle _PwrIdle fV
.even
_PwrIdle::
.dbline -1
.dbline 155
; }
;
; void PwrIdle()
; {//P30 MCUCR 休眠控制和INT0,1,
.dbline 156
; MCUCR&=0x0f;
in R24,0x35
andi R24,15
out 0x35,R24
.dbline 157
; MCUCR |=BIT(SE);
in R24,0x35
ori R24,128
out 0x35,R24
.dbline 158
; asm("sleep");
sleep
.dbline -2
L12:
.dbline 0 ; func end
ret
.dbend
.dbfunc e PwrDown _PwrDown fV
.even
_PwrDown::
.dbline -1
.dbline 162
; }
;
; void PwrDown()
; {
.dbline 163
; MCUCR&=0x0f;
in R24,0x35
andi R24,15
out 0x35,R24
.dbline 164
; MCUCR |=0x60;//0x60掉電 0x70省電
in R24,0x35
ori R24,96
out 0x35,R24
.dbline 165
; asm("sleep");
sleep
.dbline -2
L13:
.dbline 0 ; func end
ret
.dbend
.dbfunc e TestIR _TestIR fV
.even
_TestIR::
.dbline -1
.dbline 171
; }
;
; //測試紅外輸出
; //無信號時有小許干擾輸出,遙控器保持按鍵時有持續輸出
; void TestIR()
; {
.dbline 172
; if ((PIND&(1<<IR))!=0)
sbis 0x10,7
rjmp L15
.dbline 173
; {BeepOff();}
.dbline 173
rcall _BeepOff
.dbline 173
rjmp L16
L15:
.dbline 175
.dbline 175
rcall _BeepOn
.dbline 175
L16:
.dbline -2
L14:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 180
; else
; {BeepOn();}
;
; }
;
; void main(void)
; {
.dbline 182
;
; IoInit();
rcall _IoInit
.dbline 183
; SystemIni();
rcall _SystemIni
.dbline 184
; Beep();
rcall _Beep
rjmp L19
L18:
.dbline 186
; while (1)
; {
.dbline 187
; if (bTimer) TimerFunc();
lds R2,_bTimer
tst R2
breq L21
.dbline 187
rcall _TimerFunc
L21:
.dbline 189
; //TestIR();
; if (bIrCmdOk) CheckIrCmd();
lds R2,_bIrCmdOk
tst R2
breq L23
.dbline 189
rcall _CheckIrCmd
L23:
.dbline 190
; if (bCmdOk) ReadCmd();
lds R2,_bCmdOk
tst R2
breq L25
.dbline 190
rcall _ReadCmd
L25:
.dbline 191
rcall _PwrIdle
.dbline 192
L19:
.dbline 185
rjmp L18
X0:
.dbline 192
; PwrIdle();
; };
.dbline -2
L17:
.dbline 0 ; func end
ret
.dbend
.dbfunc e ReadCmd _ReadCmd fV
.even
_ReadCmd::
rcall push_gset1
.dbline -1
.dbline 198
;
; }
;
; //命令執行
; void ReadCmd()
; {
.dbline 199
; bCmdOk=0;
clr R2
sts _bCmdOk,R2
.dbline 201
; //Beep();
; switch (iCmd)
lds R20,_iCmd
clr R21
cpi R20,1
ldi R30,0
cpc R21,R30
breq L31
cpi R20,2
ldi R30,0
cpc R21,R30
breq L32
cpi R20,3
ldi R30,0
cpc R21,R30
breq L33
cpi R20,4
ldi R30,0
cpc R21,R30
breq L34
cpi R20,5
ldi R30,0
cpc R21,R30
breq L37
rjmp L28
X1:
.dbline 202
; {
L31:
.dbline 204
; case CSTOP:
; MotorStop();
rcall _MotorStop
.dbline 205
; BeepN(2);
ldi R16,2
ldi R17,0
rcall _BeepN
.dbline 206
; break;
rjmp L29
L32:
.dbline 208
; case CUP:
; MotorUp();
rcall _MotorUp
.dbline 209
; BeepN(1);
ldi R16,1
ldi R17,0
rcall _BeepN
.dbline 210
; break;
rjmp L29
L33:
.dbline 212
; case CDOWN:
; MotorDown();
rcall _MotorDown
.dbline 213
; BeepN(1);
ldi R16,1
ldi R17,0
rcall _BeepN
.dbline 214
; break;
rjmp L29
L34:
.dbline 216
; case CLAMP:
; if ((PORTC&(1<<LAMP))==0)
sbic 0x15,2
rjmp L35
.dbline 217
; { LampOn();
.dbline 217
rcall _LampOn
.dbline 218
; BeepN(1);
ldi R16,1
ldi R17,0
rcall _BeepN
.dbline 219
; }
rjmp L29
L35:
.dbline 221
; else
; { LampOff();
.dbline 221
rcall _LampOff
.dbline 222
; BeepN(2);
ldi R16,2
ldi R17,0
rcall _BeepN
.dbline 223
; }
.dbline 224
; break;
rjmp L29
L37:
.dbline 226
; case CDIS:
; if ((PORTC&(1<<DIS))==0)
sbic 0x15,3
rjmp L38
.dbline 227
; { DisOn();
.dbline 227
rcall _DisOn
.dbline 228
; BeepN(1);
ldi R16,1
ldi R17,0
rcall _BeepN
.dbline 229
; }
rjmp L29
L38:
.dbline 231
; else
; { DisOff();
.dbline 231
rcall _DisOff
.dbline 232
; BeepN(2);
ldi R16,2
ldi R17,0
rcall _BeepN
.dbline 233
; }
.dbline 234
; break;
L28:
L29:
.dbline -2
L27:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbend
.dbfunc e CheckIR _CheckIR fV
; iPos -> R16
; iNowBit -> R18
.even
_CheckIR::
.dbline -1
.dbline 240
; }
; }
;
; //紅外解碼
; void CheckIR()
; {uchar iNowBit,iPos;
.dbline 242
clr R2
in R24,0x10
andi R24,128
cp R2,R24
brsh L41
.dbline 242
clr R18
rjmp L42
L41:
.dbline 242
;
; if ((PIND&(1<<IR))>0) iNowBit=0;else iNowBit=1;//先反相
ldi R18,1
L42:
.dbline 245
;
; //把信號持續的處理作為公共處理
; if ((iPreBit==1)&&(iNowBit==1))//hight++
lds R24,_iPreBit
cpi R24,1
brne L43
cpi R18,1
brne L43
.dbline 246
; { iHight++;
.dbline 246
lds R24,_iHight
subi R24,255 ; addi 1
sts _iHight,R24
.dbline 247
; return;
rjmp L40
L43:
.dbline 249
; }
; if ((iPreBit==0)&&(iNowBit==0))//low++
lds R2,_iPreBit
tst R2
brne L45
tst R18
brne L45
.dbline 250
; { iLow++;
.dbline 250
lds R24,_iLow
subi R24,255 ; addi 1
sts _iLow,R24
.dbline 251
; return;
rjmp L40
L45:
.dbline 254
; }
;
; switch (iIrMode)
lds R16,_iIrMode
clr R17
cpi R16,0
cpc R16,R17
breq L50
X2:
cpi R16,1
ldi R30,0
cpc R17,R30
breq L57
cpi R16,2
ldi R30,0
cpc R17,R30
brne X6
rjmp L65
X6:
rjmp L47
X3:
.dbline 255
; {
L50:
.dbline 257
; case 0://等待9ms的高電平
; if ((iPreBit==0)&&(iNowBit==1))//0->1:start
lds R2,_iPreBit
tst R2
brne L51
cpi R18,1
brne L51
.dbline 258
; { iPreBit=1;
.dbline 258
ldi R24,1
sts _iPreBit,R24
.dbline 259
; iHight=1;
sts _iHight,R24
.dbline 260
; return;
rjmp L40
L51:
.dbline 263
; }
;
; if ((iPreBit==1)&&(iNowBit==0))//1->0
lds R24,_iPreBit
cpi R24,1
breq X7
rjmp L48
X7:
tst R18
breq X8
rjmp L48
X8:
.dbline 264
; { iPreBit=0;
.dbline 264
clr R2
sts _iPreBit,R2
.dbline 265
; if (iHight>85)//9.0ms
ldi R24,85
lds R2,_iHight
cp R24,R2
brsh L55
.dbline 266
; { iIrMode=1;
.dbline 266
ldi R24,1
sts _iIrMode,R24
.dbline 267
; iLow=1;
sts _iLow,R24
.dbline 268
; iHight=0;
clr R2
sts _iHight,R2
.dbline 270
; //bCmdOk=1;iCmd=10;//Test..
; }
rjmp L40
L55:
.dbline 272
; else
; {iHight=0;//reset
.dbline 272
clr R2
sts _iHight,R2
.dbline 273
; }
.dbline 274
; return;
rjmp L40
X4:
.dbline 276
; }
; break;
L57:
.dbline 279
;
; case 1://等待4.5ms的低電平
; if ((iPreBit==0)&&(iNowBit==1))//0->1
lds R2,_iPreBit
tst R2
breq X9
rjmp L48
X9:
cpi R18,1
breq X10
rjmp L48
X10:
.dbline 280
; { iPreBit=1;
.dbline 280
ldi R24,1
sts _iPreBit,R24
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -