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!