#include
#include
#include
unsigned char rdata;
unsigned char biaozhi;
#define CRYSTAL 8000000 //系统时钟8MHZ
//发送函数
void USART_Transmit(unsigned int data)
{
UDR=data;
}
ISR(USART_RXC_vect)
{
rdata=UDR;
biaozhi=1;
}
void init(unsigned int BAUD)
{
unsigned char a;
a=CRYSTAL/16/BAUD-1;
UCSRC=0x86;
UCSRB=0x98;
UBRRH=a%256;
UBRRL=a/256;
sei();
}
int main()
{ DDRD=0x02;
init(9600);
while(1)
{ if(biaozhi)
biaozhi=0;
USART_Transmit(rdata);
}