PocketMagic

February 13, 2009

ATmega8 and 2×16 HD44780 LCD

Filed under: Electronics, Hardware, Uncategorized — Tags: , , , — radumotisan @ 4:43 pm

Following my first article on the initial findings and results of my tests on the ATMega8, this article will show basic steps on how to connect a 2×16 characters LCD to the micro chip.

The reason for this is to have a way of debugging the microchip functionality, to output the results, the data and various other stuff. I can tell you this is a must have.

To use a minimum of I/O pins, I’ve decided to build a 4bit interface with the LCD. The hard part was to write the code, but finally after fixing several bugs and reading a lot of HD44780 documentation, I can say that I’ve completed a nice flexible code – meaning that you can easily configure the LCD pin connection.

The wiring diagram is below:

The code interface is also attached, not much to say about it here, since it’s full of technical details and bit-wise operations, but if anyone has questions feel free to use the comments form at the bottom.
To edit some parameters like frequency or PIN connections (you can change the I/O pins used by the LCD on the ATMega), have a look in lcd.h . Zip attached:
atmega8-lcd

Function lcd_string2 is very useful for outputting text, since it supports variable parameters similar to printf. So you can use it for outputting misc content: lcd_string2(“Hello World! %d\npocketmagic.net”,i);

Here are some pictures with my LCD running:

Next thing to do is to start connecting various sensors.

Radu Motisan

14 Comments »

  1. do u have any work on the connections of LCD HD44780 with ATMEGA 32…. if u have then send to mee…

    Comment by JAWAD — March 15, 2009 @ 9:39 pm

  2. it’s the same as for atmega8, simply connect the LCD to some free pins on your uC, and compile the software in the post for your hardware.

    Comment by Radu Motisan — March 15, 2009 @ 11:22 pm

  3. how can i connect for 4*20?

    Comment by ioana — March 16, 2009 @ 3:12 pm

  4. Ioana, you can do it in the same way as for 2×16.
    Regarding the software, in LCD.h change LCD_LINES to 4 and LCD_DISP_LENGTH to 20.

    I also have a 4×20 lcd, I’ll see if I can hook it up to the uC, and post the modified code.

    Comment by Radu Motisan — March 16, 2009 @ 5:20 pm

  5. Hi;

    How can I make that work for an Atmega128. I have also a HD44780 controller. But I don’t understand how it works to just get something on the screen thats why I w<ant a simple excample

    grtz

    Comment by Nils — April 2, 2009 @ 9:37 am

  6. Hello Nils, making it work with the Atmega 128 is pretty much the same thing.

    Connect the HD44780 to the atmega 128, change the code to reflect the correct PIN connections, and recompile for the atmega128 (code currently is for atmega8).

    This should be all. good luck!

    Comment by Radu Motisan — April 2, 2009 @ 6:05 pm

  7. Thanks already,

    But I don’t understand much of the pin connections. Does it mather that i connect them to ie. PortA or PortB.
    Do I need to change something in the make file or just in AVR Studio.

    greetz

    Comment by Nils — April 2, 2009 @ 7:19 pm

  8. hey!!do u have any work on the connections of LCD HD44780 with ATMEGA 16….i just need the coding at this point… if u do then plz send them to me..i need it for VMLAB and the code in C and assembly…

    Comment by Alvina — April 4, 2009 @ 8:05 pm

  9. Hi Alvina,

    Currently I’m not using the Atmega16, but the code I’ve posted is easily configurable to work with any pin layout.

    just go in LCD.h and select the PINs you’re using according to the 4bit model, and recompile the code for atmega16.

    hope this helps.

    Comment by Radu Motisan — April 5, 2009 @ 12:38 pm

  10. Nils, you can connect them to what port you want.

    Simply choose 6 pins and configure the code in lcd.h and that’s it!

    Comment by Radu Motisan — April 5, 2009 @ 12:39 pm

  11. Do I need to change something in the make file of do something with the clock frequency? Ik work with a extern christal on 7372800 HZ.

    grtz

    Comment by Nils Winkelmans — April 5, 2009 @ 9:27 pm

  12. The clock frequency is also defined in lcd.h (XTAL…) Change that as well and recompile.

    Comment by Radu Motisan — April 6, 2009 @ 11:25 am

  13. Hey.

    Stupid question – I’m not exactly sure how to connect the AVR to the LCD screen. Is it simply a case of soldering the pins of the AVR to the appropriate holes in the LCD display?

    In addition, what are pins 1,2,3 and 5 for? A power supply?

    Comment by Ash — April 23, 2009 @ 5:45 pm

  14. Yes you need to provide 5V for the LCD.

    Comment by Radu Motisan — May 2, 2009 @ 11:19 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Create a free website or blog at WordPress.com.