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

📄 uart.s

📁 avr单片机mega128 的串口通讯的完整程序
💻 S
字号:
	.module uart.c
	.area text(rom, con, rel)
	.dbfile C:\AVR_TOOL\test\uart.c
	.dbfunc e Uart0_Init _Uart0_Init fV
	.even
_Uart0_Init::
	.dbline -1
	.dbline 19
; //-----------------------------------------------------------
; //程序由AVR辅助开发工具V2.1.1自动生成     
; //MCU系统的处理器为:    ATMega128
; //MCU系统的晶振频率:    8.0000 Mhz
; //-----------------------------------------------------------
; 
; #include <iom128v.h>
; #include "uart.h"
; #include "delay.h"
; 
; 
; //-----------------------------------------------------------
; //串口0初始化子程序
; //字符长度:8位
; //奇偶校验:禁止
; //通讯模式:异步
; //-----------------------------------------------------------
; void Uart0_Init(void)
; {
	.dbline 20
;     UCSR0B  =  0x00;     //disable while setting baud rate
	clr R2
	out 0xa,R2
	.dbline 21
;     UCSR0A  =  0x00;     //Bit1为1则倍速发送
	out 0xb,R2
	.dbline 22
;     UCSR0C  =  0x06;  
	ldi R24,6
	sts 149,R24
	.dbline 23
;     UBRR0L  =  0x22;     //波特率:14400 Bps
	ldi R24,34
	out 0x9,R24
	.dbline 24
;     UBRR0H  =  0x00;     //误差率:-0.799%
	sts 144,R2
	.dbline 25
;     UCSR0B  =  0x18;  
	ldi R24,24
	out 0xa,R24
	.dbline 27
; //初始化RS485通讯的流控制引脚
;     RS485_RD0_PORT|= RS485_RD0_BIT;
	sbi 0x3,2
	.dbline 28
;     RS485_RD0_DDR|= RS485_RD0_BIT;
	sbi 0x2,2
	.dbline 29
;     RS485_RD0_L;
	sbi 0x3,2
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Getchar0 _Getchar0 fc
	.even
_Getchar0::
	.dbline -1
	.dbline 36
; }
; 
; //-----------------------------------------------------------
; //串口0接收字节子程序
; //-----------------------------------------------------------
; unsigned char Getchar0(void)
; {
L3:
	.dbline 37
L4:
	.dbline 37
;  while(!(UCSR0A& (1<<RXC0)));
	sbis 0xb,7
	rjmp L3
	.dbline 38
;    return UDR0;
	in R16,0xc
	.dbline -2
L2:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Putchar0 _Putchar0 fV
;              c -> R20
	.even
_Putchar0::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 45
; }
; 
; //-----------------------------------------------------------
; //串口0发送字节子程序
; //-----------------------------------------------------------
; void Putchar0(unsigned char c)
; {
	.dbline 46
;    RS485_RD0_H;
	cbi 0x3,2
L7:
	.dbline 47
L8:
	.dbline 47
;    while (!(UCSR0A&(1<<UDRE0)));
	sbis 0xb,5
	rjmp L7
	.dbline 48
;    UDR0=c;
	out 0xc,R20
L10:
	.dbline 49
L11:
	.dbline 49
;    while (!(UCSR0A&(1<<UDRE0)));
	sbis 0xb,5
	rjmp L10
	.dbline 50
;    delay_nus(500);
	ldi R16,500
	ldi R17,1
	xcall _delay_nus
	.dbline 51
;    RS485_RD0_L;
	sbi 0x3,2
	.dbline -2
L6:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r c 20 c
	.dbend
	.dbfunc e Putstr0 _Putstr0 fV
;              s -> R20,R21
	.even
_Putstr0::
	xcall push_gset1
	movw R20,R16
	.dbline -1
	.dbline 58
; }
; 
; //-----------------------------------------------------------
; //串口0发送字符串子程序
; //-----------------------------------------------------------
; void Putstr0(char *s)
; {
	xjmp L15
L14:
	.dbline 60
	.dbline 61
	movw R30,R20
	ldd R16,z+0
	xcall _Putchar0
	.dbline 62
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 63
L15:
	.dbline 59
;    while (*s)
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L14
	.dbline -2
L13:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r s 20 pc
	.dbend
	.dbfunc e Puts0 _Puts0 fV
;              s -> R20,R21
	.even
_Puts0::
	xcall push_gset1
	movw R20,R16
	.dbline -1
	.dbline 70
;    {
;       Putchar0(*s);
;       s++;
;    }
; }
; 
; //-----------------------------------------------------------
; //串口0发送字符串子程序(带有换行符)
; //-----------------------------------------------------------
; void Puts0(char *s)
; {
	xjmp L19
L18:
	.dbline 72
	.dbline 73
	movw R30,R20
	ldd R16,z+0
	xcall _Putchar0
	.dbline 74
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 75
L19:
	.dbline 71
;    while (*s)
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L18
	.dbline 76
;    {
;       Putchar0(*s);
;       s++;
;    }
;    Putchar0(0x0d);   //回车换行
	ldi R16,13
	xcall _Putchar0
	.dbline 77
;    Putchar0(0x0a);
	ldi R16,10
	xcall _Putchar0
	.dbline -2
L17:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r s 20 pc
	.dbend
	.dbfunc e buffer2str _buffer2str fpc
;              i -> R20
;            hhh -> R16,R17
	.even
_buffer2str::
	xcall push_gset1
	.dbline -1
	.dbline 84
; }
; 
; //-----------------------------------------------------------
; //数组转换成可发送的字符串
; //-----------------------------------------------------------
; char *buffer2str(char *hhh)
; {
	.dbline 85
;    unsigned char i=0;
	clr R20
	xjmp L23
L22:
	.dbline 88
	.dbline 89
	mov R2,R20
	clr R3
	add R2,R16
	adc R3,R17
	movw R30,R2
	ldd R24,z+0
	subi R24,208    ; addi 48
	std z+0,R24
	.dbline 90
	inc R20
	.dbline 91
L23:
	.dbline 87
; 
;    while (i<40)
	cpi R20,40
	brlo L22
	.dbline 92
;    {
;       hhh[i]=hhh[i]+48;
;       i++;
;    }	
;    return hhh;
	.dbline -2
L21:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbsym r hhh 16 pc
	.dbend
	.dbfunc e long2str _long2str fpc
;             ss -> R10,R11
;             hh -> y+6
	.even
_long2str::
	xcall push_arg4
	xcall push_gset3
	.dbline -1
	.dbline 99
; }
; 
; //-----------------------------------------------------------
; //数字转换成可发送的字符串
; //-----------------------------------------------------------
; char *long2str(unsigned long hh)
; {
	.dbline 100
;    char *ss="    ";
	ldi R24,<L26
	ldi R25,>L26
	movw R10,R24
	.dbline 102
; 
;    ss[0]=48+hh/1000;
	ldi R20,232
	ldi R21,3
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	movw R16,R2
	movw R18,R4
	xcall div32u
	movw R2,R16
	movw R4,R18
	ldi R20,48
	ldi R21,0
	ldi R22,0
	ldi R23,0
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	movw R30,R10
	std z+0,R2
	.dbline 103
;    ss[1]=48+(hh%1000)/100;
	ldi R20,232
	ldi R21,3
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	movw R16,R2
	movw R18,R4
	xcall mod32u
	ldi R20,100
	ldi R21,0
	ldi R22,0
	ldi R23,0
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall div32u
	movw R2,R16
	movw R4,R18
	ldi R20,48
	ldi R21,0
	ldi R22,0
	ldi R23,0
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	movw R30,R10
	std z+1,R2
	.dbline 104
;    ss[2]=48+(hh%100)/10;
	ldi R20,100
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	movw R16,R2
	movw R18,R4
	xcall mod32u
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	xcall div32u
	movw R2,R16
	movw R4,R18
	ldi R20,48
	ldi R21,0
	ldi R22,0
	ldi R23,0
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	movw R30,R10
	std z+2,R2
	.dbline 105
;    ss[3]=48+(hh%10);
	ldi R20,10
	ldi R21,0
	ldi R22,0
	ldi R23,0
	movw R30,R28
	ldd R2,z+6
	ldd R3,z+7
	ldd R4,z+8
	ldd R5,z+9
	st -y,R23
	st -y,R22
	st -y,R21
	st -y,R20
	movw R16,R2
	movw R18,R4
	xcall mod32u
	movw R2,R16
	movw R4,R18
	ldi R20,48
	ldi R21,0
	ldi R22,0
	ldi R23,0
	add R2,R20
	adc R3,R21
	adc R4,R22
	adc R5,R23
	movw R30,R10
	std z+3,R2
	.dbline 107
; 
;    return ss;	
	movw R16,R10
	.dbline -2
L25:
	xcall pop_gset3
	adiw R28,4
	.dbline 0 ; func end
	ret
	.dbsym r ss 10 pc
	.dbsym l hh 6 l
	.dbend
	.area data(ram, con, rel)
	.dbfile C:\AVR_TOOL\test\uart.c
L26:
	.blkb 5
	.area idata
	.byte 32,32,32,32,0
	.area data(ram, con, rel)
	.dbfile C:\AVR_TOOL\test\uart.c

⌨️ 快捷键说明

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