KEMBAR78
LCD Interface with ATmega16 Guide | PDF | Computing | Software
100% found this document useful (1 vote)
207 views6 pages

LCD Interface with ATmega16 Guide

This document provides instructions for interfacing a 2x16 LCD display to an Atmega 16 microcontroller and displaying variables on the LCD. It explains how to set up a codevision compiler project to initialize the LCD connection and select the appropriate ports. It then describes the basic LCD functions like clear, gotoxy, putchar, and puts/putsf for displaying text. Finally, it gives an example of how to display a variable value on the LCD by breaking it into hundreds, tens, and ones places and sending the ASCII values.

Uploaded by

laithnatour
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
207 views6 pages

LCD Interface with ATmega16 Guide

This document provides instructions for interfacing a 2x16 LCD display to an Atmega 16 microcontroller and displaying variables on the LCD. It explains how to set up a codevision compiler project to initialize the LCD connection and select the appropriate ports. It then describes the basic LCD functions like clear, gotoxy, putchar, and puts/putsf for displaying text. Finally, it gives an example of how to display a variable value on the LCD by breaking it into hundreds, tens, and ones places and sending the ASCII values.

Uploaded by

laithnatour
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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); t=(x-h*100)/10; lcd_putchar(t+0x30); u=(x-h*100-t*10); lcd_putchar(u+0x30);

// to display 2 you must send it's ASCII to the LCD which is 0x32 //245-200=45 >>>> 45/10=4; // send 0x34 //245-200=45 >>>45-40=5 // 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/

You might also like