Plans for AVR LCD display, need some help..

I've just ordered at ATMEGA644 after running out of space on my ATTINY2313 too easy. Along with that, i got a 20X4 LCD screen, character one that displays letters, and the cursors are 5X7 matrix.

How does one write to a LCD screen? like is there a good place for a tutorial? maybe a simple sample code of HELLO WORLD? I know in DOS you need stlib or w/e, and you do printf("HELLO WORLD\n"); does it work similar to displaying on a 20X4 character screen? I'm a ok C programmer, knowing the basics to create little games with 3X3 leds and speakers. I've got a C programming book to help along with it. So feel free to explain, or just give code samples. i can figure it.


sort by: active | newest | oldest
gmoon9 years ago
Most char LCDs copy the Hitatchi 44780 style driver. Here's an in-depth explaination of it's operation. You can start from scratch, or reuse / rewrite other projects. There are dozens (or hundreds) of AVR 44780 drivers out there.

Actually, one of the avr-libc demo projects includes an LCD driver. And Peter Fleury has an LCD library many have used. You can find simpler implementations, of you look hard enough.

One caveat about LCD displays--they sometimes require a negative voltage for contrast control. Some won't display anything at all without one. In fact, it's often the better ones that require it (they have a wider temperature-range tolerance.) I had to build a small negative power supply for my 40 X 2--although ICs exist for that....
Killa-X (author)  gmoon9 years ago
Ok you, So say i wanted to hook a keyboard to my chip so i push Q, light goes on. Simple 2-wire connection. Now why cant i just include stdio and use getchar and stuff? is there not a simple fast way to do it? all i found was this mega 300 line code for a keyboard reading! wtf D:
I've never used a keyboard with a uC before, but here's some things I know. USB will be pretty much impossible for you to do easily, use a PS/2 keyboard. PS/2 is fairly open & standardized, but its not perfect. I'd use that 300-line code -- you'll need it. You'll end up doing similar things for the LCD. I gennerally like the ones that havea "serial backpack", so that you only have to send serial data as letters, but that one doesn't appear to have it, so it will require some other programming: read the datasheet ;-)
gmoon zachninme9 years ago
Now why cant i just include stdio and use getchar and stuff?

Avr-libc and avrgcc are fast, powerful and create small code--but they aren't always the most convenient for beginners. Also why there are things like BASICstamps and Arduinos to bridge the gap--but someone wrote LCD libraries for those devices, just like the AVRs...

From the avrlibc page on stdio.h:

The standard streams stdin, stdout, and stderr are provided, but contrary to the C standard, since avr-libc has no knowledge about applicable devices, these streams are not already pre-initialized at application startup. Also, since there is no notion of "file" whatsoever to avr-libc, there is no function fopen() that could be used to associate a stream to some device.

Face it--that's "operating systems" stuff, and not necessary for most micro projects. You couldn't do any of that with a real microprocessor (and a RAM and IO bus) either, without the OS. At least avr-libc has all the string manipulation routines. And you could create streams for stdio (if you were a masochist...)

Still, why complain, when you've got libraries with functions like lcd_puts() and lcd_gotoxy()? You can always go through an "gut" the code, keep what you need if it's too bloated...

5 minutes of googleing found this Atmel document, Interfacing the PC AT Keyboard, and also this project: AVR LCD terminal, which includes both LCD and PS/2 keyboard code...(as well as RS-232 output and servo control.) All running on an ATtiny2313--the code can't be too large...
Killa-X (author)  gmoon9 years ago
Yeah thanks for the help as always. AVR LCD terminal, using its library, their code is like only 10 lines for keyboard.

if (ps2dataReceived()){
while(!(UCSRA & _BV(UDRE))); // Wait for empty transmit buffer
temp = getps2char();
UDR = temp;
if (temp == 0x75){
pos = pos + 0x0A;
if (temp == 0x72){
pos = pos - 0x0A;

First if, is 8 key, 2nd one is Down arrow.
gmoon Killa-X9 years ago
Yeah. And most of that's not PS/2 code. He's set aside a 16 byte buffer for the keyboard data. And there's an init routine for the PS/2 port:
UCSRA, UDRE, UDR are part of the USART (for the RS-232 data port.) setServo() and pos are for the servo. You don't need that stuff.

To read the keyboard and display on the LCD (init that, too, of course), inside of an endless loop:

if (ps2dataReceived()){    temp = getps2char();    lcd_putc(temp);}
or even simpler:
if (ps2dataReceived()){    lcd_putc(getps2char());}

Assuming no translation is needed for keybd -> LCD chars.
gmoon gmoon9 years ago
I see the AVR LCD terminal is using the Fleury LCD library... Sounds like an endorsement, to me.