void Usart0_Init(void)
{
UCSRB = 0x00;
UCSRA = 0x00;
UCSRC = 0x86; //UCSRC = (1 << UCSZ1) | (1 << UCSZ0)|(1 << URSEL); 异步,数据格式8,N,1
UBRRH = 0x00; //UBRRH= (F_CPU / Baud / 16 - 1) / 256;
UBRRL = 0x33; //UBRRL= (F_CPU / Baud / 16 - 1) % 256;
UCSRB = 0x98; //UCSRB =(1<<RXCIE)|(1<<RXEN)|(1<<TXEN)//发送使能
}
void PutChar(uchar c)
{
while(!(UCSRA&(1<<UDRE))); //等待缓冲器为空,UDRE为1时
UDR = c; //将要发送的数据装入UDR寄存器
}
main
{
DDRD|=0x02; //TX
PORTD|=0x10; //上拉电阻有效
Usart0_Init();
sei(); //开总中断
PutChar('A');
} |