// Lcd module connections
sbit LCD_RS at LATB4_bit;
sbit LCD_EN at LATB5_bit;
sbit LCD_D4 at LATB0_bit;
sbit LCD_D5 at LATB1_bit;
sbit LCD_D6 at LATB2_bit;
sbit LCD_D7 at LATB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
int select, select_op, selection, submenu;
void main()
{
Lcd_Init(); //LCD display initialization
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Cmd(_LCD_CURSOR_OFF); //Turn cursor Off for LCD
ANSELC = 0; //Configure PortC pins as digital
TRISC.B0 = 1; //Set RC0 pin as input - Selection
TRISC.B1 = 1; //Set RC1 pin as input - Choose selection
TRISC.B2 = 1; //Set RC2 pin as input - Back to Main menu
select = 1;
selection = 1;
submenu = 0;
select_op = 1;
//Display main menu
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 2,"Menu1");
Lcd_Out(2, 2,"Menu2");
Lcd_Out(1,10,"Menu3");
Lcd_Out(2,10,"Menu4");
while (1)
{
if ((PORTC.B0 = 1) && (submenu == 0)) //When press RC0 '>' selecting display options
{
switch(selection)
{
case 1:
Lcd_Chr(1,1,'>');
selection = 2;
select = 1;
Lcd_Chr(2,9,' ');
break;
case 2:
Lcd_Chr(2,1,'>');
selection = 3;
select = 2;
Lcd_Chr(1,1,' ');
break;
case 3:
Lcd_Chr(1,9,'>');
selection = 4;
select = 3;
Lcd_Chr(2,1,' ');
break;
case 4:
Lcd_Chr(2,9,'>');
selection = 1;
select = 4;
Lcd_Chr(1,9,' ');
break;
}
}
if (PORTC.B1 = 1) //When press RC1 - choose selected option/menu
{
switch(select)
{
case 1:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 1,"Menu 1");
Lcd_Out(1,10,"Option1");
Lcd_Out(2,10,"Option2");
submenu = 1;
break;
case 2:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 1,"Menu 2");
Lcd_Out(1,10,"Option1");
Lcd_Out(2,10,"Option2");
submenu = 1;
break;
case 3:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 1,"Menu 3");
Lcd_Out(1,10,"Option1");
Lcd_Out(2,10,"Option2");
submenu = 1;
break;
case 4:
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 1,"Menu 4");
Lcd_Out(1,10,"Option1");
Lcd_Out(2,10,"Option2");
submenu = 1;
break;
}
}
if ((PORTC.B0 = 1) && (submenu == 1))
{
switch(select_op)
{
case 1:
Lcd_Chr(1,9,'>');
select_op = 2;
Lcd_Chr(2,9,' ');
break;
case 2:
Lcd_Chr(2,9,'>');
select_op = 1;
Lcd_Chr(1,9,' ');
break;
}
}
//RETURN TO MAIN MENU IF RC2 is PRESSED
if (PORTC.B2 = 1)
{
Lcd_Cmd(_LCD_CLEAR); //Clear LCD screen
Lcd_Out(1, 2,"Menu1");
Lcd_Out(2, 2,"Menu2");
Lcd_Out(1,10,"Menu3");
Lcd_Out(2,10,"Menu4");
submenu = 0;
}
Delay_ms(300);
}
}