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

📄 usart.s

📁 avr icc开发的avr单片机与pc机vb通讯控制程序
💻 S
字号:
	.module usart.c
	.area text(rom, con, rel)
	.dbfile D:\dai\AVR_USART\usart.c
	.dbfunc e UsartInit _UsartInit fV
	.even
_UsartInit::
	.dbline -1
	.dbline 4
; #define USART_C
; #include "includes.h"
; void UsartInit(void)
; {
	.dbline 12
;     // 晶振频率 : 4.0MHz
;     // 通信参数:  9600  8 Data, 1 Stop, No Parity 
;     // 波特率:
;     // UBRRL= 0x0C    19200;
;     // UBRRL= 0x19    9600;
;     // UBRRL= 0x33    4800;
;     // UBRRL= 0x67    2400	
;     UCSRB |= (1<<RXEN)|(1<<TXEN)|(1<<RXCIE);  //允许发送和接收,接收中断使能
	in R24,0xa
	ori R24,152
	out 0xa,R24
	.dbline 13
;     UCSRC |= (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); //8位数据位+1位停止位
	in R24,0x20
	ori R24,134
	out 0x20,R24
	.dbline 14
;     UBRRH = 0x00; 
	clr R2
	out 0x20,R2
	.dbline 15
;     UBRRL = 0x19;  
	ldi R24,25
	out 0x9,R24
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e PutChar _PutChar fI
;              c -> R20
	.even
_PutChar::
	xcall push_gset1
	mov R20,R16
	.dbline -1
	.dbline 20
;     //sei();
; }
; 
; int PutChar(char c)
; {
	.dbline 21
;     if(c == '\n')
	cpi R20,10
	brne L3
	.dbline 22
;     {
	.dbline 23
;         PutChar('\r');
	ldi R16,13
	xcall _PutChar
	.dbline 24
;     }
L3:
	.dbline 25
;     UDR = c;
	out 0xc,R20
L5:
	.dbline 26
L6:
	.dbline 26
;     while(!(UCSRA &(1<<UDRE)));
	sbis 0xb,5
	rjmp L5
	.dbline 27
;     UCSRA |= (1<<UDRE);
	sbi 0xb,5
	.dbline 28
;     return 0;
	clr R16
	clr R17
	.dbline -2
L2:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r c 20 c
	.dbend
	.dbfunc e SendNbyte _SendNbyte fV
;              w -> R20
;              L -> R22
;              p -> R10,R11
	.even
_SendNbyte::
	xcall push_gset3
	mov R22,R18
	movw R10,R16
	.dbline -1
	.dbline 33
; }
; 
; 
; void SendNbyte(unsigned char *p,unsigned char L)
; {
	.dbline 35
;     unsigned char w;
;     for(w=0;w<L;w++)
	clr R20
	xjmp L12
L9:
	.dbline 36
	.dbline 40
	mov R30,R20
	clr R31
	add R30,R10
	adc R31,R11
	ldd R16,z+0
	xcall _PutChar
	.dbline 41
L10:
	.dbline 35
	inc R20
L12:
	.dbline 35
	cp R20,R22
	brlo L9
	.dbline -2
L8:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r w 20 c
	.dbsym r L 22 c
	.dbsym r p 10 pc
	.dbend
	.dbfunc e PutStr _PutStr fV
;            Str -> R20,R21
	.even
_PutStr::
	xcall push_gset1
	movw R20,R16
	.dbline -1
	.dbline 46
;     {
;        // UDR = *(p+w);
;        // while(!(UCSRA &(1<<UDRE)));
;         //UCSRA |= (1<<UDRE);
;         PutChar(*(p+w));
;     }
;     
; }
; 
; void PutStr(unsigned char *Str)
; {
	xjmp L15
L14:
	.dbline 48
	.dbline 49
	movw R30,R20
	ldd R16,z+0
	xcall _PutChar
	.dbline 50
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 51
L15:
	.dbline 47
;     while(*Str != '\0')
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L14
	.dbline -2
L13:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r Str 20 pc
	.dbend

⌨️ 快捷键说明

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