View previous topic :: View next topic |
Author |
Message |
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
dsPIC LCD problem |
Posted: Wed Dec 23, 2009 12:06 am |
|
|
Dear CCS fanatics,
I have a problem with this simple LCD driver code which i like for it's flexibility and simplicity.
Code: |
void LCD_Init ( void )
{
LCD_SetData ( 0x00 );
delay_ms ( 200 ); /* wait enough time after Vdd rise */
output_low ( LCD_RS );
LCD_SetData ( 0x03 ); /* init with specific nibbles to start 4-bit mode */
LCD_PulseEnable();
LCD_PulseEnable();
LCD_PulseEnable();
LCD_SetData ( 0x02 ); /* set 4-bit interface */
LCD_PulseEnable(); /* send dual nibbles hereafter, MSN first */
LCD_PutCmd ( 0x2C ); /* function set (all lines, 5x7 characters) */
LCD_PutCmd ( 0x0C ); /* display ON, cursor off, no blink */
LCD_PutCmd ( 0x01 ); /* clear display */
LCD_PutCmd ( 0x06 ); /* entry mode set, increment & scroll left */
}
void LCD_SetPosition ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
LCD_SetData ( cX>>4 | 0x08 );
LCD_PulseEnable();
LCD_SetData ( cX );
LCD_PulseEnable();
}
void LCD_PutChar ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
// if ( !cSkip )
// {
output_high ( LCD_RS );
LCD_SetData ( cX>>4 ); /* send high nibble */
LCD_PulseEnable();
LCD_SetData ( cX ); /* send low nibble */
LCD_PulseEnable();
output_low ( LCD_RS );
// }
}
void LCD_PutCmd ( unsigned int cX )
{
/* this subroutine works specifically for 4-bit Port A */
LCD_SetData ( cX>>4 ); /* send high nibble */
LCD_PulseEnable();
LCD_SetData ( cX ); /* send low nibble */
LCD_PulseEnable();
}
void LCD_PulseEnable ( void )
{
output_high ( LCD_EN );
delay_us ( 10 ); // was 10
output_low ( LCD_EN );
delay_us ( 5 ); // was 5
}
void LCD_SetData ( unsigned int cX )
{
output_bit ( LCD_D4, cX & 0x01 );
output_bit ( LCD_D5, cX & 0x02 );
output_bit ( LCD_D6, cX & 0x04 );
output_bit ( LCD_D7, cX & 0x08 );
}
|
The problem is that the dsPIC ports are 16-bit wide.
Do you have a clue to get this driver to work on this microcontroller.
By the way this is my test code:
Code: |
void main()
{
SETUP_ADC_PORTS(0);
LCD_Init();
printf(LCD_PutChar,"1234567890");
while(true){
}
}
|
so instead of giving 1234567890 on the lcd it give : #46s9 or 3C6s9 or #C6s or 35c80 or 3Cc8 (similar pattern)... at each start-up it's a different output from the list i gave you.
Could it be because of the port wider than the usual and all the driver using 8-bit shifting ? I've a little difficulty understanding the nibble thing.
Have a nice day and thank you for the support
Best Regards,
Laurent
EDIT: SPECS
dsPIC30F4013
PCWHD 4.101
4x20 LCD 4-bit mode |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Thu Dec 24, 2009 3:39 am |
|
|
Laurent:
The code looks ok. What are your pin definitions? Which port have you connected the LCD to?
Another option would be to try the FlexLCD 20x4 driver, which you will find here http://www.ccsinfo.com/forum/viewtopic.php?t=28268
Rohit |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Dec 24, 2009 7:24 am |
|
|
Quote: | The code looks ok. | I don't think so. It doesn't observe the delay required with various LCD actions. Even the simple LCD_PutChar() is possibly too fast with a dsPIC (you didn't tell the clock settings). You better use a tested driver code. Checking the controllers's busy state is generally more easy than considering the timing requirements of individual LCD commands, I think. |
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Thu Dec 24, 2009 1:01 pm |
|
|
Quote: | What are your pin definitions? Which port have you connected the LCD to? |
Code: |
#define LCD_D4 PIN_B4
#define LCD_D5 PIN_B5
#define LCD_D6 PIN_B6
#define LCD_D7 PIN_B7
#define LCD_EN PIN_B0
#define LCD_RS PIN_B1
|
Quote: | Even the simple LCD_PutChar() is possibly too fast with a dsPIC (you didn't tell the clock settings). |
The dsPIC is running with the internal osc at 117.92mhz.
I've tried the flex lcd code and it's working like a charm. What is strange that both driver behave the same way (no busy flag check, I've grounded the READ/WRITE pin on the lcd). I wonder where is the bug in this code.
Thank you for your help and merry Christmas !
Best Regards,
Laurent |
|
|
Rohit de Sa
Joined: 09 Nov 2007 Posts: 282 Location: India
|
|
Posted: Thu Dec 24, 2009 3:09 pm |
|
|
ELCouz wrote: | I wonder where is the bug in this code. | Like FvM mentioned, lack of appropriate delays may be the cause. On my run through of the code I didn't notice the missing delays
Oh, and Merry Christmas!
Rohit |
|
|
|