📄 main.s
字号:
.module main.c
.area text(rom, con, rel)
.dbfile E:\avr\2.2.2\main.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 11
; //ICC-AVR application builder : 2007-6-9 0:33:58
; // Target : M16
; // Crystal: 1.0000Mhz
; // 用途:演示定时器的工作原理
; // 作者:古欣
; // AVR与虚拟仪器 http://www.avrvi.com
; #include <iom16v.h>
; #include <macros.h>
;
; void port_init(void)
; {
.dbline 12
; PORTA = 0x00;
clr R2
out 0x1b,R2
.dbline 13
; DDRA = 0x03; //PA0 PA1 输出
ldi R24,3
out 0x1a,R24
.dbline 14
; PORTB = 0x00;
out 0x18,R2
.dbline 15
; DDRB = 0xFF; //PB 输出
ldi R24,255
out 0x17,R24
.dbline 16
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 17
; DDRC = 0x00;
out 0x14,R2
.dbline 18
; PORTD = 0x00;
out 0x12,R2
.dbline 19
; DDRD = 0x00;
out 0x11,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e timer0_init _timer0_init fV
.even
_timer0_init::
.dbline -1
.dbline 27
; }
;
; //TIMER0 initialize - prescale:8
; // WGM: Normal
; // desired value: 1KHz
; // actual value: 1.000KHz (0.0%)
; void timer0_init(void)
; {
.dbline 28
; TCCR0 = 0x00; //stop
clr R2
out 0x33,R2
.dbline 29
; TCNT0 = 0x83; //set count
ldi R24,131
out 0x32,R24
.dbline 30
; OCR0 = 0x7D; //set compare
ldi R24,125
out 0x3c,R24
.dbline 31
; TCCR0 = 0x02; //start timer
ldi R24,2
out 0x33,R24
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 76
jmp _timer0_comp_isr
.area text(rom, con, rel)
.dbfile E:\avr\2.2.2\main.c
.dbfunc e timer0_comp_isr _timer0_comp_isr fV
.even
_timer0_comp_isr::
st -y,R2
st -y,R24
in R2,0x3f
st -y,R2
.dbline -1
.dbline 37
; }
;
; //比较匹配中断
; #pragma interrupt_handler timer0_comp_isr:20
; void timer0_comp_isr(void)
; {
.dbline 39
; //compare occured TCNT0=OCR0
; if(OCR0==0x7D) //调整0x7D
in R24,0x3c
cpi R24,125
brne L4
.dbline 40
; {
.dbline 41
; OCR0=0x7F;
ldi R24,127
out 0x3c,R24
.dbline 42
; }
xjmp L5
L4:
.dbline 44
; else
; {
.dbline 45
; OCR0=0x7D;
ldi R24,125
out 0x3c,R24
.dbline 46
; }
L5:
.dbline 47
; PORTA ^= 0x01; //PA0取反
ldi R24,1
in R2,0x1b
eor R2,R24
out 0x1b,R2
.dbline -2
L3:
ld R2,y+
out 0x3f,R2
ld R24,y+
ld R2,y+
.dbline 0 ; func end
reti
.dbend
.area vector(rom, abs)
.org 36
jmp _timer0_ovf_isr
.area text(rom, con, rel)
.dbfile E:\avr\2.2.2\main.c
.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
.even
_timer0_ovf_isr::
st -y,R2
st -y,R24
in R2,0x3f
st -y,R2
.dbline -1
.dbline 53
; }
;
; //溢出中断中断
; #pragma interrupt_handler timer0_ovf_isr:10
; void timer0_ovf_isr(void)
; {
.dbline 54
; TCNT0 = 0x83; //reload counter value
ldi R24,131
out 0x32,R24
.dbline 55
; PORTA ^= 0x01; //PA0取反
ldi R24,1
in R2,0x1b
eor R2,R24
out 0x1b,R2
.dbline -2
L6:
ld R2,y+
out 0x3f,R2
ld R24,y+
ld R2,y+
.dbline 0 ; func end
reti
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 60
; }
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
.dbline 62
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 63
; port_init();
xcall _port_init
.dbline 64
; timer0_init();
xcall _timer0_init
.dbline 66
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 67
; GICR = 0x00;
out 0x3b,R2
.dbline 68
; TIMSK = 0x03; //timer interrupt sources 允许定时器零匹配和溢出中断
ldi R24,3
out 0x39,R24
.dbline 69
; SEI(); //re-enable interrupts
sei
.dbline -2
L7:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 74
; //all peripherals are now initialized
; }
;
; void main(void)
; {
.dbline 75
; init_devices();
xcall _init_devices
.dbline 76
; PORTA=0x00;
clr R2
out 0x1b,R2
xjmp L10
L9:
.dbline 78
.dbline 79
in R2,0x32
out 0x18,R2
.dbline 80
L10:
.dbline 77
xjmp L9
X0:
.dbline -2
L8:
.dbline 0 ; func end
ret
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -