//UART0 initialize // desired baud rate: 2400 // actual: baud rate:2404 (0.2%) // char size: 8 bit // parity: Disabled void uart0_init(void) { UCSRB = 0x00; //disable while setting baud rate UCSRA = 0x00; UBRRL = 0x19; //set baud rate lo UBRRH = 0x00; //set baud rate hi //UCSRB = 0xD8; UCSRB = (1 << RXCIE) | (1 << TXCIE) | (1 << RXEN) | (1 << TXEN); UCSRC = BIT(URSEL) | 0x06; }
//------------------------------------------------------------------------------ #pragma interrupt_handler uart0_rx_isr:12 void uart0_rx_isr(void) { //uart has received a character in UDR PutUartRx(UDR);//中数接收就OK!
} //============================================================================== //------------------------------------------------------------------------------ unsigned char a = 1; #pragma interrupt_handler uart0_tx_isr:14 void uart0_tx_isr(void) { //character has been transmitted UDR = a; //这样发送数据错在哪里?串口助手收不到数据,
} //==============================================================================
void main(void) { init_devices(); while(1) { //putchar(a);这样查询发数就没有问题 } }
请各位AVR高手帮忙,谢谢...
|