📄 main.s
字号:
.module main.c
.area text(rom, con, rel)
.dbfile D:\桌面\教程\外部中断\main.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 20
; //ICC-AVR application builder : 2007-2-17 7:56:49
; // Target : M16
; // Crystal: 7.3728Mhz
; // www.avrvi.com AVR与虚拟仪器
;
; // 硬件连接:
; // PA0—————LED0
; // PA1—————LED1
; // PD2—————独立按键A
; // PD3—————独立按键B
;
; // 实验效果:
; // 按A时,LED0亮与灭交替变换
; // 按B时,LED1亮与灭交替变换
;
; #include <iom16v.h>
; #include <macros.h>
;
; void port_init(void)
; {
.dbline 21
; PORTA = 0x00;
clr R2
out 0x1b,R2
.dbline 22
; DDRA = 0x03; //PORTA.0 PORTA.1 输出,LED指示
ldi R24,3
out 0x1a,R24
.dbline 23
; PORTB = 0x00;
out 0x18,R2
.dbline 24
; DDRB = 0x00;
out 0x17,R2
.dbline 25
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 26
; DDRC = 0x00;
out 0x14,R2
.dbline 27
; PORTD |= (1<<2)|(1<<3); //使能内部上拉
in R24,0x12
ori R24,12
out 0x12,R24
.dbline 28
; DDRD = 0x00; //PD2,PD3 对应INT0,INT1 一定要设置为输入
out 0x11,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 4
jmp _int0_isr
.area text(rom, con, rel)
.dbfile D:\桌面\教程\外部中断\main.c
.dbfunc e int0_isr _int0_isr fV
.even
_int0_isr::
st -y,R2
st -y,R24
in R2,0x3f
st -y,R2
.dbline -1
.dbline 33
; }
;
; #pragma interrupt_handler int0_isr:2
; void int0_isr(void)
; {
.dbline 35
; //external interupt on INT0
; PORTA ^= 0x01; //PA0取反
ldi R24,1
in R2,0x1b
eor R2,R24
out 0x1b,R2
.dbline -2
L2:
ld R2,y+
out 0x3f,R2
ld R24,y+
ld R2,y+
.dbline 0 ; func end
reti
.dbend
.area vector(rom, abs)
.org 8
jmp _int1_isr
.area text(rom, con, rel)
.dbfile D:\桌面\教程\外部中断\main.c
.dbfunc e int1_isr _int1_isr fV
.even
_int1_isr::
st -y,R2
st -y,R24
in R2,0x3f
st -y,R2
.dbline -1
.dbline 40
; }
;
; #pragma interrupt_handler int1_isr:3
; void int1_isr(void)
; {
.dbline 42
; //external interupt on INT1
; PORTA ^= 0x02; //PA1取反
ldi R24,2
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
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 47
; }
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
.dbline 49
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 50
; port_init();
xcall _port_init
.dbline 52
;
; MCUCR = 0x0A; //允许INT0和INT1外部中断
ldi R24,10
out 0x35,R24
.dbline 53
; GICR = 0xC0;
ldi R24,192
out 0x3b,R24
.dbline 54
; TIMSK = 0x00; //timer interrupt sources
clr R2
out 0x39,R2
.dbline 55
; SEI(); //re-enable interrupts
sei
.dbline -2
L4:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 60
; //all peripherals are now initialized
; }
;
; void main(void)
; {
.dbline 61
; init_devices();
xcall _init_devices
L6:
.dbline 63
L7:
.dbline 62
xjmp L6
X0:
.dbline -2
L5:
.dbline 0 ; func end
ret
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -