Hi Arash,
I don't fully understand your problem, more description is needed. Anyway, here is my sample code that I succesfully implemented using Hi-Tech PICC 8.05 PL2. The configuration is as follows:
MCU: PIC16F877A
RD0-RD3: LCD DB4-DB7 (LCD in 4-bit mode)
RD5: LCD RS
RD6: LCD R/W
RD7: LCD EN
Fragments of my code:
/* LCD bit definition */
static bit LCD_RS @ ((unsigned) &PORTD * 8 + 5); // Register select
static bit LCD_RW @ ((unsigned) &PORTD * 8 + 6); // Read / Write
static bit LCD_EN @ ((unsigned) &PORTD * 8 + 7); // Enable
/* MCU init sequence */
TRISD = 0b00010000; // LCD data port init
DelayMs(100);
PORTD = 0x00;
DelayMs(100);
/* LCD init sequence */
LCD_RW = 0; // write to LCD mode
LCD_EN = 0;
LCD_RS = 0; // write control bytes
DelayMs(30); // power on delay
PORTD = 0x3; // Write LCD mode
lcd_strobe();
DelayMs(5);
lcd_strobe();
DelayUs(100);
lcd_strobe();
DelayMs(5);
PORTD = 0x2; // Set 4-bit mode
lcd_strobe();
DelayUs(40);
lcd_write(0x28); // Function Set - 4 bit mode, 1/16 duty, 5x8 font
lcd_write(0x08); // display off
/* Display Control => 00001DCB: D - Display ON/IFF, C - Cursor ON/OFF, B - Blink Cursor ON/OFF */
lcd_write(0b00001100); // display on, blink curson on
lcd_write(0x06); // entry mode
This code is working just fine for me. It should work properly if you change the code to accept port B.
Good luck.