⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.s

📁 mega128平台下
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module timer.c
	.area text(rom, con, rel)
;        t_count -> R10
;          count -> R10,R11
;           type -> R12
	.even
_start_T0::
	xcall push_gset4
	movw R10,R18
	mov R12,R16
; #include "timer.h"
; //#include "schedule.h"
; #include<iom128v.h>
; #include <macros.h>
; 
; Timer_struct T0,T1,T2,T3;
; 
; void mcu_sleep();
; /*
; //Timer接口
; //Timer0
; void start_T0(char type, unsigned int count);
; void stop_T0(void);
; //Timer1
; void start_T1(char type, unsigned int count);
; void stop_T1(void);
; //Timer2
; void start_T2(char type, unsigned int count);
; void stop_T2(void);
; //Timer3
; void start_T3(char type, unsigned int count);
; void stop_T3(void);
; //init
; void T0_init();
; void T1_init();
; void T2_init();
; void T3_init();
; */
; //Timer接口
; //Timer0
; void start_T0(char type, unsigned int count)
; { 
;    //1024分频,外部时钟,最大7s计数,秒级精度100%
;     unsigned char t_count; 
;  
;    if (type==1)
	mov R24,R12
	cpi R24,1
	brne L2
;       T0.type = 1;
	ldi R24,1
	sts _T0+2,R24
	xjmp L3
L2:
;    else 
;       T0.type = 0; 
	clr R2
	sts _T0+2,R2
L3:
;    T0.ticks = count;
	movw R2,R10
	clr R4
	clr R5
	sts _T0+3+1,R3
	sts _T0+3,R2
	sts _T0+3+2+1,R5
	sts _T0+3+2,R4
;    T0.tickleft = count;
	clr R4
	clr R5
	sts _T0+7+1,R3
	sts _T0+7,R2
	sts _T0+7+2+1,R5
	sts _T0+7+2,R4
;    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 L8
;    {
;      
; 	 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
;      
;    }
	xjmp L9
L8:
;    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
;      
;    }
L9:
;    
;    TCCR0 = 0x07; //start timer
	ldi R24,7
	out 0x33,R24
;    TIMSK |= 0x01;
	in R24,0x37
	ori R24,1
	out 0x37,R24
;    T0.on=1;
	ldi R24,1
	sts _T0+1,R24
;    adjustPower();
	xcall _adjustPower
L1:
	xcall pop_gset4
	.dbline 0 ; func end
	ret
	.even
