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

📄 timer.s

📁 avr单片机atmega8系列定时器的使用测试程序
💻 S
字号:
	.module timer.c
	.area text(rom, con, rel)
	.dbfile D:\job\avrtest\web\example\timer\timer.c
	.dbfunc e timer0_init _timer0_init fV
	.even
_timer0_init::
	.dbline -1
	.dbline 12
; //ICC-AVR application builder : 2005-2-24 22:21:34
; // Target : M8
; // Crystal: 8.0000Mhz
; 
; #include <iom8v.h>
; #include <macros.h>
; 
; int  i;
; 
; //  初始化timer0, 1  ms
; void timer0_init(void)
; {
	.dbline 13
;  TCCR0 = 0x00; //stop
	clr R2
	out 0x33,R2
	.dbline 14
;  TCNT0 = 0xE1; //set count
	ldi R24,225
	out 0x32,R24
	.dbline 15
;  TCCR0 = 0x04; //start timer
	ldi R24,4
	out 0x33,R24
	.dbline -2
	.dbline 16
; }
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.area vector(rom, abs)
	.org 18
	rjmp _timer0_ovf_isr
	.area text(rom, con, rel)
	.dbfile D:\job\avrtest\web\example\timer\timer.c
	.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
	.even
_timer0_ovf_isr::
	st -y,R2
	st -y,R3
	st -y,R24
	st -y,R25
	st -y,R30
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 21
	.dbline 22
	ldi R24,225
	out 0x32,R24
	.dbline 23
	lds R24,_i
	lds R25,_i+1
	adiw R24,1
	sts _i+1,R25
	sts _i,R24
	cpi R24,232
	ldi R30,3
	cpc R25,R30
	brne L3
	.dbline 23
	.dbline 24
	clr R2
	clr R3
	sts _i+1,R3
	sts _i,R2
	.dbline 25
	ldi R24,2
	in R2,0x18
	eor R2,R24
	out 0x18,R2
	.dbline 26
L3:
	.dbline -2
	.dbline 27
; 
; //  timer0 中断
; #pragma interrupt_handler timer0_ovf_isr:10
; void timer0_ovf_isr(void)
; {
;  TCNT0 = 0xE1;     //reload counter value
;  if(++i == 1000){  //  1 秒
;     i = 0;
;     PORTB ^= 0x02; //  端口取反
;  }
; }
L2:
	ld R2,y+
	out 0x3f,R2
	ld R30,y+
	ld R25,y+
	ld R24,y+
	ld R3,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 31
; 
; //call this routine to initialise all peripherals
; void init_devices(void)
; {
	.dbline 33
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 34
;  DDRB  = 0x02;    //  设置 PB1 为输出
	ldi R24,2
	out 0x17,R24
	.dbline 35
;  timer0_init();
	rcall _timer0_init
	.dbline 37
; 
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 38
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 39
;  TIMSK = 0x01; //timer interrupt sources
	ldi R24,1
	out 0x39,R24
	.dbline 40
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
	.dbline 42
;  //all peripherals are now initialised
; }
L5:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 46
; 
; //
; void main(void)
; {
	.dbline 47
;  init_devices();
	rcall _init_devices
	.dbline 49
L7:
	.dbline 49
	.dbline 49
	.dbline 49
	rjmp L7
X0:
	.dbline -2
L6:
	.dbline 0 ; func end
	ret
	.dbend
	.area bss(ram, con, rel)
	.dbfile D:\job\avrtest\web\example\timer\timer.c
_i::
	.blkb 2
	.dbsym e i _i I

⌨️ 快捷键说明

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