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

📄 usart.s

📁 M16控制,从键盘输入字符,当输入字符达到10个的时候,终端和LCD都显示所接收到的字符
💻 S
字号:
	.module usart.c
	.area text(rom, con, rel)
	.dbfile E:\新建文件夹\usart_icc\cfile\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
;     // 通信参数: 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::
	st -y,R20
	mov R20,R16
	.dbline -1
	.dbline 20
;     //sei();
; }
; 
; int PutChar(char c)
; {
	.dbline 21
;     if(c == '\n')
	cpi R20,10
	brne L3
X0:
	.dbline 22
;     {
	.dbline 23
;         PutChar('\r');
	ldi R16,13
	xcall _PutChar
	.dbline 24
;     }
L3:
	.dbline 25
;     UDR = c;
	out 0xc,R20
L5:
	.dbline 26
;     while(!(UCSRA &(1<<UDRE)));
L6:
	.dbline 26
	sbis 0xb,5
	rjmp L5
X1:
	.dbline 27
;     UCSRA |= (1<<UDRE);
	sbi 0xb,5
	.dbline 28
;     return 0;
	clr R16
	clr R17
	.dbline -2
L2:
	.dbline 0 ; func end
	ld R20,y+
	ret
	.dbsym r c 20 c
	.dbend
	.dbfunc e SendNbyte _SendNbyte fV
;              w -> R10
;              L -> R12
;              p -> R14,R15
	.even
_SendNbyte::
	xcall push_xgset00FC
	mov R12,R18
	movw R14,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 R10
	xjmp L12
L9:
	.dbline 36
;     {
	.dbline 40
;        // UDR = *(p+w);
;        // while(!(UCSRA &(1<<UDRE)));
;         //UCSRA |= (1<<UDRE);
;         PutChar(*(p+w));
	mov R30,R10
	clr R31
	add R30,R14
	adc R31,R15
	ldd R16,z+0
	xcall _PutChar
	.dbline 41
;     }
L10:
	.dbline 35
	inc R10
L12:
	.dbline 35
	cp R10,R12
	brlo L9
X2:
	.dbline -2
L8:
	.dbline 0 ; func end
	xjmp pop_xgset00FC
	.dbsym r w 10 c
	.dbsym r L 12 c
	.dbsym r p 14 pc
	.dbend
	.dbfunc e PutStr _PutStr fV
;            Str -> R20,R21
	.even
_PutStr::
	st -y,R20
	st -y,R21
	movw R20,R16
	.dbline -1
	.dbline 46
;     
; }
; 
; void PutStr(unsigned char *Str)
; {
	xjmp L15
L14:
	.dbline 48
;     while(*Str != '\0')
;     {
	.dbline 49
;         PutChar(*Str);
	movw R30,R20
	ldd R16,z+0
	xcall _PutChar
	.dbline 50
;         Str++;
	subi R20,255  ; offset = 1
	sbci R21,255
	.dbline 51
;     }
L15:
	.dbline 47
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L14
X3:
	.dbline -2
L13:
	.dbline 0 ; func end
	ld R21,y+
	ld R20,y+
	ret
	.dbsym r Str 20 pc
	.dbend
; }

⌨️ 快捷键说明

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