Knowledge Base‎ > ‎General Gyaan‎ > ‎Tutorials‎ > ‎

Interfacing a 16 X 2 LCD to your ATMEGA

posted Sep 17, 2016, 7:02 AM by Rohit Bhaskar
Often, when you are working with micro-controllers, you might feel the need to see what conditions are being executed or what input the micro-controllers are taking. For that, you can always use LEDs, but then LEDs are a very clumsy and confusing way of going about it. 

So, what should you use that shows me what's going on ?? An LCD, of course !! 

Here's how. 

1. Read the datasheet of your LCD. 
2. Understand your LCD. 
3. Write the code. 
4. Burn the code. 
5. Make the connections and voila !! 

For the purpose of modularizing work ( and for fear of this post becoming too long and boring), I have posted the detailed discussions section-wise as text files.

 All links are at the bottom of the post. 

Step 1 : Requirements : 

I am using a HITACHI JHD162A LCD Display, with a HD44780 LCD Controller, which comes for roundabout Rs. 110. The datasheet of the controller is much more important than that of the module, since its the controller which is going to take in input and print the screen. You need not bother with the datasheet of the LCD itself. Of course, you will also need a micro-controller with at least 11 usable pins and lots of connectors. 

Step 2: Understand your LCD : 

Read the datasheet.HD44780 LCD Datasheet Explained
Step 3: Write the code:

Easier said than done, eh ? Well, do the next best thing. Find code on the internet, understand it and tweak it, based on your configuration. I read Bibin John's code and modified it a bit. I have also been recommended Peter Fleury's library as being easy to use, but I haven't gone through it as yet.JHD162A LCD Code
 I have used the delay function provided by WinAVR in my code, since Bibin has written his own delay loop in assembly language and it was giving me faulty delays,making the wait too long. Step 4: Burn the code: The easiest part by far. Just make sure your code is syntactically and logically correct ( you need to know the datasheet well for that) and burn it using WinAVR. 

Step 5: 

Connect :


Quite an important step. Even if the code is correct, your screen will display junk at the most and black boxes usually if the connections are improper. Here's the checklist. 

Here's a picture of the output I get :


Shortcomings,problems, general precautions etc

There are lots of things that can go wrong, implying there are lots of things you must be careful about.LCD Interfacing Checklist
Problems :ProblemsHappy Printing !! 

P.S. Many thanks to Shashank S. for his help. --------------------------------------------------------------------------------------------- Links : 

1. Datasheets : a. HITACHI JHD162A LCD Display 
                        b. HD44780 LCD Controller (Courtesy : Sparkfun

2. Reading : a. Bibin John's Books 
                    b. Robotics India 
                    c. AVR-Beginners 
                    d. Meteosat's Tutorial 

3. Files  :     a. Datasheet summary 
                   b. Code 
                   c. Checklist 
                   d. Problems 
                   e. Peter Fleury's library 

Contributed by :
Ankit Daftery
ankitdaf [at] gmail [dot] com

Rohit Bhaskar,
Sep 17, 2016, 7:02 AM
Rohit Bhaskar,
Sep 17, 2016, 7:02 AM
Rohit Bhaskar,
Sep 17, 2016, 7:02 AM
Rohit Bhaskar,
Sep 17, 2016, 7:02 AM