NHD-0108CZ-FL-GBW initialization code

Please tell me what is wrong with my initiazation code.

SYSTEM_Initialize();
Initialize_NHD();
Update_NHD(5, 5, 5);
while (1){}

void Initialize_NHD(){
LATCbits.LATC0 = 0; //Data Bit 0
LATCbits.LATC1 = 0; //Data Bit 1
LATCbits.LATC2 = 0; //Data Bit 2
LATCbits.LATC3 = 0; //Data Bit 3 Data = 0x00
LATCbits.LATC5 = 1; //E Enable - Falling Edge Triggered
LATCbits.LATC6 = 0; //R/W 1=Read 0=Write
LATCbits.LATC7 = 0; //RS 1=Data 0=Command
__delay_ms(100);

     LATCbits.LATC0 = 1; //Data Bit 0
     LATCbits.LATC1 = 1; //Data Bit 1 = 0x03 on port
     
     __delay_ms(30);
     LATCbits.LATC5 = 1; //E = 1
     __delay_ms(1);     //Nybble
     LATCbits.LATC5 = 0; //E = 0
     
     __delay_ms(10);
     LATCbits.LATC5 = 1; //E = 1
     __delay_ms(1);     //Nybble         
     LATCbits.LATC5 = 0; //E = 0         
     
     __delay_ms(10);
     LATCbits.LATC5 = 1; //E = 1
     __delay_ms(1);     //Nybble         
     LATCbits.LATC5 = 0; //E = 0
     
     __delay_ms(10);
     
     LATCbits.LATC0 = 0; //Data Bit 0
     LATCbits.LATC1 = 1; //Data Bit 1 = 0x02 on port

     LATCbits.LATC5 = 1; //E = 1
     __delay_ms(1);     //Nybble         
     LATCbits.LATC5 = 0; //E = 0            

     Command_NHD(0x28);  //4-bit Interface
     Command_NHD(0x10);  //Set Cursor
     Command_NHD(0x0F);  //Display ON, Cursor NOT Blinking
     Command_NHD(0x06);  //Entry Mode Set     

}

void Command_NHD(unsigned char data_uc){
__delay_ms(1); //Delay 1mS
LATCbits.LATC7 = 0; //RS = 0 = command
LATCbits.LATC6 = 0; //R/W = 0 = write
if((data_uc & 0x10) == 0x10) LATCbits.LATC0 = 1;
else LATCbits.LATC0 = 0;
if((data_uc & 0x20) == 0x20) LATCbits.LATC1 = 1;
else LATCbits.LATC1 = 0;
if((data_uc & 0x40) == 0x40) LATCbits.LATC2 = 1;
else LATCbits.LATC2 = 0;
if((data_uc & 0x80) == 0x80) LATCbits.LATC3 = 1;
else LATCbits.LATC3 = 0;
LATCbits.LATC5 = 1; //E = 1
__delay_ms(1); //Delay 1mS
LATCbits.LATC5 = 0; //E = 0
if((data_uc & 0x10) == 0x10) LATCbits.LATC0 = 1;
else LATCbits.LATC0 = 0;
if((data_uc & 0x20) == 0x20) LATCbits.LATC1 = 1;
else LATCbits.LATC1 = 0;
if((data_uc & 0x40) == 0x40) LATCbits.LATC2 = 1;
else LATCbits.LATC2 = 0;
if((data_uc & 0x80) == 0x80) LATCbits.LATC3 = 1;
else LATCbits.LATC3 = 0;
LATCbits.LATC5 = 1; //E = 1
__delay_ms(1); //Delay 1mS
LATCbits.LATC5 = 0; //E = 0
}

void Data_NHD(unsigned char data_uc){
__delay_ms(1); //Delay 1mS
LATCbits.LATC7 = 1; //RS = 1 = data
LATCbits.LATC6 = 0; //R/W = 0 = write
if((data_uc & 0x01) == 0x01) LATCbits.LATC0 = 1;
else LATCbits.LATC0 = 0;
if((data_uc & 0x02) == 0x02) LATCbits.LATC1 = 1;
else LATCbits.LATC1 = 0;
if((data_uc & 0x04) == 0x04) LATCbits.LATC2 = 1;
else LATCbits.LATC2 = 0;
if((data_uc & 0x08) == 0x08) LATCbits.LATC3 = 1;
else LATCbits.LATC3 = 0;
LATCbits.LATC5 = 1; //E = 1
__delay_ms(1); //Delay 1mS
LATCbits.LATC5 = 0; //E = 0
if((data_uc & 0x10) == 0x10) LATCbits.LATC0 = 1;
else LATCbits.LATC0 = 0;
if((data_uc & 0x20) == 0x20) LATCbits.LATC1 = 1;
else LATCbits.LATC1 = 0;
if((data_uc & 0x40) == 0x40) LATCbits.LATC2 = 1;
else LATCbits.LATC2 = 0;
if((data_uc & 0x80) == 0x80) LATCbits.LATC3 = 1;
else LATCbits.LATC3 = 0;
LATCbits.LATC5 = 1; //E = 0
__delay_ms(1); //Delay 1mS
LATCbits.LATC5 = 0; //E = 1
}

void Update_NHD(unsigned char Digit_1_uc,
unsigned char Digit_2_uc,
unsigned char Digit_3_uc){
// Command_NHD((unsigned char)(0x18)); //Set pointer to right shifting left
// Data_NHD((unsigned char)(Digit_1_uc | 0x30));
// Data_NHD((unsigned char)(Digit_2_uc | 0x30));
// Data_NHD((unsigned char)(Digit_3_uc | 0x30));
Data_NHD(0x30);
Data_NHD(0x31);
Data_NHD(0x32);
Data_NHD(0x33);
Data_NHD(0x34);
Data_NHD(0x35);
Data_NHD(0x36);
Data_NHD(0x37);
Data_NHD(0x38);

// Command_NHD(24);
// Data_NHD(52);
}

I’m guessing it’s because you’re not shifting the input in your Command_NHD function. It only ever looks at the upper 4 bits.

The bit order in Data_NHD is also incorrect. It should always be the upper 4 bits that get sent first.

And just a suggestion: Shifting and masking the input byte instead of using if/else for the Data and Command functions would help make them more readable.

This,

LATC = (data_uc >> 4) & 0x0F;
Nybble();
LATC = data_uc & 0x0F;
Nybble();

is a lot easier to understand than

if((data_uc & 0x01) == 0x01) LATCbits.LATC0 = 1;
else LATCbits.LATC0 = 0;
if((data_uc & 0x02) == 0x02) LATCbits.LATC1 = 1;
else LATCbits.LATC1 = 0;
if((data_uc & 0x04) == 0x04) LATCbits.LATC2 = 1;
else LATCbits.LATC2 = 0;
if((data_uc & 0x08) == 0x08) LATCbits.LATC3 = 1;
else LATCbits.LATC3 = 0;
LATCbits.LATC5 = 1; //E = 1
__delay_ms(1); //Delay 1mS
LATCbits.LATC5 = 0; //E = 0
if((data_uc & 0x10) == 0x10) LATCbits.LATC0 = 1;
else LATCbits.LATC0 = 0;
if((data_uc & 0x20) == 0x20) LATCbits.LATC1 = 1;
else LATCbits.LATC1 = 0;
if((data_uc & 0x40) == 0x40) LATCbits.LATC2 = 1;
else LATCbits.LATC2 = 0;
if((data_uc & 0x80) == 0x80) LATCbits.LATC3 = 1;
else LATCbits.LATC3 = 0;
LATCbits.LATC5 = 1; //E = 0
__delay_ms(1); //Delay 1mS
LATCbits.LATC5 = 0; //E = 1