//-----------------------------------------------------------
//程序由AVR辅助开发工具V2.0.0自动生成
//MCU系统的处理器为: ATMega16
//MCU系统的晶振频率: 8.0000 Mhz
//-----------------------------------------------------------
#include <iom16v.h>
#include "uart.h"
//-----------------------------------------------------------
//串口初始化子程序
//字符长度:8位
//奇偶校验:禁止
//通讯模式:异步
//-----------------------------------------------------------
void Uart_Init(void)
{
UCSRB = 0x00; //disable while setting baud rate
UCSRA = 0x00; //Bit1为1则倍速发送
UCSRC = 0x86;
UBRRL = 0x33; //波特率:9600 Bps
UBRRH = 0x00; //误差率:0.156%
UCSRB = 0x18;
}
//-----------------------------------------------------------
//串口接收字节子程序
//-----------------------------------------------------------
unsigned char Getchar(void)
{
while(!(UCSRA& (1<<RXC)));
return UDR;
}
//-----------------------------------------------------------
//串口发送字节子程序
//-----------------------------------------------------------
void Putchar(unsigned char c)
{
while (!(UCSRA&(1<<UDRE)));
UDR=c;
}
//-----------------------------------------------------------
//串口发送字符串子程序
//-----------------------------------------------------------
void Putstr(char *s)
{
while (*s)
{
Putchar(*s);
s++;
}
}
//-----------------------------------------------------------
//串口发送字符串子程序(带有换行符)
//-----------------------------------------------------------
void Puts(char *s)
{
while (*s)
{
Putchar(*s);
s++;
}
Putchar(0x0a); //回车换行
Putchar(0x0d);
}