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

📄 uart.s

📁 AVR单片机平台Atmega32+CH375A芯片读写U盘代码
💻 S
字号:
	.module UART.c
	.area data(ram, con, rel)
_RxIndex::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile E:\xm\jxf\u盘读写模块\code\udisk_test0827\UART.c
	.dbsym e RxIndex _RxIndex i
_UartState::
	.blkb 1
	.area idata
	.byte 0
	.area data(ram, con, rel)
	.dbfile E:\xm\jxf\u盘读写模块\code\udisk_test0827\UART.c
	.dbsym e UartState _UartState c
	.area text(rom, con, rel)
	.dbfile E:\xm\jxf\u盘读写模块\code\udisk_test0827\UART.c
	.dbfunc e put_c _put_c fV
;              c -> R16
	.even
_put_c::
	.dbline -1
	.dbline 18
; #include "UART.h"
; //全局变量
; 
; unsigned char *UartRx;          //存放接收数据的指针
; unsigned int RxIndex=0;			//存放接收数据的个数
; unsigned int *RxLength;         //数据接收长度地址指针
; unsigned char UartState=0;        
; 
; #define UART_REC_COM 7
; /*
; BIT      7          6----------------------------------------0
;     UART_REC_COM         RESERVE
;     接收完成
;  */  
; 
; 
; void put_c(unsigned char c) //发送采用查询方式
; {
L2:
	.dbline 19
L3:
	.dbline 19
; 	while( !(UCSRA & (1<<UDRE)) );
	sbis 0xb,5
	rjmp L2
	.dbline 20
; 	UDR=c;
	out 0xc,R16
	.dbline -2
L1:
	.dbline 0 ; func end
	ret
	.dbsym r c 16 c
	.dbend
	.dbfunc e put_s _put_s fV
;            ptr -> R20,R21
	.even
_put_s::
	xcall push_gset1
	movw R20,R16
	.dbline -1
	.dbline 24
; }
; 
; void put_s(unsigned char *ptr)
; {
	xjmp L7
L6:
	.dbline 26
	.dbline 27
	movw R30,R20
	ld R16,Z+
	movw R20,R30
	xcall _put_c
	.dbline 28
L7:
	.dbline 25
; 	while (*ptr)
	movw R30,R20
	ldd R2,z+0
	tst R2
	brne L6
	.dbline -2
L5:
	xcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r ptr 20 pc
	.dbend
	.dbfunc e put_bytes _put_bytes fV
;      SendIndex -> R20,R21
;         length -> R22,R23
;            ptr -> R10,R11
	.even
_put_bytes::
	xcall push_gset3
	movw R22,R18
	movw R10,R16
	.dbline -1
	.dbline 32
; 	{
; 		put_c(*ptr++);
; 	}
; }
; 
; void put_bytes(unsigned char *ptr,unsigned int length)
; {
	.dbline 34
;     unsigned int SendIndex;
;     for(SendIndex = 0;SendIndex < length;SendIndex++)
	clr R20
	clr R21
	xjmp L13
L10:
	.dbline 35
	.dbline 36
	movw R30,R10
	ld R16,Z+
	movw R10,R30
	xcall _put_c
	.dbline 37
L11:
	.dbline 34
	subi R20,255  ; offset = 1
	sbci R21,255
L13:
	.dbline 34
	cp R20,R22
	cpc R21,R23
	brlo L10
	.dbline -2
L9:
	xcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r SendIndex 20 i
	.dbsym r length 22 i
	.dbsym r ptr 10 pc
	.dbend
	.area vector(rom, abs)
	.org 52
	jmp _usart_rx_isr
	.area text(rom, con, rel)
	.dbfile E:\xm\jxf\u盘读写模块\code\udisk_test0827\UART.c
	.dbfunc e usart_rx_isr _usart_rx_isr fV
	.even
_usart_rx_isr::
	st -y,R2
	st -y,R3
	st -y,R24
	st -y,R25
	st -y,R30
	st -y,R31
	in R2,0x3f
	st -y,R2
	.dbline -1
	.dbline 44
	.dbline 46
	lds R2,_UartRx
	lds R3,_UartRx+1
	lds R30,_RxIndex
	lds R31,_RxIndex+1
	add R30,R2
	adc R31,R3
	in R2,0xc
	std z+0,R2
	.dbline 47
	lds R24,_RxIndex
	lds R25,_RxIndex+1
	adiw R24,1
	sts _RxIndex+1,R25
	sts _RxIndex,R24
	.dbline 48
	cpi R24,2
	ldi R30,0
	cpc R25,R30
	brlo L15
	lds R30,_RxLength
	lds R31,_RxLength+1
	ldd R2,z+0
	ldd R3,z+1
	cp R24,R2
	cpc R25,R3
	brlo L15
	.dbline 50
	.dbline 51
	clr R2
	clr R3
	sts _RxIndex+1,R3
	sts _RxIndex,R2
	.dbline 52
	lds R24,_UartState
	ori R24,128
	sts _UartState,R24
	.dbline 53
L15:
	.dbline -2
L14:
	ld R2,y+
	out 0x3f,R2
	ld R31,y+
	ld R30,y+
	ld R25,y+
	ld R24,y+
	ld R3,y+
	ld R2,y+
	.dbline 0 ; func end
	reti
	.dbend
	.dbfunc e init_USART _init_USART fV
;     EnInterrup -> R16
	.even
_init_USART::
	.dbline -1
	.dbline 62
;     {
;         put_c(*ptr++);
;     }
; }
; 
; 
; //串口接收中断服务程序
; #pragma interrupt_handler usart_rx_isr: iv_USART_RX
; void usart_rx_isr(void)
; {
; 	
; 	*(UartRx+RxIndex) = UDR;		//保存数据到数组里面
;     RxIndex++;
; 	if((RxIndex>=2) &&
;         (RxIndex>= *RxLength))
;     {
;         RxIndex=0;
;         UartState|= 1<<UART_REC_COM;    //通知主函数已经接收一帧数据完成
;     }
; 		
; }
; 
; /************************************************************************/
; /* EnInterrup:0,不使能接收功能,!0使能接收功能
;                                                                      */
; /************************************************************************/
; void init_USART(unsigned char EnInterrup)//USART 初始化
; {
	.dbline 65
; 
;     //USART 9600 8, n,1  PC上位机软件(超级终端等)也要设成同样的设置才能通讯
;     UCSRC = (1<<URSEL) | 0x06;
	ldi R24,134
	out 0x20,R24
	.dbline 81
;     //异步,8位数据,无奇偶校验,一个停止位,无倍速
;     /*
;     UBRRH与UCSRC共用I/O 地址。因此访问该地址时需注意以下问题。
;     写访问
;     当在该地址执行写访问时, USART 寄存器选择位(URSEL)控制被写入的寄存器。
;     若URSEL为0,对UBRRH值更新;若URSEL为1,对UCSRC设置更新
;     
;     读访问
;     对UBRRH 或UCSRC 寄存器的读访问则较为复杂。但在大多数应用中,基本不需要读这些寄存器
;     
;     
;     没有UBRR这个16位寄存器,因为UBRRL(0x09)/UBRRH(0x20)的地址不连续,而且UBRRH跟UCSRC共用地址
;     */
;     
;     //U2X=0时的公式计算
;     UBRRL= (F_CPU/BAUDRATE/16-1)%256;
	ldi R24,51
	out 0x9,R24
	.dbline 82
;     UBRRH= (F_CPU/BAUDRATE/16-1)/256;
	clr R2
	out 0x20,R2
	.dbline 89
;     //U2X=1时的公式计算
;     //UBRRL= (F_CPU/BAUDRATE/8-1)%256;
;     //UBRRH= (F_CPU/BAUDRATE/8-1)/256;
;     //也可根据数据手册的[波特率设置的例子]查得
;     //UBRRL = 0x2F; //set baud rate lo
;     //UBRRH = 0x00; //set baud rate hi
;     UCSRA = 0x00;
	out 0xb,R2
	.dbline 90
;     if(EnInterrup)
	tst R16
	breq L18
	.dbline 91
;         UCSRB = (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
	ldi R24,152
	out 0xa,R24
	xjmp L19
L18:
	.dbline 94
	ldi R24,24
	out 0xa,R24
L19:
	.dbline -2
L17:
	.dbline 0 ; func end
	ret
	.dbsym r EnInterrup 16 c
	.dbend
	.area bss(ram, con, rel)
	.dbfile E:\xm\jxf\u盘读写模块\code\udisk_test0827\UART.c
_RxLength::
	.blkb 2
	.dbsym e RxLength _RxLength pi
_UartRx::
	.blkb 2
	.dbsym e UartRx _UartRx pc

⌨️ 快捷键说明

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