///////////////////////////////////////////////////////////////////////////
//// LCD.C ////
//// Driver for common LCD modules ////
//// ////
//// lcd_init() Must be called before any other function. ////
//// ////
//// lcd_putc(c) Will display c on the next position of the LCD. ////
//// The following have special meaning: ////
//// \f Clear display ////
//// \n Go to start of second line ////
//// \b Move back one position ////
//// ////
//// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1) ////
//// ////
//// ////
///////////////////////////////////////////////////////////////////////////
#define RS PIN_C0
#define RD_WRT PIN_C1
#define ENABLE PIN_C2
#BYTE PORTC=0x7 // C4,C5,C6,C7
#define LCD_ROW_1 1
#define LCD_ROW_2 2
#define LCD_LINE_TWO 0x40 // LCD RAM address for the second line
BYTE const LCD_INIT_STRING[4] = {0x28, 0xc, 1, 6}; //const = Data is read-only. Depending on compiler configuration,
// this qualifier may just make the data read-only -AND/OR- it may place the data
// into program memory to save space. (see #DEVICE const=)
// These bytes need to be sent to the LCD
// to start it up.
extern unsigned char dispbuf[16];
const unsigned char welcome_mess_1[17] = {" Hi Prabhu "};
const unsigned char welcome_mess_2[17] = {"Welcome toindia "};
void lcddisplay(int8);
void lcd_send_nibble( BYTE n )
{
PORTC = (PORTC & 0x0f) | (n<<4);
delay_cycles(1);
output_high(enable);
delay_us(2);
output_low(enable);
delay_ms(2);
}
void lcd_send_byte( BYTE address, BYTE n )
{
output_low(rs);
delay_cycles(3);//added
delay_us(1);//added
if ( address & 0x01)
output_high(rs);
else
output_low(rs);
delay_cycles(1);
delay_cycles(1);
output_low(enable);
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
void lcd_init(void)
{
int8 i=0;
set_tris_c(0x00);
delay_ms(15);
output_low(RD_WRT);
output_low(rs);
output_low(enable);
lcd_send_nibble(3); // send 8 bit long
delay_ms(5);
lcd_send_nibble(3); // send 8 bit long
delay_ms(1);
lcd_send_nibble(3); // send 8 bit long
delay_ms(1);
lcd_send_nibble(2);
for(i=0;i<=3;++i)
lcd_send_byte(0,LCD_INIT_STRING[i]);
}
void lcd_gotoxy( BYTE x, BYTE y)
{
BYTE address;
if(y!=1)
address=LCD_LINE_TWO;
else
address=0;
address+=x-1;
lcd_send_byte(0,0x80|address);
}
void lcd_putc( char c)
{
switch (c)
{
case '\f' : lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n' : lcd_gotoxy(1,2);
break;
case '\b' : lcd_send_byte(0,0x10);
break;
default : lcd_send_byte(1,c);
break;
}
}
//////////////////// ADDED ///////////////////
// This is the welcome message shown to LCD display
// when the power is coming up
void shwmess(void)
{
BYTE i;
for(i=0;i<=15;i++)
dispbuf[i]=welcome_mess_1[i];
lcddisplay(LCD_ROW_1);
for(i=0;i<=15;i++)
dispbuf[i]=welcome_mess_2[i];
lcddisplay(LCD_ROW_2);
}
// write the dispbuf data to LCD display
// based on the row number passed to function
void lcddisplay(int8 row_no)
{
BYTE i=0;
if(row_no == LCD_ROW_1)
lcd_gotoxy(1,1);
else
lcd_gotoxy(1,2);
for(i=0;i<=15;i++)
lcd_putc(dispbuf[i]);
}