EmbeddedRelated.com
Forums

4bit LCD C code

Started by cbhargava March 5, 2011
cbhargava wrote:
> Some time ago I wrote a library for 8051. I might as well port it.
>

I'm curious. Why not use the code I posted? I even used defines so you
can move the port and control pins around pretty easily. If you are not
using gcc for the short_pause, that is the only thing you have to come
up with.

Best, Dan.

Beginning Microcontrollers with the MSP430

Thanks,

I will definitely try out the posted code. I had to re-do the brief_pause routine to compile it correctly.

My 8051 code is berried in my CVS tree that I need to import into my current git setup.

Regards,

Chetan

--- In m..., Dan Bloomquist wrote:
>
> cbhargava wrote:
> > Some time ago I wrote a library for 8051. I might as well port it.
> >
>
> I'm curious. Why not use the code I posted? I even used defines so you
> can move the port and control pins around pretty easily. If you are not
> using gcc for the short_pause, that is the only thing you have to come
> up with.
>
> Best, Dan.
>

Posted here:
https://github.com/microwiz/msp430-lcd4bit/

--- In m..., Dan Bloomquist wrote:
>
> cbhargava wrote:
> > Some time ago I wrote a library for 8051. I might as well port it.
> >
>
> I'm curious. Why not use the code I posted? I even used defines so you
> can move the port and control pins around pretty easily. If you are not
> using gcc for the short_pause, that is the only thing you have to come
> up with.
>
> Best, Dan.
>

Hi Dan,

I added the schematic to the code. Function putchar was conflicting with in built function so renamed it.

Can you please verify for correctness?

https://github.com/microwiz/msp430-lcd4bit

Thanks.

Chetan

--- In m..., "cbhargava" wrote:
>
> Posted here:
> https://github.com/microwiz/msp430-lcd4bit/
>
> --- In m..., Dan Bloomquist wrote:
> >
> > cbhargava wrote:
> > > Some time ago I wrote a library for 8051. I might as well port it.
> > >
> >
> > I'm curious. Why not use the code I posted? I even used defines so you
> > can move the port and control pins around pretty easily. If you are not
> > using gcc for the short_pause, that is the only thing you have to come
> > up with.
> >
> > Best, Dan.
>

cbhargava wrote:
> Hi Dan,
>
> I added the schematic to the code. Function putchar was conflicting with in built function so renamed it.
>
> Can you please verify for correctness?
>
> https://github.com/microwiz/msp430-lcd4bit
>
> Thanks.
>
> Chetan
>

Hi Chetan,
Thanks for posting. In my case putchar was intended as I used printf to
write the LCD. I'm not sure what you use, why the 'conflict', as putchar
needs to be declared/defined by the user for the higher level standard
library to work, in my case,(gcc). If you have a conflict you have
included some other intended output device in your libs link and need to
eliminate that if you want to use the likes of printf for the lcd. Check
for another putchar, maybe for your uart. But as far as I know, IAR and
CCS don't define this out of the box. Which development system are you
using?

Best, Dan.

> --- In m..., "cbhargava" wrote:
>
>> Posted here:
>> https://github.com/microwiz/msp430-lcd4bit/
>>
>> --- In m..., Dan Bloomquist wrote:
>>
>>> cbhargava wrote:
>>>
>>>> Some time ago I wrote a library for 8051. I might as well port it.
>>>>
>>>>
>>> I'm curious. Why not use the code I posted? I even used defines so you
>>> can move the port and control pins around pretty easily. If you are not
>>> using gcc for the short_pause, that is the only thing you have to come
>>> up with.
>>>
>>> Best, Dan.
>>>
>>>
>>
>
>
Hi Dan,

putchar is found in standard C library and therefore it might have been conflicting (http://en.wikipedia.org/wiki/Putchar). Here is what I got if I change lcd_putchar to putchar:

main.c:52: warning: conflicting types for built-in function `putchar'

Were you able to check the schematic that I added in code body.

Regards,
-Chetan

--- In m..., Dan Bloomquist wrote:
>
> Hi Chetan,
> Thanks for posting. In my case putchar was intended as I used printf to
> write the LCD. I'm not sure what you use, why the 'conflict', as putchar
> needs to be declared/defined by the user for the higher level standard
> library to work, in my case,(gcc). If you have a conflict you have
> included some other intended output device in your libs link and need to
> eliminate that if you want to use the likes of printf for the lcd. Check
> for another putchar, maybe for your uart. But as far as I know, IAR and
> CCS don't define this out of the box. Which development system are you
> using?
>
> Best, Dan.
>
> cbhargava wrote:
> > Hi Dan,
> >
> > I added the schematic to the code. Function putchar was conflicting with in built function so renamed it.
> >
> > Can you please verify for correctness?
> >
> > https://github.com/microwiz/msp430-lcd4bit
> >
> > Thanks.
> >
> > Chetan
> >
>

function putchar is defined in stdio.h:

int putchar(int c); //has to be supplied by the user, but avoids useless warnings

I think that I got the warning because the type declaration differs void vs int.

-Chetan

cbhargava wrote:
> Hi Dan,
>
> putchar is found in standard C library and therefore it might have been conflicting (http://en.wikipedia.org/wiki/Putchar). Here is what I got if I change lcd_putchar to putchar:
>
> main.c:52: warning: conflicting types for built-in function `putchar'
>
> Were you able to check the schematic that I added in code body.
>

Hi Chetan,
No, I did not see a schematic link. 'confilcting types' says that your
library has a different 'decleration', not that it is defined. Decleare
it apropreatly, maybe 'int putchar(...), I can't know from here, you
have not said what compieler you are using; please say. And I may have
posted wrong, find your deceleration and clean it up from there. That is
if you want to use the likes of printf...

Best, Dan.

cbhargava wrote:
> function putchar is defined in stdio.h:
>
> int putchar(int c); //has to be supplied by the user, but avoids useless warnings
>
> I think that I got the warning because the type declaration differs void vs int.
>
> -Chetan
>
>
There we go!!

Best, Dan.

/*
4bit LCD drive code posted by Dan Bloomquist on MSP430 Yahoo Group.
Modified by Chetan BhargavaCompiler: MSPGCC4Testbed: TI Launchpad
MSP430G22xx HD44780 LCD -----------------
---------------- | | |
| | |-------|GND | |
|-------|DB0 | | |-------|DB1 |
| |-------|DB2 | | |-------|DB3
| | |-------|RW | | V
| | | | |
P1.0|------------|DB4 | P1.1|------------|DB5
| P1.2|------------|DB6 |
P1.3|------------|DB7 | | |
| P1.3|------------|EN |
P1.1|------------|RS | | |
Original code uses RW line of the LCD but as we will only write to the
LCD it might not be needed.
*/
I embedded the schematic in the header.

> No, I did not see a schematic link. 'confilcting types' says that your