📄 外部中断.s
字号:
.module _外部中断.c
.area text(rom, con, rel)
.dbfile E:\xiaozhiyong2009\设计资料\项目设计\mega8_C语言常用程序\ICCAVR_mega8_外部中断\外部中断.c
.area data(ram, con, rel)
.dbfile E:\xiaozhiyong2009\设计资料\项目设计\mega8_C语言常用程序\ICCAVR_mega8_外部中断\外部中断.c
_i::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile E:\xiaozhiyong2009\设计资料\项目设计\mega8_C语言常用程序\ICCAVR_mega8_外部中断\外部中断.c
.dbsym e i _i c
.area text(rom, con, rel)
.dbfile E:\xiaozhiyong2009\设计资料\项目设计\mega8_C语言常用程序\ICCAVR_mega8_外部中断\外部中断.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 10
; //ICC-AVR application builder : 2009-3-10 17:06:48
; // Target : M8
; // Crystal: 8.0000Mhz
;
; #include <iom8v.h>
; #include <macros.h>
; unsigned char i=0;
;
; void port_init(void)
; {
.dbline 11
; PORTB = 0x00;
clr R2
out 0x18,R2
.dbline 12
; DDRB = 0x00;
out 0x17,R2
.dbline 13
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 14
; DDRC = 0x00;
out 0x14,R2
.dbline 15
; PORTD = 0x00;
out 0x12,R2
.dbline 16
; DDRD = 0x00;
out 0x11,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 21
; }
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
.dbline 23
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 24
; port_init();
rcall _port_init
.dbline 26
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 27
; GICR = 0x00;
out 0x3b,R2
.dbline 28
; TIMSK = 0x00; //timer interrupt sources
out 0x39,R2
.dbline 29
; SEI(); //re-enable interrupts
sei
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay_us _delay_us fV
; time -> R16,R17
.even
_delay_us::
.dbline -1
.dbline 41
; //all peripherals are now initialized
; }
;
; /************************************
; 用 途:微秒级延时程序
; Taget :mega8
; crystal :8M
; 介 绍:在8M的晶振上进行us级的延时
; 入口参数:
; *************************************/
; void delay_us(int time)
; {
L4:
.dbline 43
; do
; {
.dbline 44
; time--;
subi R16,1
sbci R17,0
.dbline 45
; }
L5:
.dbline 46
; while (time > 1);
ldi R24,1
ldi R25,0
cp R24,R16
cpc R25,R17
brlt L4
X0:
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbsym r time 16 I
.dbend
.area lit(rom, con, rel)
_num::
.byte 63,6
.byte 91,'O
.byte 'f,'m
.byte 125,7
.byte 127,'o
.byte 'w,124
.byte 57,94
.byte 'y,'q
.dbsym e num _num A[16:16]kc
.area text(rom, con, rel)
.dbfile E:\xiaozhiyong2009\设计资料\项目设计\mega8_C语言常用程序\ICCAVR_mega8_外部中断\外部中断.c
.dbfunc e show_2_digit _show_2_digit fV
; i -> <dead>
; digi -> R10
.even
_show_2_digit::
st -y,R10
mov R10,R16
.dbline -1
.dbline 68
; }
;
;
; /************************************
; 用 途:两位数码管显示一个数
; Taget :mega8
; crystal :8M
; 介 绍:共阳数码管
; 1-PC1(片选)
; 2-PC0
; -----
; a-PB0(数据)
; b-PB1
; ...
; h-PB6
; DP-PB7
; 入口参数:要显示的数,十进制表示
; *************************************/
; const unsigned char num[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
; 0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
; void show_2_digit(unsigned char digi)
; {
.dbline 70
; unsigned char i;
; DDRC=0xff;
ldi R24,255
out 0x14,R24
.dbline 71
; DDRB=0xff;
out 0x17,R24
.dbline 72
; PORTC=0;//关片选
clr R2
out 0x15,R2
.dbline 73
; PORTB=~num[(unsigned char )(digi/10)];//显示十位
ldi R18,10
ldi R19,0
mov R16,R10
clr R17
rcall div16s
mov R30,R16
clr R31
ldi R24,<_num
ldi R25,>_num
add R30,R24
adc R31,R25
lpm R2,Z
com R2
out 0x18,R2
.dbline 74
; PORTC=(0x1<<1);//开十位的显示
ldi R24,2
out 0x15,R24
.dbline 75
; delay_us(200);
ldi R16,200
ldi R17,0
rcall _delay_us
.dbline 76
; PORTC=0;//关显示
clr R2
out 0x15,R2
.dbline 77
; PORTB=~num[(unsigned char )(digi%10)];//显示个位
ldi R18,10
ldi R19,0
mov R16,R10
clr R17
rcall mod16s
mov R30,R16
clr R31
ldi R24,<_num
ldi R25,>_num
add R30,R24
adc R31,R25
lpm R2,Z
com R2
out 0x18,R2
.dbline 78
; PORTC=(0x1<<0);//开个位的显示
ldi R24,1
out 0x15,R24
.dbline 79
; delay_us(200);
ldi R16,200
ldi R17,0
rcall _delay_us
.dbline 80
; PORTC=0x0;//关显示
clr R2
out 0x15,R2
.dbline -2
L7:
.dbline 0 ; func end
ld R10,y+
ret
.dbsym l i 1 c
.dbsym r digi 10 c
.dbend
.dbfunc e int_init _int_init fV
.even
_int_init::
.dbline -1
.dbline 90
; }
;
; /************************************
; 用 途:打开外部中断
; 介 绍:
; 入口参数:
; 出口参数:
; *************************************/
; void int_init()
; {
.dbline 91
; CLI();
cli
.dbline 92
; PORTD|=(1<<PD2)|(1<<PD3);
in R24,0x12
ori R24,12
out 0x12,R24
.dbline 93
; MCUCR|=(1<<ISC11)|(1<<ISC01);//3-0,外部中断定1,0的控制方式
in R24,0x35
ori R24,10
out 0x35,R24
.dbline 95
; //MCUCR=3-2,0是低电平中断,1是下(降沿)和上(升沿)中断,2是下中断,3是上中断
; GICR|=(1<<INT0)|(1<<INT1);//7,6外部中断1,0使能
in R24,0x3b
ori R24,192
out 0x3b,R24
.dbline 96
; SEI();
sei
.dbline -2
L8:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 2
rjmp _init_0
.area text(rom, con, rel)
.dbfile E:\xiaozhiyong2009\设计资料\项目设计\mega8_C语言常用程序\ICCAVR_mega8_外部中断\外部中断.c
.dbfunc e init_0 _init_0 fV
.even
_init_0::
st -y,R24
in R24,0x3f
st -y,R24
.dbline -1
.dbline 107
; }
;
; /************************************
; 用 途:中断0服务子程序
; 介 绍:
; 入口参数:
; 出口参数:
; *************************************/
; #pragma interrupt_handler init_0:2
; void init_0()
; {
.dbline 108
; i--;
lds R24,_i
subi R24,1
sts _i,R24
.dbline 109
; if (i==0)i=99;
tst R24
brne L10
X1:
.dbline 109
ldi R24,99
sts _i,R24
L10:
.dbline -2
L9:
.dbline 0 ; func end
ld R24,y+
out 0x3f,R24
ld R24,y+
reti
.dbend
.area vector(rom, abs)
.org 4
rjmp _init_1
.area text(rom, con, rel)
.dbfile E:\xiaozhiyong2009\设计资料\项目设计\mega8_C语言常用程序\ICCAVR_mega8_外部中断\外部中断.c
.dbfunc e init_1 _init_1 fV
.even
_init_1::
st -y,R2
st -y,R24
st -y,R25
in R2,0x3f
st -y,R2
.dbline -1
.dbline 120
; }
;
; /************************************
; 用 途:中断1服务子程序
; 介 绍:
; 入口参数:
; 出口参数:
; *************************************/
; #pragma interrupt_handler init_1:3
; void init_1()
; {
.dbline 121
; i++;
lds R24,_i
subi R24,255 ; addi 1
sts _i,R24
.dbline 122
; if (i==100)i=0;
cpi R24,100
brne L13
X2:
.dbline 122
clr R2
sts _i,R2
L13:
.dbline -2
L12:
.dbline 0 ; func end
ld R2,y+
out 0x3f,R2
ld R25,y+
ld R24,y+
ld R2,y+
reti
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 126
; }
;
; void main()
; {
.dbline 127
; port_init();
rcall _port_init
.dbline 128
; init_devices();
rcall _init_devices
.dbline 130
;
; int_init();//中断初始化
rcall _int_init
rjmp L17
L16:
.dbline 132
; while(1)
; {
.dbline 133
; show_2_digit(i);
lds R16,_i
rcall _show_2_digit
.dbline 134
; }
L17:
.dbline 131
rjmp L16
X3:
.dbline -2
L15:
.dbline 0 ; func end
ret
.dbend
; }
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -