Coding
[syntax=c]// LCD module connections
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections
void main()
{
TRISA.F0 = 1; //PortA bit 1 input
TRISD.F0 = 0; //Port D pada bit 0,1,2 output
while (1)
{
if(PORTA.F0 == 0) //If the switch is pressed
{
Delay_ms(1000); //Switch Debounce
PORTD.F0 = 0; //LED port 0 ON
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"FULL ");
}
else
{
Delay_ms(1000); //Switch Debounce
PORTD.F0 = 1; //LED port 0 ON
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"AVAILABLE 2");
} // Write text'Hello World' in first row
}
}[/syntax]