[En-Nut-Discussion] Ethernut + LCD

0 views
Skip to first unread message

José Vallet

unread,
Mar 22, 2007, 9:58:14 AM3/22/07
to Ethernut mail list
Hello.

I am trying to add a 4x16 LCD to my Ethernut 2. I am using NutOS 4.2.1

I found a document (Ethernut application note 001) that describes a
simple add-on board and the internals of some drivers. However it does
not explain how to write code using the drivers already included in the
NutOS.

I guess that the very basic process is more or less like follows
(PLEASE, correct me!)

1-Recompile the NutOS libraries including the LCD drivers (form the
nutconf).
2-Add the #include <dev/hd44780.h> to your source file
3-Feed some libraries to the linker in the makefile (-lsomething)

As said before, please correct/complete me if I am missing something,
cause I have figured out this by myself with no prior experience.

Now my questions.
1-To include the libraries with the nutconf one has to go to
Architecture->AVR->HD44780 Driver
and there one can select the LCD size (4x16 in my case). Should I do
anything else here? I mean, there are other stuff to play with (Data
port, Bits Data Port, Enable Bit, etc.) but I cannot change anything...

2-Why the dev/hd44780.h has NO declaration of any function at all? It
only contains defines and the declaration of NUTDEVICE devLcd;

3-What is the library to give to the linker (-lsomething)?

4-Where and how should I specify what port and pins of the
microcontroller to use for the data, enable, select, etc.. pins of the
LCD? "How" it seems to be with defines, but where should I put them?
Should I use my own header file for this? Should I use any "#undef"?

I would appreciate if anybody would clear these things up for me.
As a working example I am trying to compile the following simple code.

----------------------------------------------
#include <sys/timer.h>
#include <dev/hd44780.h>
//#include "hd44780.h"

int main(void)
{
/*
* Initialize the LCd
*/
NutRegisterDevice(&devLcd, 0, 0);

NutSleep(500);
unsigned char ch=0;
LcdSetCursor(ch);
LcdWriteData('0' + (ch%10));

while(1);
}
--------------------------------------------------------

that of course gives me

--------------------------------------------
jose@aut-19:~/ethernut-4.2.1/app/lcd-test$ make
avr-gcc -c -mmcu=atmega128 -Os -fno-delete-null-pointer-checks -Wall
-Wstrict-prototypes -Wa,-ahlms=lcd-test2.lst -DETHERNUT2
-D__HARVARD_ARCH__ -I/home/jose/ethernut-4.2.1/bld/include
-I/home/jose/ethernut-4.2.1/include lcd-test2.c -o lcd-test2.o
lcd-test2.c: In function `NutAppMain':
lcd-test2.c:15: warning: implicit declaration of function `LcdSetCursor'
lcd-test2.c:16: warning: implicit declaration of function `LcdWriteData'
avr-gcc lcd-test2.o -mmcu=atmega128
-Wl,--defsym=main=0,-Map=lcd-test2.map,--cref
-L/home/jose/ethernut-4.2.1/lib -Wl,--start-group
/home/jose/ethernut-4.2.1/lib/nutinit.o -lnutarch -lnutos -lnutdev
-lnutos -lnutcrt -Wl,--end-group -o lcd-test2.elf
lcd-test2.o(.text+0x1e): In function `NutAppMain':
: undefined reference to `LcdSetCursor'
lcd-test2.o(.text+0x26): In function `NutAppMain':
: undefined reference to `LcdWriteData'
make: *** [lcd-test2.elf] Error 1
-----------------------------------------------


Thanks!
José

_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion

José Vallet

unread,
Mar 27, 2007, 3:14:48 PM3/27/07
to Ethernut User Chat (English)
Now I am able to answer myself, so I post for future reference.

José Vallet wrote:
> Hello.
>
> I am trying to add a 4x16 LCD to my Ethernut 2. I am using NutOS 4.2.1
>
> I found a document (Ethernut application note 001) that describes a
> simple add-on board and the internals of some drivers. However it does
> not explain how to write code using the drivers already included in the
> NutOS.
>
> I guess that the very basic process is more or less like follows
> (PLEASE, correct me!)
>
> 1-Recompile the NutOS libraries including the LCD drivers (form the
> nutconf).
> 2-Add the #include <dev/hd44780.h> to your source file
> 3-Feed some libraries to the linker in the makefile (-lsomething)
>

Basically it seems correct.

> Now my questions.
> 1-To include the libraries with the nutconf one has to go to
> Architecture->AVR->HD44780 Driver
> and there one can select the LCD size (4x16 in my case). Should I do
> anything else here? I mean, there are other stuff to play with (Data
> port, Bits Data Port, Enable Bit, etc.) but I cannot change anything...

Yes you can. The problem is that under my Linux Kubuntu the column of
the GUI where you can change the values of the macros (between the
Nut/OS components panel and the other half of the window with the
property/value and comments panels) is just all uniformly gray and you
cannot imagine that there are drop-down menus there until you click on
top. In windows it was more clear (visible).

>
> 2-Why the dev/hd44780.h has NO declaration of any function at all? It
> only contains defines and the declaration of NUTDEVICE devLcd;

Still unknown.

>
> 3-What is the library to give to the linker (-lsomething)?

-lnutdev

>
> 4-Where and how should I specify what port and pins of the
> microcontroller to use for the data, enable, select, etc.. pins of the
> LCD? "How" it seems to be with defines, but where should I put them?
> Should I use my own header file for this? Should I use any "#undef"?

Use the nutconf.

>
> I would appreciate if anybody would clear these things up for me.
> As a working example I am trying to compile the following simple code.
>

...
This one is more interesting. It is for a 16x4LCD

-------------------------
#include <stdio.h>
#include <sys/timer.h>

#include <dev/hd44780.h>
#include <dev/term.h>

int main(void)
{
int j=0;


/*
* Initialize the LCd
*/
NutRegisterDevice(&devLcd, 0, 0);

freopen("lcd", "w",stdout);
while (1)
{
NutSleep(1500);
//Place the cursor in the HOME position
printf(ESC_CLRHOME);
//Print the info in fixed positions using VT52 controls
printf("Vo=%i" ESC_POS "%c%cIo=%i\n",j,32+0,32+8,j);
printf("Hm=%i" ESC_POS "%c%cPr=%i\n",j,32+1,32+8,j);
printf("H2f=%i" ESC_POS "%c%cAir=%i\n",j,32+2,32+8,j);
printf("To=%i" ESC_POS "%c%cT1=%i",j,32+3,32+8,j++);
printf(ESC_CLRHOME);

}
}
---------------------------------

Regards.

José

_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion

Ole Reinhardt

unread,
Mar 27, 2007, 3:31:50 PM3/27/07
to Ethernut User Chat (English)
Hi,

> > 2-Why the dev/hd44780.h has NO declaration of any function at all? It
> > only contains defines and the declaration of NUTDEVICE devLcd;
>
> Still unknown.

In fact there are no public functions in the lcd driver available. These
are all access through the device struct. The device struct is connected
to the terminal functions and these again are accessible through normal
i/o operations like fprintf...

Regards,

Ole Reinhardt

--
kernel concepts GbR Tel: +49-271-771091-14
Inh. Faerber & Kirchner Fax: +49-271-771091-19
Sieghütter Hauptweg 48 Mobil: +49-177-7420433
D-57072 Siegen UstID: DE 205 648 898

_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion

Reply all
Reply to author
Forward
0 new messages