_stop_T0::
;   // post(mcu_sleep);
; }
; void stop_T0(void)
; {
;   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
L15:
	.dbline 0 ; func end
	ret
;        t_count -> R10,R11
;          count -> R10,R11
;           type -> R12
	.even
_start_T1::
	xcall push_gset4
	movw R10,R18
	mov R12,R16
; }
; //Timer1
; void start_T1(char type, unsigned int count)
; {
;    unsigned int t_count; 
;  
;    if (type==1)
	mov R24,R12
	cpi R24,1
	brne L18
;       T1.type = 1;
	ldi R24,1
	sts _T1+2,R24
	xjmp L19
L18:
;    else 
;       T1.type = 0; 
	clr R2
	sts _T1+2,R2
L19:
;    T1.ticks = count;
	movw R2,R10
	clr R4
	clr R5
	sts _T1+3+1,R3
	sts _T1+3,R2
	sts _T1+3+2+1,R5
	sts _T1+3+2,R4
;    T1.tickleft = count;
	clr R4
	clr R5
	sts _T1+7+1,R3
	sts _T1+7,R2
	sts _T1+7+2+1,R5
	sts _T1+7+2,R4
;    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 L24
;    {
;      
; 	 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 L25
L24:
;    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
;    }
L25:
;    
;    TCCR1B = 0x05; //1024分频 
	ldi R24,5
	out 0x2e,R24
;    TIMSK |= 0x04;
	in R24,0x37
	ori R24,4
	out 0x37,R24
;    T1.on=1;
	ldi R24,1
	sts _T1+1,R24
L17:
	xcall pop_gset4
	.dbline 0 ; func end
	ret
	.even
_stop_T1::
;  
;    // led1On();
; }
; void stop_T1(void)
; {
;    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
L31:
	.dbline 0 ; func end
	ret
;        t_count -> R10
;          count -> R10,R11
;           type -> R12
	.even
_start_T2::
	xcall push_gset4
	movw R10,R18
	mov R12,R16
; }
; //Timer2
; void start_T2(char type, unsigned int count)
; {
;   //1024分频,最大35ms
;    unsigned char t_count; 
;  
;    if (type==1)
	mov R24,R12
	cpi R24,1
	brne L34
;       T2.type = 1;
	ldi R24,1
	sts _T2+2,R24
	xjmp L35
L34:
;    else 
;       T2.type = 0; 
	clr R2
	sts _T2+2,R2
L35:
;    T2.ticks = count;
	movw R2,R10
	clr R4
	clr R5
	sts _T2+3+1,R3
	sts _T2+3,R2
	sts _T2+3+2+1,R5
	sts _T2+3+2,R4
;    T2.tickleft = count;
	clr R4
	clr R5
	sts _T2+7+1,R3
	sts _T2+7,R2
	sts _T2+7+2+1,R5
	sts _T2+7+2,R4
;    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 L40
;    {
;      
; 	 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 L41
L40:
;    else
;    {
;       
;      t_count = T2.tickleft*72/10 -1; 
	lds R4,_T2+7+2
	lds R5,_T2+7+2+1
	lds R2,_T2+7
	lds R3,_T2+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
; 	 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
;      
;    }
L41:
;    
;    TCCR2 = 0x05; //start timer
	ldi R24,5
	out 0x25,R24
;    TIMSK |= 0x40;
	in R24,0x37
	ori R24,64
	out 0x37,R24
;    T2.on=1;
	ldi R24,1
	sts _T2+1,R24
L33:
	xcall pop_gset4
	.dbline 0 ; func end
	ret
	.even
_stop_T2::
; 
; }
; void stop_T2(void)
; {
;   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
L47:
	.dbline 0 ; func end
	ret
;        t_count -> R10,R11
;          count -> R10,R11
;           type -> R12
	.even
_start_T3::
	xcall push_gset4
	movw R10,R18
	mov R12,R16
; }
; //Timer3
; void start_T3(char type, unsigned int count)
; {
; 
;    unsigned int t_count; 
;  
;    if (type==1)
	mov R24,R12
	cpi R24,1
	brne L50
;       T3.type = 1;
	ldi R24,1
	sts _T3+2,R24
	xjmp L51
L50:
;    else 
;       T3.type = 0; 
	clr R2
	sts _T3+2,R2
L51:
;    T3.ticks = count;
	movw R2,R10
	clr R4
	clr R5
	sts _T3+3+1,R3
	sts _T3+3,R2
	sts _T3+3+2+1,R5
	sts _T3+3+2,R4
;    T3.tickleft = count;
	clr R4
	clr R5
	sts _T3+7+1,R3
	sts _T3+7,R2
	sts _T3+7+2+1,R5
	sts _T3+7+2,R4
;    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 L56
;    {
;      
; 	 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 L57
L56:
;    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
;    }
L57:
;    
;    TCCR3B = 0x05; //1024分频 
	ldi R24,5
	sts 138,R24
;    ETIMSK |= 0x04;
	lds R24,125
	ori R24,4
	sts 125,R24
;    T3.on=1;
	ldi R24,1
	sts _T3+1,R24
L49:
	xcall pop_gset4
	.dbline 0 ; func end
	ret
	.even
_stop_T3::
; }
; void stop_T3(void)
; {
;    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
L63:
	.dbline 0 ; func end
	ret
	.even
_T0_init::
	xcall push_gset2
; }
; //init
; void T0_init()
; {
;   T0.num = 0;
	clr R2
	sts _T0,R2
;   T0.on = 0;
	sts _T0+1,R2
;   T0.type = 0;  //类型,reapeat=1  单次=0
	sts _T0+2,R2
;   T0.ticks = 0;  //执行周期
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	sts _T0+3+1,R21
	sts _T0+3,R20
	sts _T0+3+2+1,R23
	sts _T0+3+2,R22
;   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
;   T0.adjustedticks = 0;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	sts _T0+11+1,R21
	sts _T0+11,R20
	sts _T0+11+2+1,R23
	sts _T0+11+2,R22
;   TCCR0 = 0x00; //stop
	out 0x33,R2
;   ASSR  = 0x08; //set async mode
	ldi R24,8
	out 0x30,R24
L65:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.even
_T1_init::
	xcall push_gset2
;   
;  // TCCR0 = 0x05; //start timer
; }
; 
; void T1_init(void)
; {
;   T1.num = 0;
	clr R2
	sts _T1,R2
;   T1.on = 0;
	sts _T1+1,R2
;   T1.type = 0;  //类型,reapeat=1  单次=0
	sts _T1+2,R2
;   T1.ticks = 0;  //执行周期
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	sts _T1+3+1,R21
	sts _T1+3,R20
	sts _T1+3+2+1,R23
	sts _T1+3+2,R22
;   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
;   T1.adjustedticks = 0;
	ldi R20,0
	ldi R21,0
	ldi R22,0
	ldi R23,0
	sts _T1+11+1,R21
	sts _T1+11,R20
	sts _T1+11+2+1,R23
	sts _T1+11+2,R22
; 
;  TCCR1B = 0x00; //stop
	out 0x2e,R2
;  //TCNT1H = 0xE3; //setup
;  //TCNT1L = 0xE1;
;  
;  TCCR1A = 0x00;
	out 0x2f,R2
L71:
	xcall pop_gset2
	.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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -