?? uart.c
字號:
#include "uart.h"
uint8_t Tx_Data_Pos=0;
uint8_t Tx_Data_Len=0;
uint8_t Rx_Data_Pos=0;
uint8_t Rx_Data_Len=0;
uint8_t Send_Buf[16];
uint8_t Recv_Buf[16];
uint8_t Is_Recv_Complete(void)
{
return Rx_Data_Len==0;
}
uint8_t Is_Send_Complete(void)
{
return Tx_Data_Len==0;
}
void Uart_Init(uint16_t UART_BAUD)
{
UCSRA = _BV(U2X);
UCSRB = 0x00;
UBRRL = (F_CPU / (8UL * UART_BAUD)) - 1;
UCSRC = (3<<UCSZ0)| _BV(URSEL);
UCSRB = _BV(TXEN) | _BV(RXEN) |_BV(RXCIE) |_BV(TXCIE);
}
void Uart_Send(uint8_t len)
{
Tx_Data_Pos=0;
Tx_Data_Len=len;
UDR=Send_Buf[0];
while(Tx_Data_Len>0);
}
void Uart_Recv(uint8_t len)
{
Rx_Data_Pos=0;
Rx_Data_Len=len;
while(Rx_Data_Len>0);
}
SIGNAL(USART_TXC_vect)
{
if(--Tx_Data_Len>0)
UDR=Send_Buf[++Tx_Data_Pos];
}
SIGNAL(USART_RXC_vect)
{
uint8_t c=UDR;
if(Rx_Data_Len>0)
{
Recv_Buf[Rx_Data_Pos++]=c;
Rx_Data_Len--;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -