#include <avr/io.
h>
#include <avr/interrupt.h>
#include <stdlib.h>
#define F_CPU 16000000UL // AVR clock frequency in Hz
#define BAUD 9600 // Serial communication baud rate
#define UBRR_VAL (F_CPU / 16 / BAUD) - 1
volatile char received_data;
void USART_Init() {
// Set baud rate
UBRR0H = (UBRR_VAL >> 8);
UBRR0L = UBRR_VAL;
// Enable receiver and RX complete interrupt
UCSR0B = (1 << RXEN0) | (1 << RXCIE0);
// Set frame format: 8 data bits, 1 stop bit
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
void USART_SendChar(char data) {
// Wait for the transmit buffer to be empty
while (!(UCSR0A & (1 << UDRE0)));
// Put the data into the buffer and send it
UDR0 = data;
void LCD_Init() {
// Initialize LCD
// Implement your LCD initialization code here
void LCD_WriteChar(char data) {
// Write a character to the LCD
// Implement your LCD write character code here
int main() {
// Initialize USART and LCD
USART_Init();
LCD_Init();
// Enable global interrupts
sei();
while (1) {
// Display the received character on the LCD
LCD_WriteChar(received_data);
return 0;
// USART receive complete interrupt handler
ISR(USART_RX_vect) {
// Read the received data
received_data = UDR0;
// If you want to display the received character on LEDs connected to PORTB, uncomment the
following code
// PORTB = received_data;