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

📄 atmega16_8led.s

📁 AVR单片机来驱动8位数码管
💻 S
字号:
	.module ATMEGA16_8LED.C
	.area text(rom, con, rel)
	.dbfile E:\AVR单片机程序调试\ATMEGA16_8LED/delay.h
	.dbfunc e delay_1us _delay_1us fV
	.even
_delay_1us::
	.dbline -1
	.dbline 6
; //ICC-AVR application builder : 2009-3-3 14:58:49
; // Target : M16
; // Crystal: 8.0000Mhz
; 
; #include <iom16v.h>
; #include <macros.h>
	.dbline 7
; #include "delay.h"
	nop
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay_nus _delay_nus fV
;              i -> R20,R21
;              n -> R22,R23
	.even
_delay_nus::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 11
; #define uchar unsigned char
; #define uint  unsigned int
; #define ulong  unsigned long
; 
	.dbline 12
; #define CLK_1  PORTA|=(1<<0)
	clr R20
	clr R21
	.dbline 13
; #define CLK_0  PORTA&=~(1<<0)
	xjmp L6
L3:
	.dbline 14
	xcall _delay_1us
L4:
	.dbline 13
	subi R20,255  ; offset = 1
	sbci R21,255
L6:
	.dbline 13
	cp R20,R22
	cpc R21,R23
	brlo L3
	.dbline -2
L2:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r n 22 i
	.dbend
	.dbfunc e delay_1ms _delay_1ms fV
;              i -> R16,R17
	.even
_delay_1ms::
	.dbline -1
	.dbline 18
; #define RCLK_1  PORTA|=(1<<1) 
; #define RCLK_0  PORTA&=~(1<<1)
; #define DAT_1  PORTA|=(1<<2) 
; #define DAT_0  PORTA&=~(1<<2) 
; 
	.dbline 20
	clr R16
	clr R17
	xjmp L11
L8:
	.dbline 20
L9:
	.dbline 20
	subi R16,255  ; offset = 1
	sbci R17,255
L11:
	.dbline 20
; const char tab[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0};//0-9,
; const char seg[9]={0x08,0x04,0x02,0x01,0x10,0x20,0x40,0x80,0x00};
	cpi R16,116
	ldi R30,4
	cpc R17,R30
	brlo L8
	.dbline -2
L7:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 i
	.dbend
	.dbfunc e delay_nms _delay_nms fV
;              i -> R20,R21
;              n -> R22,R23
	.even
_delay_nms::
	xcall push_gset2
	movw R22,R16
	.dbline -1
	.dbline 24
; const char off[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
; const char on[8]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
; uchar display_buff[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
; uint i,number;
	.dbline 25
; 
	clr R20
	clr R21
	.dbline 26
; 
	xjmp L16
L13:
	.dbline 27
	xcall _delay_1ms
L14:
	.dbline 26
	subi R20,255  ; offset = 1
	sbci R21,255
L16:
	.dbline 26
	cp R20,R22
	cpc R21,R23
	brlo L13
	.dbline -2
L12:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r n 22 i
	.dbend
	.area lit(rom, con, rel)
_tab::
	.byte 63,6
	.byte 91,'O
	.byte 'f,'m
	.byte 125,7
	.byte 127,'o
	.byte 'w,124
	.byte 57,94
	.byte 'y,'q
	.byte 0
	.dbfile E:\AVR单片机程序调试\ATMEGA16_8LED\ATMEGA16_8LED.C
	.dbsym e tab _tab A[17:17]kc
_seg::
	.byte 8,4
	.byte 2,1
	.byte 16,32
	.byte 64,128
	.byte 0
	.dbsym e seg _seg A[9:9]kc
_off::
	.byte 0,0
	.byte 0,0
	.byte 0,0
	.byte 0,0
	.dbsym e off _off A[8:8]kc
_on::
	.byte 255,255
	.byte 255,255
	.byte 255,255
	.byte 255,255
	.dbsym e on _on A[8:8]kc
	.area data(ram, con, rel)
	.dbfile E:\AVR单片机程序调试\ATMEGA16_8LED\ATMEGA16_8LED.C
_display_buff::
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.dbfile E:\AVR单片机程序调试\ATMEGA16_8LED\ATMEGA16_8LED.C
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.dbfile E:\AVR单片机程序调试\ATMEGA16_8LED\ATMEGA16_8LED.C
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.dbfile E:\AVR单片机程序调试\ATMEGA16_8LED\ATMEGA16_8LED.C
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.dbfile E:\AVR单片机程序调试\ATMEGA16_8LED\ATMEGA16_8LED.C
	.dbsym e display_buff _display_buff A[8:8]c
	.area text(rom, con, rel)
	.dbfile E:\AVR单片机程序调试\ATMEGA16_8LED\ATMEGA16_8LED.C
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 28
; void port_init(void)
; {
	.dbline 29
;  PORTA = 0x00;
	clr R2
	out 0x1b,R2
	.dbline 30
;  DDRA  = 0x07;
	ldi R24,7
	out 0x1a,R24
	.dbline -2
L17:
	.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
; 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
L18:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e BINtoBCD _BINtoBCD fV
;           temp -> R10,R11
;              i -> R12,R13
;          count -> y+8
	.even
_BINtoBCD::
	xcall push_arg4
	xcall push_gset4
	.dbline -1
	.dbline 47
;  //all peripherals are now initialized
; }
; 
; void BINtoBCD(ulong count)
; { 
	.dbline 49
;   uint temp,i;
;   temp=count;
	movw R30,R28
	ldd R10,z+8
	ldd R11,z+9
	.dbline 50
;   for (i=0;i<8;i++)
	clr R12
	clr R13
	xjmp L23
L20:
	.dbline 51
	.dbline 52
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+8
	ldd R3,z+9
	ldd R4,z+10
	ldd R5,z+11
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	movw R16,R2
	movw R18,R4
	xcall mod32u
	movw R10,R16
	.dbline 53
	ldi R24,<_tab
	ldi R25,>_tab
	movw R30,R10
	add R30,R24
	adc R31,R25
	lpm R30,Z
	ldi R24,<_display_buff
	ldi R25,>_display_buff
	movw R26,R12
	add R26,R24
	adc R27,R25
	st x,R30
	.dbline 54
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+8
	ldd R3,z+9
	ldd R4,z+10
	ldd R5,z+11
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	movw R16,R2
	movw R18,R4
	xcall div32u
	movw R30,R28
	std z+8,R16
	std z+9,R17
	std z+10,R18
	std z+11,R19
	.dbline 55
L21:
	.dbline 50
	movw R24,R12
	adiw R24,1
	movw R12,R24
L23:
	.dbline 50
	movw R24,R12
	cpi R24,8
	ldi R30,0
	cpc R25,R30
	brsh X0
	xjmp L20
X0:
	.dbline -2
L19:
	xcall pop_gset4
	adiw R28,4
	.dbline 0 ; func end
	ret
	.dbsym r temp 10 i
	.dbsym r i 12 i
	.dbsym l count 8 l
	.dbend
	.dbfunc e write_595 _write_595 fV
;           temp -> R20
;              i -> R22
;           data -> R16
	.even
_write_595::
	xcall push_gset2
	.dbline -1
	.dbline 59
;   {
;    temp=count%10;
;    display_buff[i]=tab[temp];
;    count=count/10; 
;    }
; }
; //发送一个字节
; void write_595 (uchar data)
; {
	.dbline 61
;  uchar i,temp;
;  temp=data;
	mov R20,R16
	.dbline 62
;  for (i=0;i<8;i++)
	clr R22
	xjmp L28
L25:
	.dbline 63
;  {
	.dbline 64
;   CLK_0;
	cbi 0x1b,0
	.dbline 65
;   if (temp&0x80)DAT_1;
	sbrs R20,7
	rjmp L29
	.dbline 65
	sbi 0x1b,2
	xjmp L30
L29:
	.dbline 66
;   else DAT_0;
	cbi 0x1b,2
L30:
	.dbline 67
	lsl R20
	.dbline 68
	sbi 0x1b,0
	.dbline 69
L26:
	.dbline 62
	inc R22
L28:
	.dbline 62
	cpi R22,8
	brlo L25
	.dbline -2
L24:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r temp 20 c
	.dbsym r i 22 c
	.dbsym r data 16 c
	.dbend
	.dbfunc e out_595 _out_595 fV
	.even
_out_595::
	.dbline -1
	.dbline 73
;   temp<<=1;
;   CLK_1;
;  }
; }
; 
; void out_595 ()
; {
	.dbline 74
;  RCLK_0;
	cbi 0x1b,1
	.dbline 75
;  RCLK_1;
	sbi 0x1b,1
	.dbline -2
L31:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e display _display fV
;              i -> R20
	.even
_display::
	xcall push_gset1
	.dbline -1
	.dbline 80
; }
; 
; //发送并显示四个字节
; void display ()
; {
	.dbline 82
;  uchar i;
;  for (i=0;i<4;i++)
	clr R20
	xjmp L36
L33:
	.dbline 83
	.dbline 84
	ldi R24,<_seg
	ldi R25,>_seg
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	lpm R16,Z
	xcall _write_595
	.dbline 85
	ldi R24,<_display_buff
	ldi R25,>_display_buff
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	ldd R16,z+0
	xcall _write_595
	.dbline 86
	xcall _out_595
	.dbline 87
	ldi R16,2
	ldi R17,0
	xcall _delay_nms
	.dbline 88
L34:
	.dbline 82
	inc R20
L36:
	.dbline 82
	cpi R20,4
	brlo L33
	.dbline -2
L32:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e display_off _display_off fV
;              i -> R20
	.even
_display_off::
	xcall push_gset1
	.dbline -1
	.dbline 92
;  {
;   write_595 (seg[i]);
;   write_595 (display_buff[i]);
;   out_595 ();
;   delay_nms (2);
;  }
; }
; 
; void display_off ()
; {
	.dbline 94
;  uchar i;
;  for (i=0;i<4;i++)
	clr R20
	xjmp L41
L38:
	.dbline 95
	.dbline 96
	ldi R24,<_seg
	ldi R25,>_seg
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	lpm R16,Z
	xcall _write_595
	.dbline 97
	ldi R24,<_off
	ldi R25,>_off
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	lpm R16,Z
	xcall _write_595
	.dbline 98
	xcall _out_595
	.dbline 99
	ldi R16,2
	ldi R17,0
	xcall _delay_nms
	.dbline 100
L39:
	.dbline 94
	inc R20
L41:
	.dbline 94
	cpi R20,4
	brlo L38
	.dbline -2
L37:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e display_on _display_on fV
;              i -> R20
	.even
_display_on::
	xcall push_gset1
	.dbline -1
	.dbline 104
;  {
;   write_595 (seg[i]);
;   write_595 (off[i]);
;   out_595 ();
;   delay_nms (2);
;  }
; }
; 
; void display_on ()
; {
	.dbline 106
;  uchar i;
;  for (i=0;i<4;i++)
	clr R20
	xjmp L46
L43:
	.dbline 107
	.dbline 108
	ldi R24,<_seg
	ldi R25,>_seg
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	lpm R16,Z
	xcall _write_595
	.dbline 109
	ldi R24,<_on
	ldi R25,>_on
	mov R30,R20
	clr R31
	add R30,R24
	adc R31,R25
	lpm R16,Z
	xcall _write_595
	.dbline 110
	xcall _out_595
	.dbline 111
	ldi R16,2
	ldi R17,0
	xcall _delay_nms
	.dbline 112
L44:
	.dbline 106
	inc R20
L46:
	.dbline 106
	cpi R20,4
	brlo L43
	.dbline -2
L42:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 116
;  {
;   write_595 (seg[i]);
;   write_595 (on[i]);
;   out_595 ();
;   delay_nms (2);
;  }
; }
; 
; void main ()
; {
	.dbline 117
;  init_devices();
	xcall _init_devices
	.dbline 118
;  number=0;
	clr R2
	clr R3
	sts _number+1,R3
	sts _number,R2
	xjmp L49
L48:
	.dbline 120
;  while (1)
;  {
	.dbline 121
;   number++;
	lds R24,_number
	lds R25,_number+1
	adiw R24,1
	sts _number+1,R25
	sts _number,R24
	.dbline 122
;   BINtoBCD(number);
	movw R2,R24
	clr R4
	clr R5
	movw R16,R2
	movw R18,R4
	xcall _BINtoBCD
	.dbline 123
;   for (i=0;i<125;i++) 
	clr R2
	clr R3
	sts _i+1,R3
	sts _i,R2
	xjmp L54
L51:
	.dbline 124
	xcall _display
L52:
	.dbline 123
	lds R24,_i
	lds R25,_i+1
	adiw R24,1
	sts _i+1,R25
	sts _i,R24
L54:
	.dbline 123
	lds R24,_i
	lds R25,_i+1
	cpi R24,125
	ldi R30,0
	cpc R25,R30
	brlo L51
	.dbline 125
;   display ();
;   if (number>=9999) number=0;
	lds R24,_number
	lds R25,_number+1
	cpi R24,15
	ldi R30,39
	cpc R25,R30
	brlo L55
	.dbline 125
	clr R2
	clr R3
	sts _number+1,R3
	sts _number,R2
L55:
	.dbline 126
L49:
	.dbline 119
	xjmp L48
X1:
	.dbline -2
L47:
	.dbline 0 ; func end
	ret
	.dbend
	.area bss(ram, con, rel)
	.dbfile E:\AVR单片机程序调试\ATMEGA16_8LED\ATMEGA16_8LED.C
_number::
	.blkb 2
	.dbsym e number _number i
_i::
	.blkb 2
	.dbsym e i _i i

⌨️ 快捷键说明

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