friend i am now replying you through my mobile. I cant give you full code for your need. But now i can give you my final LCD program . (copy in my mobile). Try this working code...Its 100%working.
/////////////////////////////////////////////////////////
//16x2 LCD with PIC16F877A ///
//RS= RC4 R/W=ground ///
//EN=RC5 ///
//DATA=PORTB ( LOWER 4 BITS ) ///
//connect RB0 to D4, RB1 to D5, .....RB3 to D7 of LCD ///
/////////////////////////////////////////////////////////
#include <htc.h>
#define _XTAL_FREQ 20e6 // 20MHz
__CONFIG(0x3F3A);
#define RS RC4 #define EN RC5
///////////////////////////////////////////////////////////////////
void LCD_STROBE(void)
{
EN = 1;
__delay_us(0.5); EN = 0;
}
////////////////////////////////////////////////////////////////////
void data(unsigned char c)
{ RS=1;
__delay_us(40); PORTB = ( c >> 4 );LCD_STROBE();
PORTB = ( c );LCD_STROBE(); }
//////////////////////////////////////////////////////////////////
void cmd(unsigned char c)
{ RS=0;
__delay_us(40); PORTB = ( c >> 4 );LCD_STROBE();
__delay_ms(2);
PORTB = ( c );LCD_STROBE();
__delay_ms(2);
}
///////////////////////////////////////////////////////////////// void clear(void)
{ cmd(0x1);
__delay_ms(2);
}
/////////////////////////////////////////////////////////////////
void lcd_init()
{ __delay_ms(20);
cmd(0x03);
__delay_us(200);
cmd(0x03);
__delay_us(200);
cmd(0x03); cmd(0x28 ); // Function set (4-bit
interface, 2 lines, 5*7 Pixels)
cmd(0x0c); // Make cursor invisible
clear(); // Clear screen
cmd(0x6); // Set entry Mode
} ////////////////////////////////////////////////////////////////
void string(const char *q)
{
while(*q)
data(*q++);
} /////////////////////////////////////////////////////////////////
void main()
{__delay_ms(100);
PORTB=0;PORTC=0;TRISB=0;
TRISC=0b11001111;
__delay_ms(15); lcd_init();
////////////////////////////////////////////////////////////////
cmd(0x82);//simply to start display
from 3rd column of first row//
//first row start address is 0x80 and
second row is 0xC0// string("HELLO WORLD");
cmd(0xC0); //NEXT LINE START
ADDRESS//
string("LCD 4-BIT MODE"); ////////////////////////////////////////////////////////////////
while(1);
////////////////////////////////////////////////////////////////
}
---------- Post added at 19:48 ---------- Previous post was at 19:45 ----------
but i think the delay function will work only in hightech c professional version...If you have only the light version then you need to use some good working delay routines...Will get it from google search...