#include "myuart.h"
#include "avr/io.h"
#include
#define UDRE 5
#define RXEN 4
#define TXEN 3
#define UCSZ0 1
#define RXC 7
#define RXCIE 7
ISR(USART0_RX_vect)//接收中斷
{
unsigned char dummy;
while ( UCSR0A & (1<
dummy = UDR0;
}
USART_Transmit(dummy);
}
void USART_Transmit(unsigned char data)//發(fā)送字節(jié)
{
/* 等待發(fā)送緩沖器為空 */
while ( !( UCSR0A & (1<
/* 將數(shù)據(jù)放入緩沖器,發(fā)送數(shù)據(jù) */
UDR0 = data;
}
void myuart_init(void)
{
//關(guān)總中斷
cli();
//4MHZ晶振,設(shè)置波特率
UCSR0A &= 0x02; //不倍頻
unsigned char baud;
baud = 25; //9600
UBRR0H = (unsigned char)(baud>>8);
UBRR0L = (unsigned char)baud;
// 接收器與發(fā)送器使能,接收中斷允許
UCSR0B = (1<
UCSR0C = (3<
//開總中斷
sei();
}