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.
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.