KL
Joined: 24 Feb 2004 Posts: 11
|
Problems initializing LCD with PIC24HJ |
Posted: Wed Apr 23, 2008 10:57 am |
|
|
I have code for controlling a character LCD with 4 data lines that I've been sucessfully using for years on PIC 16 and PIC 18 series.
I attempted to use it on with a PIC24HJ and cannot get the LCD initialized.
I suspect the problem has to do with the swapping / manipulation of the data. The code passes in (unsigned int). With the PIC24 and (int) is 16 bits. I attempted to change this to (unsigned short) but it still does not work.
Any input would be appreciated.
Here is my code.
Code: |
void LCD_init(void) //initializes LCD
{
int i;
output_low(LCD_D0);
output_low(LCD_D1);
output_low(LCD_D2);
output_low(LCD_D3);
delay_ms(300); //wait long enough for Vdd to rise
output_low (LCD_RS);
output_low (LCD_EN);
delay_ms(5);
LCD_setdata(0x03); //init with specific nibble to start 4 bit mode
for(i=0; i<3; i++)
PULSE_EN();
LCD_setdata(0x02);
PULSE_EN (); //send dual nibbles hereafter, MSN first
LCD_cmd (0x28); //function set (all lines, 5x7 characters)
LCD_cmd (0x0C); //display ON, cursor off, no blink
LCD_cmd (0x01); //clear display
LCD_cmd (0x06); //entry mode set, increment
}
void LCD_position (unsigned int cX)
{
LCD_setdata(swap (cX) | 0x08);
PULSE_EN ();
LCD_setdata(swap (cX));
PULSE_EN ();
}
void LCD_cmd (unsigned int cX)
{
LCD_setdata(swap (cX)); // send high nibble
PULSE_EN ();
LCD_setdata(swap (cX)); // send low nibble
PULSE_EN ();
}
void LCD_setdata (unsigned int cX)
{
output_bit (LCD_D0, cX & 0x01);
output_bit (LCD_D1, cX & 0x02);
output_bit (LCD_D2, cX & 0x04);
output_bit (LCD_D3, cX & 0x08);
}
void LCD_char (unsigned int cX)
{
output_high (LCD_RS);
LCD_setdata(swap (cX)); // send high nibble
PULSE_EN ();
LCD_setdata(swap (cX)); // send low nibble
PULSE_EN();
output_low (LCD_RS);
} |
|
|