HI

i want to interface PIC24F16KA102 AND LCM-S01602DTR M.

The code runs on proteus simulation but not on hardware.

i want to use port b for 8 bit data and control pins. what is the correct way of writing data and control signals on same 16 bit port.

////////////////////////////////main.c//////////////////////////////////////
#include <24F16KA102.h>
#include
#include
#FUSES WPOSTS1, frc , NOBROWNOUT
#use delay(clock=1000000)
//#use rs232(UART2,baud=1200,parity=N,bits=8)
//#use rs232(baud=1200, xmit=PIN_b0,rcv=PIN_b1)

void WriteCommandToLCD(unsigned char);
void WriteDataToLCD(char);
void InitLCD(void);
void ClearLCDScreen(void);
//void WriteStringToLCD(const char*);

char k= 0x00;


void main()
{



InitLCD(); // Initialize LCD in 8bit mode
ClearLCDScreen();


while(1)

{


//delay_ms(100);
ClearLCDScreen();
delay_ms(100);
WriteDataToLCD('t');
WriteDataToLCD('e');
WriteDataToLCD('m');
WriteDataToLCD('p');
WriteDataToLCD('=');
WriteDataToLCD(k);
delay_ms(500);


}


}


//////////////////////lcd.h///////////////////


#FUSES WPOSTS1, frc , NOBROWNOUT

#use delay(clock=1000000)

// Define Pins
#bit LCD_E = 0x02CA.7 // Enable pin for LCD
#bit LCD_RS = 0x02CA.6 // RS pin for LCD
//#byte PORTB = 0x02CA // Data bus bit 4
#byte TRISB = 0x02C8
#byte PORTB = 0x02CA
#byte LATB = 0x02CC
#byte ODCB = 0x02CE

// Define Pins direction registrers

#bit LCD_E_Dir = 0x02C8.7
#bit LCD_RS_Dir = 0x02C8.6

#bit LCD_RS_d0 = 0x02C8.10
#bit LCD_RS_d1 = 0x02C8.10
#bit LCD_RS_d2 = 0x02C8.10
#bit LCD_RS_d3 = 0x02C8.11
#bit LCD_RS_d4 = 0x02C8.12
#bit LCD_RS_d5 = 0x02C8.13
#bit LCD_RS_d6 = 0x02C8.14
#bit LCD_RS_d7 = 0x02C8.15

#byte PORT_B_L=getenv("SFR:PORTB")
#byte PORT_B_H=PORT_B_L+1




unsigned char data;
//long long data;
int16 test;

//int8 addr = 0x33;
//int8 data = 0x22;

void ToggleEpinOfLCD(void)
{
output_bit (PIN_B7 , 1); // Give a pulse on E pin
delay_us(500); // so that LCD can latch the
output_bit (PIN_B7 , 0); // data from data bus
delay_us(500);
}



void WriteCommandToLCD(unsigned char Command)
{
int temp =command;
output_bit (PIN_B6 , 0); // It is a command
temp=(temp<<8);
output_b(temp );

ToggleEpinOfLCD();
}

void WriteDataToLCD(char LCDChar)
{
int temp =LCDChar;
output_bit (PIN_B6 , 1);
temp=(temp<<8);
output_b(temp | 0x40); // making output_bit (PIN_B6 , 1);
ToggleEpinOfLCD();


}

void InitLCD(void)
{
output_bit (PIN_B6 , 0); // E = 0
output_bit (PIN_B7 , 0); // D = 0
output_b(0x0000);


///////////////// Reset process from datasheet //////////////
delay_ms(40);
WriteCommandToLCD(0x30);

delay_ms(6);
WriteCommandToLCD(0x30);

delay_us(300);
WriteCommandToLCD(0x30);

delay_ms(2);
/////////////////////////////////////////////////////

WriteCommandToLCD(0x38); //function set
WriteCommandToLCD(0x0c); //display on,cursor off,blink off
WriteCommandToLCD(0x01); //clear display
WriteCommandToLCD(0x06); //entry mode, set increment
}






void ClearLCDScreen(void)
{
WriteCommandToLCD(0x01); // Clear the screen
delay_ms(2); // Delay for cursor to return at zero position
}


void WriteStringToLCD( char *s)
{
while(*s)
WriteDataToLCD(*s++); // print first character on LCD
}