Society of Robots - Robot Forum

Software => Software => Topic started by: rahulmagoo on June 27, 2008, 08:51:45 AM

Title: Interfacing LCD
Post by: rahulmagoo on June 27, 2008, 08:51:45 AM
hello,
Do any one has any experience in interfacing LCD with AVR (Atmega16)??


If yes then can you  tell me how you interfaced lcd with your avr  and how you displayed letters and stuff on your lcd.
PLEASE be clear in the following points.

How to connect an lcd with avr?

How to command the lcd to display characters on its screen?

How to program your avr for interfacing with an lcd?

Any kind of code example will be highly helpful..

Thanks

Title: Re: Interfacing LCD
Post by: airman00 on June 27, 2008, 12:23:02 PM
what kind of LCD - parallel one or a serial one
Title: Re: Interfacing LCD
Post by: rahulmagoo on June 28, 2008, 02:14:04 AM
I am just a beginner..i really don't know whether my LCD is serial or parallel..i bought it for around rs.200(~5$).
It look similar to one shown here: http://www.onlinetps.com/ViewItem.php?ItemID=3
Title: Re: Interfacing LCD
Post by: benji on June 28, 2008, 03:16:07 AM
it lookslike just another 2*16 lcd
it has more than 10 pins so i guess its not serial
you should have the driver datasheet to know the lcd commands
i guess its the same ol hitachi HD4478
google lcd microcontroller interface , your gonna have loads of tutorials

the interface options im aware of is
1/ 8 bit interface
2/ 4 bit interface
3/ connect lcd as external memory
Title: Re: Interfacing LCD
Post by: rahulmagoo on June 28, 2008, 01:31:35 PM
I have Atmega16 and i am using AVR studio.
Writing a code in C to display it on my LCD is creating all problem. If any one could help me in providing any sample code...even if the code is to display name or any simple code would really help me in solving my problem.
Title: Re: Interfacing LCD
Post by: izua on June 28, 2008, 01:46:23 PM
Tell us what your problem is, show us what you have made up till now, and we'll try to help you.
Without any input from your side, we can't know what you are doing wrong.
Title: Re: Interfacing LCD
Post by: rahulmagoo on June 28, 2008, 01:58:44 PM
As i ve said before i am just a beginner...basically my problem is that i am not able to code in AVR studio..

When i set my port(say B) to high it works fine without any compilation error...but when i set a pin(say B 4)...it shows a compilation error... ???
So can any one please help me in writing a program in AVR studio..as i want 2 program my Amega16 to set its 2 pins as input and 2 pins as output.
Title: Re: Interfacing LCD
Post by: benji on June 28, 2008, 02:37:34 PM
right ur your code here, with the copiler errors
Title: Re: Interfacing LCD
Post by: airman00 on June 28, 2008, 10:14:01 PM
use google like benji said, there are loads of tutorials
http://homepage.hispeed.ch/peterfleury/avr-lcd44780.html


perhaps someone could write a better one on this site???

Title: Re: Interfacing LCD
Post by: izua on June 28, 2008, 11:03:46 PM
I have a hunch your problem is not the LCD itself, but the fact that you don't know the language. Start simple, make a led flash.
Title: Re: Interfacing LCD
Post by: rahulmagoo on June 29, 2008, 04:29:58 AM
I wrote a code for blinking LED which is:
#include <avr/io.h>
#include <avr/delay.h>

void MSDelay(unsigned int);
int main()
{
   DDRB=0;
   while(1)
   {PORTB=~PORTB;
    MSDelay(25);
      
   }
   
}
void MSDelay(unsigned int itime)
{
   unsigned int i,j;
   for(i=0;i<itime;i++)
   for(j=0;j<125;j++);
}


this code dose not show any problem(any compilation error)...this works for all the pins of port B...if I want for a specific PIN say(B 2)...the code gives compilation error :'(
Title: Re: Interfacing LCD
Post by: izua on June 29, 2008, 05:29:10 AM
Do you know how to set/clear/toggle a single bit in a byte in winAVR?
And you know that C has no idea of pins, ports, and the such, you are just operating on bytes, right?

To set a single bit in a byte, you need to do something like
byte |= mask
where mask, is a bitmask of the bits you want to set.
for example, to set bits 3 and 6 you can do something like
mask = (1 << 3) | (1 << 6)

or, simply, to set bits 3 and 6 in a byte
byte |= (1<<3) | (1 <<6)

to clear a bit, invert your mask (~ operator) and do a logical and with your byte and the mask (and = &)
to toggle some bits, use XOR (^)

Title: Re: Interfacing LCD
Post by: rahulmagoo on June 29, 2008, 08:27:32 AM
Thanks a lot izua...u really helped me....and thanks to others also
Thanks!!!  :)