📄 main.s
字号:
.module main.c
.area text(rom, con, rel)
.dbfile E:\ICCAVR\project\AVRMEG~2\icc\009-UART-LED-A\main.c
.dbfunc e Uart_Init _Uart_Init fV
.even
_Uart_Init::
.dbline -1
.dbline 18
; /*
; 实验九:
;
; UART接口实险。
; 1、串口以查询方式接收数据,并分别将数据显示的PB口和返回。
; 2、内部1 M晶振,程序采用单任务方式,软件延时。
; 3、进行此实验请插上JP1的所有8个短路块,JP7(LED_EN)短路块。
; 4、通过此实验,可以对串口通信有个初步认识。
;
; AVR mega16学习板
; www.iccavr.com
; 11:47 2007-4-8
; */
;
; #include "iom16v.h"
;
; /*串口初始化函数*/
; void Uart_Init(void) {
.dbline 19
; UCSRA = 0x02; /*倍速*/
ldi R24,2
out 0xb,R24
.dbline 20
; UCSRB = 0x18; /*允许接收和发送*/
ldi R24,24
out 0xa,R24
.dbline 21
; UCSRC = 0x06; /*8位数据*/
ldi R24,6
out 0x20,R24
.dbline 22
; UBRRH = 0x00;
clr R2
out 0x20,R2
.dbline 23
; UBRRL = 12; /*9600*/
ldi R24,12
out 0x9,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Uart_Transmit _Uart_Transmit fV
; i -> R16
.even
_Uart_Transmit::
.dbline -1
.dbline 27
; }
;
; /*数据发送,查询方式*/
; void Uart_Transmit(unsigned char i) {
L3:
.dbline 29
L4:
.dbline 29
;
; while (!(UCSRA & (1<<UDRE))); /* 等待发送缓冲器为空*/
sbis 0xb,5
rjmp L3
.dbline 30
; UDR = i; /* 发送数据*/
out 0xc,R16
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbsym r i 16 c
.dbend
.dbfunc e Uart_Receive _Uart_Receive fc
.even
_Uart_Receive::
.dbline -1
.dbline 34
; }
;
; /*数据接收,查询方式*/
; unsigned char Uart_Receive( void ) {
L7:
.dbline 36
L8:
.dbline 36
;
; while (!(UCSRA & (1<<RXC))); /* 等待接收数据*/
sbis 0xb,7
rjmp L7
.dbline 37
; return UDR; /* 获取并返回数据*/
in R16,0xc
.dbline -2
L6:
.dbline 0 ; func end
ret
.dbend
.dbfunc e main _main fV
; temp -> R20
.even
_main::
.dbline -1
.dbline 42
; }
;
;
; /*主函数*/
; void main(void) {
.dbline 46
;
; unsigned char temp;
;
; DDRA = 0x00; /*方向输入*/
clr R2
out 0x1a,R2
.dbline 47
; PORTA = 0xFF; /*打开上拉*/
ldi R24,255
out 0x1b,R24
.dbline 48
; DDRB = 0xFF; /*方向输出*/
out 0x17,R24
.dbline 49
; PORTB = 0xFF; /*电平设置*/
out 0x18,R24
.dbline 50
; DDRC = 0x00;
out 0x14,R2
.dbline 51
; PORTC = 0xFF;
out 0x15,R24
.dbline 52
; DDRD = 0x02;
ldi R24,2
out 0x11,R24
.dbline 53
; PORTD = 0xFF;
ldi R24,255
out 0x12,R24
.dbline 54
; Uart_Init();
xcall _Uart_Init
xjmp L12
L11:
.dbline 56
.dbline 57
xcall _Uart_Receive
mov R20,R16
.dbline 58
mov R2,R20
com R2
out 0x18,R2
.dbline 59
xcall _Uart_Transmit
.dbline 60
L12:
.dbline 56
xjmp L11
X0:
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -