|
用串口调试助手发送数据,单片机每次接收时,在中断程序中总是接收到数据0.
我把相关程序代码贴上,请高手们看看。
//UART0 initialize
// desired baud rate: 4800
// actual: baud rate:4808 (0.2%)
void uart0_init(void)
{
UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06; //异步模式,无奇偶校验位,1位停止位,8位数据位,
UBRR0L = 0x67; //set baud rate lo,波特率设置为4800bps.
UBRR0H = 0x00; //set baud rate hi
UCSR0B = 0xD8; //接收中断使能,发送中断使能,发送使能,接收使能
}
#pragma interrupt_handler uart0_rx_isr:iv_USART0_RXC
void uart0_rx_isr(void)
{
uint8 status, data;
status = UCSR0A;
data = UDR0;
if(data == 0x00)
{
PORTE |= (1<
}
}
|
|