Docstoc

LCD 2x16 interface to ATmega16

Document Sample
LCD 2x16 interface to ATmega16 Powered By Docstoc
					                 LCD (2x16) interface to Atmega 16


                                                   In this tutorial we are going to interface a
                                                   2x16 LCD to ATmega 16 microcontroller
                                                   and simulate it using proteus software and
                                                   explain how to display variables on LCD in
                                                   an easy way.

                                                   The editor we are going to use is codevision
                                                   avr compiler.




 Steps

1-open the editor and select the wizard as shown in the following picture
 2- select the chip tab and choose your microcontroller here we are using Atmega 16 so we select
it , then select the frequecny for your chip in this example ( 8 Mhz)




3-then select LCD tab and choose the PORT you want to connect LCD to (example : PORTC).

 then choose the type of your LCD where 16 is the LCD 2x16 character

 (NOTE : Atmega 16 has 4 PORTS : PORTA,PORTB,PORTC,PORTD)
4- now you have finished initialization of your code, to see your code select file > generate,save
and exit.

  then save your file (the program will ask you to save three files save them in the same folder
with the same name) . after you save your files your code will be displayed .




( NOTE : the underlined word determines which port the lcd is connected to and since we choose
PORTC , the number 0x15 is written where 0x15 is the address of PORTC in the I/O registers of
Atmega 16 e.g. if want PORTA >> 0x1B , PORTB >> 0x18 , PORTD >> 0x12 )

5- at the end of the code you will find while (1) where we place the main program of the
microcontroller. Now we have to give a look at the lcd functions.

 LCD Functions

1- lcd_clear( ) :

clears the LCD and sets the printing character position at row 0 and column 0. (char position will
be explained in the next function )

2- lcd_gotoxy(x, y)

sets the current display position at column x and row y. The row and column numbering starts

from 0.

for example : lcd_gotoxy(11,1) will set the pointer at the location arrowed in the following figure
i.e. the next character will be displaye at row #1 and column #11
3- lcd_putchar(c)

displays the character c at the current display position.(used to display variables)

4- lcd_puts(char *str)

displays at the current display position the string str, located in RAM.

5- lcd_putsf(char flash *str)

displays at the current display position the string str, located in FLASH.(used to display strings
i.e. words)

for examlpe : lcd_putsf( "Hello World!!!") >> the string Hello World!!! will be displayed as it's
i.e. any thing between double qoutes will be displayed as it's.




 CONNECTION




As shown in the following figure :
 Displaying Variable

assume you are displaying the temperature of a room at some time it's 30 Celsius and later it's 28
Celsius how can you display the varying temperature .

Here we go :

Assume the variable you want display has a max value 999 i.e. it's three digits and stored in the
variable x.

Define three variables(char) : h,t,u                  >> where h stands for hubdreds , t for tenth and u for units.



Then :

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

h=x/100;                // assume x=245             >>>>> 245/100=2

lcd_putchar(h+0x30);               // to display 2 you must send it's ASCII to the LCD which is 0x32

t=(x-h*100)/10;                    //245-200=45 >>>> 45/10=4;

lcd_putchar(t+0x30);                // send 0x34

u=(x-h*100-t*10);                      //245-200=45 >>>45-40=5

lcd_putchar(u+0x30);                   // send 0x35

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Here is a simple program where there are 8 switches connected to PORTA represent our variable
which can take a value from 0 to 255 and we display this value on the LCD.

Download here >>> http://www.mediafire.com/?lt7v9zlb7y735wj

                  if you liked this tutorial visit us at :

               http://all-about-embedded.blogspot.com/

				
DOCUMENT INFO
Shared By:
Stats:
views:487
posted:8/13/2012
language:English
pages:6
Description: This tutorial explains how to connect LCD 2x16 to ATmega16 microcontroller using codevision avr compiler.