📄 main.s
字号:
.module main.c
.area text(rom, con, rel)
.dbfile E:\avr\跑马灯\main.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 19
; //ICC-AVR application builder : 2007-1-29 10:04:38
; // Target : M16
; // Crystal: 7.3728Mhz
; // 作者:古欣
; // AVR与虚拟仪器 http://www.avrvi.com
;
; #include <iom16v.h>
; #include <macros.h>
;
; #define led_port PORTA
; //定义输出端口
; #define led_ddr DDRA
; //定义输出控制寄存器
; //可以自行修改,必须保持 led_port和led_ddr一致,PORTA对应DDRA
;
;
;
; void port_init(void)
; {
.dbline 20
; PORTA = 0x00;
clr R2
out 0x1b,R2
.dbline 21
; DDRA = 0x00;
out 0x1a,R2
.dbline 22
; PORTB = 0x00;
out 0x18,R2
.dbline 23
; DDRB = 0x00;
out 0x17,R2
.dbline 24
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 25
; DDRC = 0x00;
out 0x14,R2
.dbline 26
; PORTD = 0x00;
out 0x12,R2
.dbline 27
; DDRD = 0x00;
out 0x11,R2
.dbline 28
; led_ddr=0xff; //设置LED的端口为输出
ldi R24,255
out 0x1a,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 34
; }
;
; //call this routine to initialize all peripherals
; //此处为ICC系统生成,未做更改
; void init_devices(void)
; {
.dbline 36
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 37
; port_init();
xcall _port_init
.dbline 39
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 40
; GICR = 0x00;
out 0x3b,R2
.dbline 41
; TIMSK = 0x00; //timer interrupt sources
out 0x39,R2
.dbline 42
; SEI(); //re-enable interrupts
sei
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Delay _Delay fV
; i -> R16
; j -> R18
.even
_Delay::
.dbline -1
.dbline 47
; //all peripherals are now initialized
; }
;
; void Delay(void) //延时,没有详细计算
; {
.dbline 49
; unsigned char i,j;
; for(i=20;i>0;i--)
ldi R16,20
xjmp L7
L4:
.dbline 50
; {
.dbline 51
; for(j=200;j>0;j--)
ldi R18,200
xjmp L11
L8:
.dbline 52
L9:
.dbline 51
dec R18
L11:
.dbline 51
clr R2
cp R2,R18
brlo L8
.dbline 53
L5:
.dbline 49
dec R16
L7:
.dbline 49
clr R2
cp R2,R16
brlo L4
.dbline -2
L3:
.dbline 0 ; func end
ret
.dbsym r i 16 c
.dbsym r j 18 c
.dbend
.dbfunc e main _main fV
; j -> R20
; i -> R22
; k -> R10
.even
_main::
.dbline -1
.dbline 57
; ;
; }
; }
;
; void main()
; {
.dbline 59
; unsigned char i,j,k; //定义变量
; init_devices(); //初始化
xcall _init_devices
xjmp L14
L13:
.dbline 61
; while(1)
; {
.dbline 62
; i=0x80;
ldi R22,128
.dbline 63
; for (j=0;j<8;j++) //循环8次,即PA0~~PA7轮流闪亮
clr R20
xjmp L19
L16:
.dbline 64
; {
.dbline 65
; led_port=~i; //反相输出,低电平有效 位操作指令详解:http://bbs.avrvi.com/read.php?fid=30&tid=392&toread=1
mov R2,R22
com R2
out 0x1b,R2
.dbline 66
clr R10
xjmp L23
L20:
.dbline 66
xcall _Delay
L21:
.dbline 66
inc R10
L23:
.dbline 66
mov R24,R10
cpi R24,10
brlo L20
.dbline 67
lsr R22
.dbline 76
L17:
.dbline 63
inc R20
L19:
.dbline 63
cpi R20,8
brlo L16
.dbline 77
; for (k=0;k<10;k++) Delay(); //延时 可自行调节
; i=i>>1; //左移一位 移位算法详解:http://bbs.avrvi.com/read.php?fid=5&tid=897&toread=1
; // 0b00000001 PA0
; // 0b00000010 PA1
; // 0b00000100 PA2
; // 0b00001000 PA3
; // 0b00010000 PA4
; // 0b00100000 PA5
; // 0b01000000 PA6
; // 0b10000000 PA7
; }
; i=1;
ldi R22,1
.dbline 78
; for (j=0;j<8;j++) //循环8次,即PA0~~PA7轮流闪亮
clr R20
xjmp L27
L24:
.dbline 79
; {
.dbline 80
; led_port=~i; //反相输出,低电平有效 位操作指令详解:http://bbs.avrvi.com/read.php?fid=30&tid=392&toread=1
mov R2,R22
com R2
out 0x1b,R2
.dbline 81
clr R10
xjmp L31
L28:
.dbline 81
xcall _Delay
L29:
.dbline 81
inc R10
L31:
.dbline 81
mov R24,R10
cpi R24,10
brlo L28
.dbline 82
lsl R22
.dbline 91
L25:
.dbline 78
inc R20
L27:
.dbline 78
cpi R20,8
brlo L24
.dbline 92
L14:
.dbline 60
xjmp L13
X0:
.dbline -2
L12:
.dbline 0 ; func end
ret
.dbsym r j 20 c
.dbsym r i 22 c
.dbsym r k 10 c
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -