📄 两位数码管显示.s
字号:
.module _两位数码管显示.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 9
; //ICC-AVR application builder : 2009-3-10 14:45:48
; // Target : M8
; // Crystal: 8.0000Mhz
;
; #include <iom8v.h>
; #include <macros.h>
;
; void port_init(void)
; {
.dbline 10
; PORTB = 0x00;
clr R2
out 0x18,R2
.dbline 11
; DDRB = 0x00;
out 0x17,R2
.dbline 12
; PORTC = 0x00; //m103 output only
out 0x15,R2
.dbline 13
; DDRC = 0x00;
out 0x14,R2
.dbline 14
; PORTD = 0x00;
out 0x12,R2
.dbline 15
; 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 20
; }
;
; //call this routine to initialize all peripherals
; void init_devices(void)
; {
.dbline 22
; //stop errant interrupts until set up
; CLI(); //disable all interrupts
cli
.dbline 23
; port_init();
rcall _port_init
.dbline 25
;
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 26
; GICR = 0x00;
out 0x3b,R2
.dbline 27
; TIMSK = 0x00; //timer interrupt sources
out 0x39,R2
.dbline 28
; 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 40
; //all peripherals are now initialized
; }
;
; /************************************
; 用 途:微秒级延时程序
; Taget :mega8
; crystal :8M
; 介 绍:在8M的晶振上进行us级的延时
; 入口参数:
; *************************************/
; void delay_us(int time)
; {
L4:
.dbline 42
; do
; {
.dbline 43
; time--;
subi R16,1
sbci R17,0
.dbline 44
; }
L5:
.dbline 45
; 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 67
; }
;
;
; /************************************
; 用 途:两位数码管显示一个数
; 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 69
; unsigned char i;
; DDRC=0xff;
ldi R24,255
out 0x14,R24
.dbline 70
; DDRB=0xff;
out 0x17,R24
.dbline 71
; PORTC=0;//关片选
clr R2
out 0x15,R2
.dbline 72
; 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 73
; PORTC=(0x1<<1);//开十位的显示
ldi R24,2
out 0x15,R24
.dbline 74
; delay_us(200);
ldi R16,200
ldi R17,0
rcall _delay_us
.dbline 75
; PORTC=0;//关显示
clr R2
out 0x15,R2
.dbline 76
; 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 77
; PORTC=(0x1<<0);//开个位的显示
ldi R24,1
out 0x15,R24
.dbline 78
; delay_us(200);
ldi R16,200
ldi R17,0
rcall _delay_us
.dbline 79
; 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 main _main fV
.even
_main::
.dbline -1
.dbline 83
; }
;
; void main()
; {
.dbline 84
; port_init();
rcall _port_init
.dbline 85
; init_devices();
rcall _init_devices
rjmp L10
L9:
.dbline 88
;
; while(1)
; {
.dbline 89
; show_2_digit(34);
ldi R16,34
rcall _show_2_digit
.dbline 90
; }
L10:
.dbline 87
rjmp L9
X1:
.dbline -2
L8:
.dbline 0 ; func end
ret
.dbend
; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -