The LCD won't display anything no matter what I try.
I am trying to display data to an LCD using a PIC24EP512GU810 microcontroller. I know the bits are set to the correct pins for the LCD data because I have gotten characters to show up before with the same config. However now the characters don't seem to be showing up at all. I tried messing with delays to see if the LCD just needed more time to display the data values. I tried manually moving the cursor, adjusting the initialization settings for the LCD, commenting out the timer (so it doesn't interrupt a write to the LCD), and more. I know it is making it through the char arrays sent to it and even setting the right bits to the LCD. I have done everything I can think of to make this work, so I was hoping I could get some advise. The LCD I am using is a Hacktronix HDM16216L-7, not to be confused with Hacktronics god knows I've made that mistake. I should mention the LCD does work as I have checked it with a different board I have, so that is not the issue.
LCD_manual: text LCD_DataSheet: text
const unsigned int tm10ms = 2;
const unsigned int tm20ms = 4;
const unsigned int tm25ms = 5;
const unsigned int tm50ms = 10;
const unsigned int tm100ms = 20;
const unsigned int tm200ms = 40;
const unsigned int tm500ms = 100;
const unsigned int tm1000ms = 200;
const unsigned int tm2000ms = 400;
const unsigned int tm5000ms = 1000;
const unsigned int tm1min = 12000;
const unsigned int tm5min = 60000;
const unsigned long tm10min = 120000;
unsigned int count5ms = 1;
unsigned int count = 0;
unsigned int ii = 0;
void SetLCDData(unsigned char chardata);
void LcdInit();
void LcdCmd(unsigned char cmd);
void LcdWrite(unsigned char *cmd);
unsigned char charData;
int countvar = 0;
void InitTimer1(){ //10ms
T1CON = 0x8020;
T1IE_bit = 1;
T1IF_bit = 0;
IPC0 = IPC0 | 0x1000;
PR1 = 10937;
}
void Timer1Interrupt() iv IVT_ADDR_T1INTERRUPT
{
T1IF_bit = 0;
count5ms = 1;
}
void LcdInit()
{
delay_ms(50);
AN_AvgValues[idxSigBusFLT] = 0; //corresponds to the R/W bit of the LCD
LcdCmd(0x38); //Set LCD Functionality
LcdCmd(0x0e); //LCD ON 1110 cursor on
LcdCmd(0x01); //clear the Display 0001
LcdCmd(0x06); //Entry Mode Set 0111 increment cursor no display shift
LcdCmd(0x80); //set the DD Ram address aka the location on the lcd which we will Display a character
}
void LcdCmd(unsigned char cmd)
{
LCD_RS = 0;
SetLCDData(cmd);
delay_ms(1);
}
void LcdWrite(unsigned char *cmd)
{
LCD_RS = 1;
ii = 0;
while (cmd[ii] != '~')
{
SetLCDData(cmd[ii]);
delay_ms(100);
LD_FAULT=~LD_FAULT;
ii++;
}
}
void SetLCDData(unsigned char charData)
{
AN_AvgValues[idxSigBusFLT] = 0; //represents the R/W signal always 0
LCD_D0 = charData.B0;
LCD_D1 = charData.B1;
LCD_D2 = charData.B2;
LCD_D3 = charData.B3;
LCD_D4 = charData.B4;
LCD_D5 = charData.B5;
LCD_D6 = charData.B6;
LCD_D7 = charData.B7;
LCD_EN = 1;
delay_ms(1);
LCD_EN = 0;
delay_ms(50);
}
void main() {
//PLL Config for 140MHz Fosc
//Fosc = Fin*(M/(N1*N2)) --> 140MHz = 8*(70/4)
PLLFBD = 68; // PLL multiplier M=70
CLKDIV = 0x0000; // PLL prescaler N1=2, PLL postscaler N2=2
//SET Analog bits and TRIS bits
LcdInit(); // Initialize The LCD
delay_ms(50);
LcdWrite("test~");
LcdCmd(0xc0);
LcdWrite("BadApple~");
//InitTimer1(); // Initialize Timer 1 for Period Interrupts
while(1)
{
/*if (count5ms == 1)
{
count5ms = 0;
count++;
if (count%tm1000ms == 0)
{
LcdWrite("Bad Apple~");
}
} */
}
}