📄 usart.s
字号:
.module usart.c
.area text(rom, con, rel)
.dbfile F:\开发\C程序开发\AVR\usart\usart.c
.dbfunc e uart_init _uart_init fV
.even
_uart_init::
.dbline -1
.dbline 17
; //Project : USART
; //Writer :youhu
; //ICC-AVR application builder : 2007-4-24 16:45:33
; // Target : M16
; // Crystal: 8.0000Mhz
; // USART initialize
; // desired baud rate: 115200
; // actual: baud rate:111111 (3.7%)
; // char size: 8 bit
; // parity: Disabled
;
; #include <iom16v.h>
; #include <macros.h>
; unsigned char mes;
;
; void uart_init(void)
; {
.dbline 18
; UCSRB = 0x00;
clr R2
out 0xa,R2
.dbline 19
; UCSRA = 0x03; //异步模式,禁止奇偶校验,8位数据帧
ldi R24,3
out 0xb,R24
.dbline 20
; UCSRC = BIT(URSEL) | 0x06;
ldi R24,134
out 0x20,R24
.dbline 21
; UBRRL = 0x08; //波特率设置为115200
ldi R24,8
out 0x9,R24
.dbline 22
; UBRRH = 0x00;
out 0x20,R2
.dbline 23
; UCSRB = 0xF8; //允许串口发送和接收,接收和发送中断使能
ldi R24,248
out 0xa,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e USART_Receive _USART_Receive fc
.even
_USART_Receive::
.dbline -1
.dbline 34
; }
;
; /*
; void USART_Transmit( unsigned char data )
; {
; while ( !( UCSRA & (1<<UDRE)) );
; UDR = data;
; }
; */
; unsigned char USART_Receive( void ) //串口从主机接收数据
; {
L3:
.dbline 36
L4:
.dbline 36
;
; while ( !(UCSRA & (1<<RXC)) ); // 等待接收数据
sbis 0xb,7
rjmp L3
.dbline 38
;
; return UDR; // 从缓冲器中获取并返回数据
in R16,0xc
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 52
jmp _uart0_tx_isr
.area text(rom, con, rel)
.dbfile F:\开发\C程序开发\AVR\usart\usart.c
.dbfunc e uart0_tx_isr _uart0_tx_isr fV
.even
_uart0_tx_isr::
xcall push_lset
.dbline -1
.dbline 50
; }
;
; /*
; #pragma interrupt_handler uart0_rx_isr:12 //接收中断函数
; void uart0_rx_isr(void)
; {
; //wait a task;
; }
; */
; #pragma interrupt_handler uart0_tx_isr:14 //发送中断函数
; void uart0_tx_isr(void)
; {
.dbline 51
; mes = USART_Receive();
xcall _USART_Receive
sts _mes,R16
L7:
.dbline 52
L8:
.dbline 52
; while ( !( UCSRA & (1<<UDRE)) ); // 等待发送缓冲器为空
sbis 0xb,5
rjmp L7
.dbline 53
; UDR = mes; // 将数据放入缓冲器,发送数据
lds R2,_mes
out 0xc,R2
.dbline -2
L6:
xcall pop_lset
.dbline 0 ; func end
reti
.dbend
.dbfunc e init_devices _init_devices fV
.even
_init_devices::
.dbline -1
.dbline 57
; }
;
; void init_devices(void) //初始化各中断
; {
.dbline 58
; CLI();
cli
.dbline 59
; uart_init();
xcall _uart_init
.dbline 60
; MCUCR = 0x00;
clr R2
out 0x35,R2
.dbline 61
; GICR = 0x00;
out 0x3b,R2
.dbline 62
; TIMSK = 0x00;
out 0x39,R2
.dbline 63
; SEI();
sei
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 68
; }
;
;
; void main(void)
; {
.dbline 69
; init_devices();
xcall _init_devices
.dbline -2
L11:
.dbline 0 ; func end
ret
.dbend
.area bss(ram, con, rel)
.dbfile F:\开发\C程序开发\AVR\usart\usart.c
_mes::
.blkb 1
.dbsym e mes _mes c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -