timer.s
来自「mega128平台下」· S 代码 · 共 1,657 行 · 第 1/2 页
S
1,657 行
.dbline 0 ; func end
ret
.even
_T2_init::
xcall push_gset2
;
; //TCCR1B = 0x05; //start Timer
; }
;
;
;
; void T2_init()
; {
; T2.num = 0;
clr R2
sts _T2,R2
; T2.on = 0;
sts _T2+1,R2
; T2.type = 0; //类型,reapeat=1 单次=0
sts _T2+2,R2
; T2.ticks = 0; //执行周期
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
sts _T2+3+1,R21
sts _T2+3,R20
sts _T2+3+2+1,R23
sts _T2+3+2,R22
; 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
; T2.adjustedticks = 0;
ldi R20,0
ldi R21,0
ldi R22,0
ldi R23,0
sts _T2+11+1,R21
sts _T2+11,R20
sts _T2+11+2+1,R23
sts _T2+11+2,R22
; TCCR2 = 0x00; //stop
out 0x25,R2
L69:
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
L75:
xcall pop_gset2
.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;
; // printf("T0\n");
; 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 L82
; {
; post(T0_timeout);
ldi R16,<PL_T0_timeout
ldi R17,>PL_T0_timeout
xcall _post
; if (T0.type==1)
lds R24,_T0+2
cpi R24,1
brne L85
; 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
xjmp L86
L85:
;
; else
; {
; TIMSK &= ~0x01;
in R24,0x37
andi R24,254
out 0x37,R24
; return ;
xjmp L81
L86:
; }
; }
L82:
;
; if (T0.tickleft > 900)
ldi R20,132
ldi R21,3
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 L90
; {
; T0.tickleft -= 900;
ldi R20,132
ldi R21,3
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
; }
xjmp L91
L90:
; else
; {
; t_count = T0.tickleft*256/1000 -1;
lds R4,_T0+7+2
lds R5,_T0+7+2+1
lds R2,_T0+7
lds R3,_T0+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
; 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
;
; }
L91:
; TCCR0 = 0x05; //1024分频
ldi R24,5
out 0x33,R24
; TIMSK |= 0x01;
in R24,0x37
ori R24,1
out 0x37,R24
L81:
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
;
; }
;
;
;
; #pragma interrupt_handler timer1_ovf_isr:15
; void timer1_ovf_isr(void)
; {
; //TIMER1 has overflowed
; unsigned int t_count;
; // printf("T1\n");
; 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 L97
; {
; 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 L100
; 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
xjmp L101
L100:
; else
; {
; TIMSK &= ~0x04;
in R24,0x37
andi R24,251
out 0x37,R24
; return;
xjmp L96
L101:
; }
; }
L97:
;
; 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 L105
; {
; 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
; }
xjmp L106
L105:
; 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
; }
L106:
; TCCR1B = 0x05; //1024分频
ldi R24,5
out 0x2e,R24
; TIMSK |= 0x04;
in R24,0x37
ori R24,4
out 0x37,R24
L96:
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;
; // 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 L112
; {
; 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 L115
; 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
xjmp L116
L115:
; else
; {
; TIMSK &= ~0x40;
in R24,0x37
andi R24,191
out 0x37,R24
; return ;
xjmp L111
L116:
; }
; }
L112:
;
; 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 L120
; {
; 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
; }
xjmp L121
L120:
; 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
;
; }
L121:
; TCCR2 = 0x05; //1024分频
ldi R24,5
out 0x25,R24
; TIMSK |= 0x40;
in R24,0x37
ori R24,64
out 0x37,R24
L111:
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;
;
; 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 L127
; { led0Toggle();
xcall _led0Toggle
; if( post(T3_timeout))
ldi R16,<PL_T3_timeout
ldi R17,>PL_T3_timeout
xcall _post
tst R16
breq L130
; // printf("post success\n");
;
; if (T3.type==1)
lds R24,_T3+2
cpi R24,1
brne L132
; 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
xjmp L133
L132:
; else
; {
; ETIMSK &= ~0x04;
lds R24,125
andi R24,251
sts 125,R24
; return ;
xjmp L126
L133:
L130:
; }
; }
L127:
; 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 L137
; {
; 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
; }
xjmp L138
L137:
; 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
; }
L138:
; TCCR3B = 0x05; //1024分频
ldi R24,5
sts 138,R24
; ETIMSK |= 0x04;
lds R24,125
ori R24,4
sts 125,R24
L126:
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 + =
减小字号Ctrl + -
显示快捷键?