Saturday, 5 October 2013

LCD INTERFACING WITH ATmega16 IN 4-BIT MODE

Here we interface a 16x2 alphanumeric LCD with ATmega16 which is a AVR controller.
                                       
Pin configuration is written behind this LCD as...

1       -   GND
2       -   VCC (+5V)
3       -   VEE  (FOR CONTRAST)
4       -    RS    (REGISTER SELECT)
5       -    RW   (READ/WRITE)
6       -    EN    (ENABLE)
7-14  -    DATA PINS D0-D7
15      -   LED PLUS
16      -   LED MINUS


Components required :-
  1. 10k ohm registance
  2. 10k ohm variable registance
  3. 8 MHZ crystal oscilltor
  4. 16x2 LCD
  5. ATmega16 IC
  6. 12v battery 
  7. Toggle button
  8. 7805 IC
  9. 330 ohm resistance
  10. 1N4007 diode
  11. 1000uf capacitor
  12. Green LED

Circuit diagram : - 

                                 


In  4-bit mode ground the first 4 data pins of LCD means pin 7-11. make the connections as shown above.


Code (compiled in AVR studio 4) :-
                                                       (see.. AVR STUDIO 4 TUTORIAL)

Note :- In AVR studio 4 for compiling the program a makefile is necessary to create.
                                     (see.. HOW TO CREATE A MAKEFILE)
          Add this makefile in STUDIO 4. This makefile and lcd.c and lcd.h files must be in the               same folder of project. Click below links go to file>download.
                                (download.. lcd.c and lcd.h from here)

-----------------------------------------------------------------------------------------------------------------------

#include<avr/io.h>
#include<util/delay.h>
#include"lcd.h"
int main(void)
{
lcd_init(LCD_DISP_ON);
lcd_clrscr();
while(1)
{
lcd_gotoxy(3,0);
lcd_putc('E');
_delay_ms(500);
lcd_gotoxy(6,0);
lcd_puts("FOR");
_delay_ms(500);
lcd_gotoxy(3,1);
lcd_puts("ENGINEERS");
_delay_ms(500);
}
}

-----------------------------------------------------------------------------------------------------------------------



Code (compiled in CVAVR) :-  
                                                (see.. CVAVR TUTORIAL (CODE VISION AVR))

Note :- In CVAVR program window delete all the lines and paste the code given below. because there are so much unnecessary lines.

 ----------------------------------------------------------------------------------------------------------------------

#include <mega16.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

void main(void)
{

// LCD module initialization
lcd_init(16);

while (1)
      {
        lcd_gotoxy(0,0);
        lcd_putsf("ashish");
      }
}

-----------------------------------------------------------------------------------------------------------------------
Proteus simulation of both codes :-





Note :- If you have problem to see characters in LCD then reduce the contrast level of LCD by increasing the resistance of 10k variable resistor.                                       

4 comments:

Saurav said...

Cant get anything on LCD.

Tried changing Contrast. Gets only 1 Line black dots continuosly. Connections are exactly as mentioned.

I m using Atmega16L. Frequency of system is 8MHz. No ossicilators i have used.

Plz help me.

Unknown said...

Which compiler u are using. ?

Unknown said...

you can have hand in both 4 bit and 8 bit working perfectly with proteus simulation. here i found some post while looking up over net.
http://www.mechaterrain.com/lcd-interfacing4bit-mode

Unknown said...

you can have hand in both 4 bit and 8 bit working perfectly with proteus simulation. here i found some post while looking up over net.
http://www.mechaterrain.com/lcd-interfacing4bit-mode