If you are just getting into microcontrollers there's alot to know as you have likely found out. There's alot of good online tutorials for the Atmel AVR's and chances are you have see a few of those by now. I recently got into microcontrollers and didn't know jack about it. I wanted to have some early success and get my AVR to do something cool (other than blink leds).

I struggled through some terrible blog posts about how to control a common 16x2 LCD with the popular H44780 driver. I had to combine and tweak code from 3 places to get it working.  Anyway, over the past couple months I figured it out and since no one else has this covered on Instructables, I thought I would share my approach and see if you can get some early successes which will keep you diving deeper in to geekery.

There's an embedded video and pic of what this project will look like when you are done.

Here's what you will need:
1 - Atmel AVR ATtiny2313 microcontroller
1 - breadboard w/ 5VDC source (a 7805 will work with a 100uF & 0.1uF Cap)
1 - 16x2 Character LCD Display H44780 driver (available on Ebay for ~$6 or Sparkfun for ~$14)
1 - 16pin  0.1" spacing male header
1 - 330 resistor for LED backlight
1 - 1K for pull down on interrupt switch
2 - 10K resistor  for reset and counter interrupt pull ups
2 - small "breadboardable" momentary switches for reset & counter interrupt
1 - 1.5K resistor for contrast setting (could use a potentiometer), value may vary depending on display
1 - AVR ISP Programmer (see assumptions)
1 - soldering iron & solder
~10 - jumper wires for breadboard

Here's my assumptions:

- You have a AVR ISP programmer of some type (in my case the Atmel AVRISP mkII, but USBtinyISP should also work)
- I am assuming you have already gone through the flashy led tutorials and are somewhat familiar with some of the lingo like PORTs and binary numbers a little.
- I am doing everything in C code using WinAVR GCC.
- I am running the display in 8bit mode which isn't as pin efficient, but it is easier to teach.
- I am assuming you know how to solder
- I am assuming you are using the ATtiny2313, but you could put this code on any ATmega as well, as long as you rename the PORTs respectively. I'm not sure if this will work for Arduino's.
- My set up is using Atmel AVRStudio 4.17 with WinAVR 20090313 GCC C-compiler on a 32bit Window's Vista laptop. ( this is the toughest part because you may be using AVRdude or CodeVision which means my code may not directly work for you, but you will still learn something)
- My approach and my code may not be the most efficient or elegant way to run an LCD, but it does work and I can guarantee that when you see that display work for the first time, it's exciting regardless of how pretty your code is.

With all that said, lets get started!

Step 1: Setting Up the LCD

Ok, So you have 16x2 LCD with the H44780 or equivalent driver. These LCD's basically have a display screen, typically with an LED backlight, and a PCB on the back which has the driver. This driver makes our job really easy for controlling the LCD with a little $1.50 MCU. 

The Hitachi H44780 driver already knows all the characters in the alphabet plus some special symbols. It also has settings we can choose like show/hide the cursor, among others. The trick is, the way we control this is by hitting different combinations of the pins with 5v (binary 1) or 0v (binary 0). We will do this really fast and the driver will lookup and display the letters we pick. You can read a little more about the H44780 here en.wikipedia.org/wiki/HD44780_Character_LCD   
When we write a message (character string) in the program, the compiler will compile these letters into the respective ASCII hex codes which means we don't need a font file like in the case of a POV or dot matrix.

So, lets set up the LCD for the breadboard.

To make the LCD easy to work with on the breadboard we will solder the male header to the LCD package. These LCD's typically have 14 data pins and 2 for the LED backlight. So you will snap off a 16 pin piece of header and solder it into each of the 16 holes.

See the pics.

<p>Thanks. I am still learning from this example, but I made a few changes to the code because 'A winner is you' was not showing up for me. I did not have a button so I just stuck a wire to ground.</p>
<p>Super instruction! I run it on ATMega48 with 1MHz because I want to build nAmeter. But I was encountered problems because I mess with wires 8 and 9 which goes from IC.. Be carefull with theese ones o_O!!! Anyway great instruction! 2 hours and all was working!</p>
<p>Hey! Great tutorial, I'm planning to use it for my 16x2 on an ATtiny84.</p><p>I got a question though, I got only 6 pins available for the LCD and I saw somewhere that it is possible to use only 6 pins.</p><p>That some of the data bits are not needed, is it true? How can I do it?</p><p>Thanks.</p>
<p>If someone need ASM code to be short as it can be then please upload modification of Roznerd code in ASM to display just &quot;Yo&quot;. I needed LCD for other purposes than Winner game and it would be spent of time to coppy Winner game. My code works on ATMEGA48 but as with Roznerd code, you can make it run on other AVR such as Attiny2313. Maybe you also must change call instruction to rcall if some AVR is not supported call. Good luck!</p>
<p>Also please delete &quot;call ledon&quot; line and ledon proc. It was just using for debuging code! Thanx</p>
Thanx man!, I'm new in all this electronic stuff but it's a great explanation....I'll try to do it soon. Cheers from Mexico
This would be perfect for using in a trivia type handheld game.
Love your instructions - you really helped me get going. Thank you. I ran into trouble a couple times though - I found some terrible avr-objcopy flags on some other website that stymied me for days. The AVRFreaks finally figured out the problem - I wasn't copying the .data section into the hex file! Would you consider adding a little section with an example Makefile or even a simple gcc/objcopy inline example so noobs like me don't make the same mistake again?<br><br>Also, I've taken what you taught me and created my own instructable:<br>https://www.instructables.com/id/AVR-LCD-Namebadge/<br><br>Cheers!
Thanks for the instructable. I''m trying to follow your instructions but I think there is a problem with the bottom two pinouts on the lcd diagram LCD_Schematic.png. Shouldn't one of those go to ground?
Thanks for the comment. Good Catch! The VSS is the GND pin and VDD is the +5V. I have updated the schematic in the ZIP and in Step 3. I hope you have luck getting it working. Thanks - Roznerd

About This Instructable




Bio: Mechanical Engineer
More by roznerd:DIY Cubicle Clips - Cheap and Easy How to use a 74HC595 Shift Register with a AVR ATtiny13 How to control a 16x2 LCD using an AVR ATtiny2313 
Add instructable to: