// LCD module connections
sbit LCD_RS at RC4_bit;
sbit LCD_EN at RC5_bit;
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
// End LCD module connections
// Back Light Switch connected to RA1
sbit BackLight at RA1_bit;
// Define Messages
char message0[] = "LCD Initialized";
char message1[] = "Shahbaz Khan";
char message2[] = "RA4";
char message3[] = "RA5";
char message4[] = " SCANING... ";
// ISR for LCD Backlight
void interrupt(void){
if (INTCON.RAIF == 1) // Check if INTF flag is set
{
if (RA4 == 1)
{
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
//BackLight = 1;
Lcd_Out(1,1,message2);
Delay_ms(5);
}
else if (RA5 == 1)
{
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
//BackLight = 1;
Lcd_Out(1,1,message3);
Delay_ms(5);
}
else
{
//Lcd_Cmd(_LCD_CLEAR); // CLEAR display
//BackLight = 1;
//Lcd_Out(1,1,message4);
//Delay_ms(3);
}//Delay_ms(10) ;
INTCON.RAIF = 0; // Clear interrupt flag before exiting ISR
}
}
void main() {
TRISC = 0x00 ;
TRISA = 0b00111100; // RA2, RA3, RA4, RA5 Inputs, Rest O/P's
ANSEL = 0b00000000;
PORTA = 0b00000000; // Start with Everything Low
PORTC = 0b00000000; // Start with Everything Low
CMCON0 = 0b00000111;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
BackLight = 1;
Lcd_Out(1,1,message0);
Delay_ms(5);
Lcd_Cmd(_LCD_CLEAR); // CLEAR display
Lcd_Out(1,1,message1); // Write message1 in 1st row
// Interrupt Setup
//IOCA4 = 1; //Input Change Enable RA4
//IOCA5 = 1; //Input Change Enable RA5
IOCA = 0x30;
INTCON.RAIF = 0; // Clear interrupt flag prior to enable
INTCON.RAIE = 1; // enable Input Change interrupt
//INTCON.INTF = 0; // Clear interrupt flag prior to enable
//INTCON.INTE = 1; // enable INT interrupt
INTCON.GIE = 1; // enable Global interrupts
do {
} while(1);
}