CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problems initializing LCD with PIC24HJ

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
KL



Joined: 24 Feb 2004
Posts: 11

View user's profile Send private message

Problems initializing LCD with PIC24HJ
PostPosted: Wed Apr 23, 2008 10:57 am     Reply with quote

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);
}
mkent



Joined: 09 Sep 2003
Posts: 37
Location: TN, USA

View user's profile Send private message

PostPosted: Wed Apr 23, 2008 11:48 am     Reply with quote

Some LCD's need a pull-up resistor on the enable line. (Optrex).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group