📄 timer.s
字号:
; TCCR2 = 0x00; //stop
out 0x25,R2
L77:
xcall pop_gset2
.dbline 0 ; func end
ret
.even
_T3_init::
xcall push_gset2
;
; // TCCR2 = 0x05; //start
; }
; void T3_init()
; {
; T3.num = 0;
clr R2
sts _T3,R2
; T3.on = 0;
sts _T3+1,R2
; T3.type = 0; //类型,reapeat=1 单次=0
sts _T3+2,R2
; T3.ticks = 0; //执行周期
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
sts _T3+3+1,R21
sts _T3+3,R20
sts _T3+3+2+1,R23
sts _T3+3+2,R22
; T3.tickleft = 0; //剩余时间,单位为秒
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
sts _T3+7+1,R21
sts _T3+7,R20
sts _T3+7+2+1,R23
sts _T3+7+2,R22
; T3.adjustedticks = 0;
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
sts _T3+11+1,R21
sts _T3+11,R20
sts _T3+11+2+1,R23
sts _T3+11+2,R22
; TCCR3B = 0x00; //stop
sts 138,R2
; TCCR3A = 0x00;
sts 139,R2
L83:
xcall pop_gset2
.dbline 0 ; func end
ret
.even
_mcu_sleep::
; }
; void mcu_sleep()
; {
; MCUCR = 0x38;
ldi R24,56
out 0x35,R24
; asm("sleep");
sleep
L89:
.dbline 0 ; func end
ret
.area vector(rom, abs)
.org 64
jmp _timer0_ovf_isr
.area text(rom, con, rel)
; t_count -> R10
.even
_timer0_ovf_isr::
xcall push_lset
xcall push_gset3
; }
;
; #pragma interrupt_handler timer0_ovf_isr:17
; void timer0_ovf_isr(void)
; {
; unsigned char t_count = 6000;
ldi R24,6000
ldi R25,23
mov R10,R24
; //led2Toggle();
; // printf("T0\n");
; //led0Toggle();
; if (T0.tickleft == 0)
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
lds R4,_T0+7+2
lds R5,_T0+7+2+1
lds R2,_T0+7
lds R3,_T0+7+1
cp R2,R20
cpc R3,R21
cpc R4,R22
cpc R5,R23
brne L91
; {
; post(T0_timeout);
ldi R16,<PL_T0_timeout
ldi R17,>PL_T0_timeout
xcall _post
; adjustPower();
xcall _adjustPower
; if (T0.type==1)
lds R24,_T0+2
cpi R24,1
brne L94
; {
; T0.tickleft = T0.ticks;
lds R4,_T0+3+2
lds R5,_T0+3+2+1
lds R2,_T0+3
lds R3,_T0+3+1
sts _T0+7+1,R3
sts _T0+7,R2
sts _T0+7+2+1,R5
sts _T0+7+2,R4
; T0.on =1;
ldi R24,1
sts _T0+1,R24
; }
xjmp L95
L94:
; else
; {
; TCCR0 = 0x0;
clr R2
out 0x33,R2
; TIMSK &= ~0x01;
in R24,0x37
andi R24,254
out 0x37,R24
; T0.on =0;
sts _T0+1,R2
; return ;
xjmp L90
L95:
; }
; }
L91:
;
; if (T0.tickleft > 7000)
ldi R20,88
ldi R21,27
ldi R22,0
ldi R23,0
lds R4,_T0+7+2
lds R5,_T0+7+2+1
lds R2,_T0+7
lds R3,_T0+7+1
cp R20,R2
cpc R21,R3
cpc R22,R4
cpc R23,R5
brsh L101
; {
; T0.tickleft -= 7000;
ldi R20,88
ldi R21,27
ldi R22,0
ldi R23,0
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
sts _T0+7+1,R3
sts _T0+7,R2
sts _T0+7+2+1,R5
sts _T0+7+2,R4
; TCNT0 = 0x0; //setup
clr R2
out 0x32,R2
; t_count = t_count*72/10-1;
ldi R24,72
mul R24,R10
movw R16,R0
ldi R18,10
ldi R19,0
xcall div16s
movw R24,R16
sbiw R24,1
mov R10,R24
; }
xjmp L102
L101:
; else
; {
; t_count = T0.tickleft*72/10 -1;
lds R4,_T0+7+2
lds R5,_T0+7+2+1
lds R2,_T0+7
lds R3,_T0+7+1
ldi R20,72
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R20
movw R18,R22
xcall empy32u
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall div32u
movw R2,R16
movw R4,R18
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
mov R10,R2
; T0.tickleft =0;
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
sts _T0+7+1,R21
sts _T0+7,R20
sts _T0+7+2+1,R23
sts _T0+7+2,R22
; TCNT0 = 0xff - (t_count & 0xff); //setup
mov R24,R2
clr R25
andi R25,0
ldi R30,255
ldi R31,0
sub R30,R24
sbc R31,R25
out 0x32,R30
;
; }
L102:
;
; TCCR0 = 0x07; //1024分频
ldi R24,7
out 0x33,R24
; TIMSK |= 0x01;
in R24,0x37
ori R24,1
out 0x37,R24
; adjustPower();
xcall _adjustPower
L90:
xcall pop_gset3
xcall pop_lset
.dbline 0 ; func end
reti
.area vector(rom, abs)
.org 56
jmp _timer1_ovf_isr
.area text(rom, con, rel)
; t_count -> R10,R11
.even
_timer1_ovf_isr::
xcall push_lset
xcall push_gset3
; // led0Toggle();
; // post(mcu_sleep);
;
; }
;
;
;
; #pragma interrupt_handler timer1_ovf_isr:15
; void timer1_ovf_isr(void)
; {
; //TIMER1 has overflowed
; unsigned int t_count = 8000;
ldi R24,8000
ldi R25,31
movw R10,R24
; // printf("T1\n");
; led0Toggle();
xcall _led0Toggle
; if (T1.tickleft == 0)
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
lds R4,_T1+7+2
lds R5,_T1+7+2+1
lds R2,_T1+7
lds R3,_T1+7+1
cp R2,R20
cpc R3,R21
cpc R4,R22
cpc R5,R23
brne L108
; {
; post(T1_timeout);
ldi R16,<PL_T1_timeout
ldi R17,>PL_T1_timeout
xcall _post
; if (T1.type==1)
lds R24,_T1+2
cpi R24,1
brne L111
; {
; T1.tickleft = T1.ticks;
lds R4,_T1+3+2
lds R5,_T1+3+2+1
lds R2,_T1+3
lds R3,_T1+3+1
sts _T1+7+1,R3
sts _T1+7,R2
sts _T1+7+2+1,R5
sts _T1+7+2,R4
; T1.on =1;
ldi R24,1
sts _T1+1,R24
; }
xjmp L112
L111:
; else
; {
; TCCR1B = 0x0;
clr R2
out 0x2e,R2
; TIMSK &= ~0x04;
in R24,0x37
andi R24,251
out 0x37,R24
; T1.on =0;
sts _T1+1,R2
; return;
xjmp L107
L112:
; }
; }
L108:
;
; if (T1.tickleft > 9000)
ldi R20,40
ldi R21,35
ldi R22,0
ldi R23,0
lds R4,_T1+7+2
lds R5,_T1+7+2+1
lds R2,_T1+7
lds R3,_T1+7+1
cp R20,R2
cpc R21,R3
cpc R22,R4
cpc R23,R5
brsh L118
; {
; T1.tickleft -= 9000;
ldi R20,40
ldi R21,35
ldi R22,0
ldi R23,0
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
sts _T1+7+1,R3
sts _T1+7,R2
sts _T1+7+2+1,R5
sts _T1+7+2,R4
; TCNT1H = 0x0; //setup
clr R2
out 0x2d,R2
; TCNT1L = 0x0;
out 0x2c,R2
; t_count = t_count*72/10-1;
ldi R16,72
ldi R17,0
movw R18,R10
xcall empy16s
ldi R18,10
ldi R19,0
xcall div16u
movw R24,R16
sbiw R24,1
movw R10,R24
; }
xjmp L119
L118:
; else
; {
; t_count = T1.tickleft*72/10 -1;
lds R4,_T1+7+2
lds R5,_T1+7+2+1
lds R2,_T1+7
lds R3,_T1+7+1
ldi R20,72
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R20
movw R18,R22
xcall empy32u
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall div32u
movw R2,R16
movw R4,R18
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
movw R10,R2
; T1.tickleft =0;
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
sts _T1+7+1,R21
sts _T1+7,R20
sts _T1+7+2+1,R23
sts _T1+7+2,R22
; TCNT1H = 0xff - ((t_count>>8) & 0xff); //setup
movw R24,R2
mov R24,R25
clr R25
andi R25,0
ldi R30,255
ldi R31,0
sub R30,R24
sbc R31,R25
out 0x2d,R30
; TCNT1L = 0xff - (t_count & 0xff);
movw R24,R2
andi R25,0
ldi R30,255
ldi R31,0
sub R30,R24
sbc R31,R25
out 0x2c,R30
; }
L119:
; TCCR1B = 0x05; //1024分频
ldi R24,5
out 0x2e,R24
; TIMSK |= 0x04;
in R24,0x37
ori R24,4
out 0x37,R24
L107:
xcall pop_gset3
xcall pop_lset
.dbline 0 ; func end
reti
.area vector(rom, abs)
.org 40
jmp _timer2_ovf_isr
.area text(rom, con, rel)
; t_count -> R10
.even
_timer2_ovf_isr::
xcall push_lset
xcall push_gset3
;
;
; }
;
;
; #pragma interrupt_handler timer2_ovf_isr:11
; void timer2_ovf_isr(void)
; {
; unsigned char t_count = 30;
ldi R24,30
mov R10,R24
; // printf("T2\n");
; if (T2.tickleft == 0)
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
lds R4,_T2+7+2
lds R5,_T2+7+2+1
lds R2,_T2+7
lds R3,_T2+7+1
cp R2,R20
cpc R3,R21
cpc R4,R22
cpc R5,R23
brne L125
; {
; post(T2_timeout);
ldi R16,<PL_T2_timeout
ldi R17,>PL_T2_timeout
xcall _post
; if (T2.type==1)
lds R24,_T2+2
cpi R24,1
brne L128
; {
; T2.tickleft = T2.ticks;
lds R4,_T2+3+2
lds R5,_T2+3+2+1
lds R2,_T2+3
lds R3,_T2+3+1
sts _T2+7+1,R3
sts _T2+7,R2
sts _T2+7+2+1,R5
sts _T2+7+2,R4
; T2.on=1;
ldi R24,1
sts _T2+1,R24
; }
xjmp L129
L128:
; else
; {
; TCCR2 = 0x0;
clr R2
out 0x25,R2
; TIMSK &= ~0x40;
in R24,0x37
andi R24,191
out 0x37,R24
; T2.on =0;
sts _T2+1,R2
; return ;
xjmp L124
L129:
; }
; }
L125:
;
; if (T2.tickleft > 35)
ldi R20,35
ldi R21,0
ldi R22,0
ldi R23,0
lds R4,_T2+7+2
lds R5,_T2+7+2+1
lds R2,_T2+7
lds R3,_T2+7+1
cp R20,R2
cpc R21,R3
cpc R22,R4
cpc R23,R5
brsh L135
; {
; T2.tickleft -= 35;
ldi R20,35
ldi R21,0
ldi R22,0
ldi R23,0
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
sts _T2+7+1,R3
sts _T2+7,R2
sts _T2+7+2+1,R5
sts _T2+7+2,R4
; TCNT2 = 0x0; //setup
clr R2
out 0x24,R2
; t_count = t_count*256/1000-1;
mov R18,R10
clr R19
ldi R16,256
ldi R17,1
xcall empy16s
ldi R18,1000
ldi R19,3
xcall div16s
movw R24,R16
sbiw R24,1
mov R10,R24
; }
xjmp L136
L135:
; else
; {
; t_count = T2.tickleft*256/1000 -1;
lds R4,_T2+7+2
lds R5,_T2+7+2+1
lds R2,_T2+7
lds R3,_T2+7+1
ldi R20,0
ldi R21,1
ldi R22,0
ldi R23,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R20
movw R18,R22
xcall empy32u
ldi R20,232
ldi R21,3
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall div32u
movw R2,R16
movw R4,R18
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
mov R10,R2
; T2.tickleft =0;
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
sts _T2+7+1,R21
sts _T2+7,R20
sts _T2+7+2+1,R23
sts _T2+7+2,R22
; TCNT2 = 0xff - (t_count & 0xff); //setup
mov R24,R2
clr R25
andi R25,0
ldi R30,255
ldi R31,0
sub R30,R24
sbc R31,R25
out 0x24,R30
;
; }
L136:
; TCCR2 = 0x05; //1024分频
ldi R24,5
out 0x25,R24
; TIMSK |= 0x40;
in R24,0x37
ori R24,64
out 0x37,R24
L124:
xcall pop_gset3
xcall pop_lset
.dbline 0 ; func end
reti
.area vector(rom, abs)
.org 116
jmp _timer3_ovf_isr
.area text(rom, con, rel)
; t_count -> R10,R11
.even
_timer3_ovf_isr::
xcall push_lset
xcall push_gset3
;
; }
;
;
;
; #pragma interrupt_handler timer3_ovf_isr:30
; void timer3_ovf_isr(void)
; {
; //TIMER3 has overflowed
; unsigned int t_count = 8000;
ldi R24,8000
ldi R25,31
movw R10,R24
;
; if (T3.tickleft == 0)
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
lds R4,_T3+7+2
lds R5,_T3+7+2+1
lds R2,_T3+7
lds R3,_T3+7+1
cp R2,R20
cpc R3,R21
cpc R4,R22
cpc R5,R23
brne L142
; {// led0Toggle();
; post(T3_timeout);
ldi R16,<PL_T3_timeout
ldi R17,>PL_T3_timeout
xcall _post
; // printf("post success\n");
;
; if (T3.type==1)
lds R24,_T3+2
cpi R24,1
brne L145
; {
; T3.tickleft = T3.ticks;
lds R4,_T3+3+2
lds R5,_T3+3+2+1
lds R2,_T3+3
lds R3,_T3+3+1
sts _T3+7+1,R3
sts _T3+7,R2
sts _T3+7+2+1,R5
sts _T3+7+2,R4
; T3.on =1;
ldi R24,1
sts _T3+1,R24
; }
xjmp L146
L145:
; else
; {
; TCCR3B = 0x0;
clr R2
sts 138,R2
; ETIMSK &= ~0x04;
lds R24,125
andi R24,251
sts 125,R24
; T3.on =0;
sts _T3+1,R2
; return ;
xjmp L141
L146:
; }
; }
L142:
; if (T3.tickleft > 9000)
ldi R20,40
ldi R21,35
ldi R22,0
ldi R23,0
lds R4,_T3+7+2
lds R5,_T3+7+2+1
lds R2,_T3+7
lds R3,_T3+7+1
cp R20,R2
cpc R21,R3
cpc R22,R4
cpc R23,R5
brsh L152
; {
; T3.tickleft -= 9000;
ldi R20,40
ldi R21,35
ldi R22,0
ldi R23,0
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
sts _T3+7+1,R3
sts _T3+7,R2
sts _T3+7+2+1,R5
sts _T3+7+2,R4
; TCNT3H = 0x0; //setup
clr R2
sts 137,R2
; TCNT3L = 0x0;
sts 136,R2
; t_count = t_count*72/10-1;
ldi R16,72
ldi R17,0
movw R18,R10
xcall empy16s
ldi R18,10
ldi R19,0
xcall div16u
movw R24,R16
sbiw R24,1
movw R10,R24
; }
xjmp L153
L152:
; else
; {
; t_count = T3.tickleft*72/10 -1;
lds R4,_T3+7+2
lds R5,_T3+7+2+1
lds R2,_T3+7
lds R3,_T3+7+1
ldi R20,72
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R20
movw R18,R22
xcall empy32u
ldi R20,10
ldi R21,0
ldi R22,0
ldi R23,0
st -y,R23
st -y,R22
st -y,R21
st -y,R20
xcall div32u
movw R2,R16
movw R4,R18
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
movw R10,R2
; T3.tickleft =0;
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
sts _T3+7+1,R21
sts _T3+7,R20
sts _T3+7+2+1,R23
sts _T3+7+2,R22
; TCNT3H = 0xff - ((t_count>>8) & 0xff); //setup
movw R24,R2
mov R24,R25
clr R25
andi R25,0
ldi R30,255
ldi R31,0
sub R30,R24
sbc R31,R25
sts 137,R30
; TCNT3L = 0xff - (t_count & 0xff);
movw R24,R2
andi R25,0
ldi R30,255
ldi R31,0
sub R30,R24
sbc R31,R25
sts 136,R30
; }
L153:
; TCCR3B = 0x05; //1024分频
ldi R24,5
sts 138,R24
; ETIMSK |= 0x04;
lds R24,125
ori R24,4
sts 125,R24
L141:
xcall pop_gset3
xcall pop_lset
.dbline 0 ; func end
reti
.area bss(ram, con, rel)
_T3::
.blkb 15
_T2::
.blkb 15
_T1::
.blkb 15
_T0::
.blkb 15
.area func_lit
PL_T3_timeout: .word `_T3_timeout
PL_T2_timeout: .word `_T2_timeout
PL_T1_timeout: .word `_T1_timeout
PL_T0_timeout: .word `_T0_timeout
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -