📄 uart.c
字号:
#include <iom16v.h>
#include <macros.h>
#include <stdio.h>
//函数声明
void uart0_init(void);
void main(void)
{
unsigned char temp;
uart0_init();
puts("UART TEST");//发送字符串
puts("www.ouravr.com");
putchar('\r');
putchar('\n');
while(1)
{
temp=getchar();
putchar(temp);
puts(" had been sent to the MCU!");
putchar('\r');
putchar('\n');
}
}
//UART初始化,软件生成,使能接收和发送,8数据位,1停止位,偶校验,19.2K波特率
void uart0_init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00;
UCSRC = BIT(URSEL) | 0x26;
UBRRL = 0x0C; //set baud rate lo
UBRRH = 0x00; //set baud rate hi
UCSRB = 0x18;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -