Example output
#include <avr/io.h>
#include <util/delay.h>
#define LCD_DATA_PORT PORTB // Data port of the LCD
#define LCD_CTRL_PORT PORTD // Control port of the LCD
#define LCD_RS PD0 // Register Select pin of the LCD
#define LCD_EN PD1 // Enable pin of the LCD
// Main function
int main()
{
// Initialize LCD
lcd_init();
// Display menu options
lcd_cmd(0x80); // Set cursor to first line, first column
lcd_write_string("1. Option 1"); // Option 1
lcd_cmd(0xC0); // Set cursor to second line, first column
lcd_write_string("2. Option 2"); // Option 2
lcd_cmd(0x94); // Set cursor to third line, first column
lcd_write_string("3. Option 3"); // Option 3
// Wait for button press to enter menu
while (!(PIND & (1<<PD2))); // Wait for button press on PD2
// Enter menu loop
int option = 1;
while (1)
{
// Display selected option
lcd_cmd(0x80); // Set cursor to first line, first column
if (option == 1)
{
lcd_write_string(">1. Option 1");
}
else
{
lcd_write_string(" 1. Option 1");
}
lcd_cmd(0xC0); // Set cursor to second line, first column
if (option == 2)
{
lcd_write_string(">2. Option 2");
}
else
{
lcd_write_string(" 2. Option 2");
}
lcd_cmd(0x94);