#include "uart.h"
int main()
{
UART_Init(9600); // Initialize UARt at 9600 baud rate
while(1)
{
UART_TxChar('e');
}
return (0);
}
ch = UART_RxChar();
LCD_DisplayChar(ch);
char ch;
void UART_Init(uint32_t v_baudRate_u32)
{
UCSRB= (1<<RXEN) | (1<<TXEN); // Enable Receiver and Transmitter
UCSRC= (1<<URSEL) | (1<<UCSZ1) | (1<<UCSZ0); // Asynchronous mode 8-bit data and 1-stop bit
UCSRA= 0x00; // Clear the UASRT status register
UART_SetBaudRate(v_baudRate_u32);
}
void UART_SetBaudRate(uint32_t v_baudRate_u32)
{
uint16_t RegValue;
if((v_baudRate_u32 >= C_MinBaudRate_U32) && (v_baudRate_u32<=C_MaxBaudRate_U32))
{
/* Check if the requested baudate is within range,
If yes then calculate the value to be loaded into baud rate generator. */
RegValue = M_GetBaudRateGeneratorValue(v_baudRate_u32);
}
else
{
/* Invalid baudrate requested, hence set it to default baudrate of 9600 */
RegValue = M_GetBaudRateGeneratorValue(9600);
}
UBRRL = util_ExtractByte0to8(RegValue);
UBRRH = util_ExtractByte8to16(RegValue);
}
char UART_RxChar(void)
{
while(util_IsBitCleared(UCSRA,RXC)); // Wait till the data is received
return(UDR); // return the received char
}
void UART_TxChar(char v_uartData_u8)
{
while(util_IsBitCleared(UCSRA,UDRE)); // Wait till Transmitter(UDR) register becomes Empty
UDR =v_uartData_u8; // Load the data to be transmitted
}