uart.c
来自「avr应用有关使用注意事项如下 1 在使用例子程序之前将库文件libslavr」· C语言 代码 · 共 35 行
C
35 行
#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 + =
减小字号Ctrl + -
显示快捷键?