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

dsPIC LCD problem

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



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

dsPIC LCD problem
PostPosted: Wed Dec 23, 2009 12:06 am     Reply with quote

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 Smile

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

View user's profile Send private message Visit poster's website

PostPosted: Thu Dec 24, 2009 3:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Dec 24, 2009 7:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Dec 24, 2009 1:01 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Thu Dec 24, 2009 3:09 pm     Reply with quote

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 Embarassed

Oh, and Merry Christmas! Very Happy
Rohit
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