/*
* USART.h
*
* Created: 2014/3/11 0:03:01
* Author: 000
*/
#ifndef USART_H_
#define USART_H_
#include <avr/io.h>
#include <stdio.h>
//#define Baud_9600 51//8MHz
#define Baud_9600 77//12MHz
void USART_Init( uint16_t Baud );
#endif /* USART_H_ */
/*
* USART.c
*
* Created: 2014/3/11 0:02:46
* Author: 000
*/
#include "USART.h"
/**********************************************************
*函数名:USART_Init
*参 数:Baud,波特率
*时 间:2014-03-03
*修 改:
*说 明:USART初始化
**********************************************************/
void USART_Init( uint16_t Baud )
{
/*设置波特率*/
UBRRH = (uint8_t)(Baud>>8);
UBRRL = (uint8_t)Baud;
/*数据结构设置*/
UCSRB &= ~_BV(UCSZ2);
UCSRC |= _BV(URSEL)|_BV(UCSZ0)|_BV(UCSZ1);//字符长度8bit
UCSRC &=~_BV(USBS);//停止位1bit
/*使能USART发送功能*/
UCSRB |= _BV(TXEN);
}
|