- //UART1 initialize
- // desired baud rate:9600
- // actual baud rate:9615 (0.2%)
- // char size: 8 bit
- // parity: Disabled
- void uart1_init(void)
- {
- UCSR1B = 0x00; //disable while setting baud rate
- UCSR1A = 0x00;
- UCSR1C = 0x06;
- UBRR1L = 0x33; //set baud rate lo
- UBRR1H = 0x00; //set baud rate hi
- UCSR1B = 0x98;
- Rx_485_on;
- }
- #pragma interrupt_handler uart1_rx_isr:31
- void uart1_rx_isr(void)
- {
- //uart has received a character in UDR
- Usart1_RX_Buff = UDR1 ;
- if (Usart1_RX_Buff=='1')
- {
- Usart0_num = (Usart0_num + 1)%2;
- if(Usart0_num==1)
- {
- Led_on;
- }
- else
- {
- Led_off;
- }
- }
- }
- void USART1_Transmit(uchar data)
- {
- //UCSR1B = 0x90;
- Tx_485_on;
- delay(20);
- //UCSR1B = 0x98;
- //等待数据寄存器为空
- while ( !( UCSR1A & (1<<UDRE1)))
- ;
- //数据放入缓存器
- UDR1 = data;
- //UCSR1B = 0x88;
- Rx_485_on;
- delay(20);
- //UCSR1B = 0x98;
- }
错误率很高,请问是什么问题?
|