📄 com.s
字号:
.module Com.c
.area text(rom, con, rel)
.dbfile E:\software\MP3程序\Usart\Com.c
.dbfunc e Usart_init _Usart_init fV
.even
_Usart_init::
.dbline -1
.dbline 8
; #include <iom64v.h>
; #include <macros.h>
; /*-----------------------------------------------------------------------
; 延时函数
; 系统时钟:8M
; -----------------------------------------------------------------------*/
; void Usart_init(void)
; {
.dbline 10
; //set com0 for debug
; UBRR0H = 0X00;
clr R2
sts 144,R2
.dbline 11
; UBRR0L = 0X33;
ldi R24,51
out 0x9,R24
.dbline 12
; UCSR0B = (1<<3)|(1<<4); //调试信息不允许中断
ldi R24,24
out 0xa,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e USART_Transmit _USART_Transmit fV
; data -> R16
.even
_USART_Transmit::
.dbline -1
.dbline 16
; }
;
; void USART_Transmit( unsigned char data )
; {
L3:
.dbline 18
L4:
.dbline 18
; /* 等待发送缓冲器为空*/
; while ( !( UCSR0A & (1<<5)) );
sbis 0xb,5
rjmp L3
.dbline 20
; /* 将数据放入缓冲器,发送数据*/
; UDR0 = data;
out 0xc,R16
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbsym r data 16 c
.dbend
.dbfunc e USART_Receive _USART_Receive fc
.even
_USART_Receive::
.dbline -1
.dbline 23
; }
; unsigned char USART_Receive( void )
; {
L7:
.dbline 25
L8:
.dbline 25
; /* 等待接收数据*/
; while ( !(UCSR0A & (1<<7)) );
sbis 0xb,7
rjmp L7
.dbline 27
; /* 从缓冲器中获取并返回数据*/
; return UDR0;
in R16,0xc
.dbline -2
L6:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Print_str _Print_str fV
; pt -> R20,R21
.even
_Print_str::
xcall push_gset1
movw R20,R16
.dbline -1
.dbline 30
; }
; void Print_str(unsigned char *pt) //子
; {
xjmp L12
L11:
.dbline 31
movw R30,R20
ld R16,Z+
movw R20,R30
xcall _USART_Transmit
L12:
.dbline 31
; while(*pt != '\0') USART_Transmit(*pt++);
movw R30,R20
ldd R2,z+0
tst R2
brne L11
.dbline -2
L10:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r pt 20 pc
.dbend
.dbfunc e Print_val _Print_val fV
; temp -> R20
; data -> R22
.even
_Print_val::
xcall push_gset2
mov R22,R16
.dbline -1
.dbline 34
; }
; void Print_val(unsigned char data)
; {
.dbline 36
; unsigned char temp;
; temp = data;
mov R20,R22
.dbline 37
; temp >>= 4;
mov R24,R20
swap R24
andi R24,#0x0F
mov R20,R24
.dbline 38
; temp &= 0x0f;
andi R20,15
.dbline 39
; if(temp > 0x09) USART_Transmit(temp+0x37);
ldi R24,9
cp R24,R20
brsh L15
.dbline 39
mov R16,R20
subi R16,201 ; addi 55
xcall _USART_Transmit
xjmp L16
L15:
.dbline 40
; else USART_Transmit(temp+'0');
mov R16,R20
subi R16,208 ; addi 48
xcall _USART_Transmit
L16:
.dbline 41
; temp = data & 0x0f;
mov R20,R22
andi R20,15
.dbline 42
; if(temp > 0x09) USART_Transmit(temp+0x37);
ldi R24,9
cp R24,R20
brsh L17
.dbline 42
mov R16,R20
subi R16,201 ; addi 55
xcall _USART_Transmit
xjmp L18
L17:
.dbline 43
mov R16,R20
subi R16,208 ; addi 48
xcall _USART_Transmit
L18:
.dbline -2
L14:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym r data 22 c
.dbend
.dbfunc e Print_int _Print_int fV
; temp -> R20
; data -> R22,R23
.even
_Print_int::
xcall push_gset2
movw R22,R16
.dbline -1
.dbline 46
; else USART_Transmit(temp+'0');
; }
; void Print_int(unsigned int data)
; {
.dbline 48
; unsigned char temp;
; temp = data >> 8;
movw R20,R22
mov R20,R21
clr R21
.dbline 49
; Print_val(temp);
mov R16,R20
xcall _Print_val
.dbline 50
; temp = data;
mov R20,R22
.dbline 51
; Print_val(temp);
mov R16,R20
xcall _Print_val
.dbline -2
L19:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym r data 22 i
.dbend
.dbfunc e Print_size _Print_size fV
; data -> R22,R23
; temp -> R20
; ii -> R20,R21
.even
_Print_size::
xcall push_gset2
movw R20,R16
.dbline -1
.dbline 55
; }
;
; void Print_size(unsigned int ii)
; {
.dbline 58
; unsigned char temp;
; unsigned int data;
; data = ii;
movw R22,R20
.dbline 59
; temp = data/10000;
ldi R18,10000
ldi R19,39
movw R16,R22
xcall div16u
.dbline 60
; USART_Transmit(temp+'0');
subi R16,208 ; addi 48
xcall _USART_Transmit
.dbline 62
;
; data %= 10000;
ldi R18,10000
ldi R19,39
movw R16,R22
xcall mod16u
movw R22,R16
.dbline 63
; temp = data/1000;
ldi R18,1000
ldi R19,3
xcall div16u
.dbline 64
; USART_Transmit(temp+'0');
subi R16,208 ; addi 48
xcall _USART_Transmit
.dbline 66
;
; data %= 1000;
ldi R18,1000
ldi R19,3
movw R16,R22
xcall mod16u
movw R22,R16
.dbline 67
; temp = data/100;
ldi R18,100
ldi R19,0
xcall div16u
.dbline 68
; USART_Transmit(temp+'0');
subi R16,208 ; addi 48
xcall _USART_Transmit
.dbline 70
;
; data %= 100;
ldi R18,100
ldi R19,0
movw R16,R22
xcall mod16u
movw R22,R16
.dbline 71
; temp = data/10;
ldi R18,10
ldi R19,0
xcall div16u
.dbline 72
; USART_Transmit(temp+'0');
subi R16,208 ; addi 48
xcall _USART_Transmit
.dbline 74
;
; temp = data%10;
ldi R18,10
ldi R19,0
movw R16,R22
xcall mod16u
mov R20,R16
.dbline 75
; USART_Transmit(temp+'0');
subi R16,208 ; addi 48
xcall _USART_Transmit
.dbline -2
L20:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r data 22 i
.dbsym r temp 20 c
.dbsym r ii 20 i
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -