Tuesday 6 May 2014

How to interface LCD in 4 bit mode with AVR microcontroller

This article explains interfacing of LCD with ATmega8 using 4-bit mode. In this mode only four pins are used for sending data and command instructions. This mode has the advantage over the 8-bit mode as it uses less number of pins. The remaining pins of the controller are available for normal use


LCD Pin Description :
Pin No
Symbol
I/O
Description
1
Vss
-
Ground
2
Vcc

+5V
3
Vee

Contrast Control
4
RS
Input
Command/Data Register
5
R/W
Input
Read/Write Register
6
E
Input/Output
Enable
7
DB0
Input/Output
Not Used in 4-Bit Mode
8
DB1
Input/Output
Not Used in 4-Bit Mode
9
DB2
Input/Output
Not Used in 4-Bit Mode
10
DB3
Input/Output
Not Used in 4-Bit Mode
11
DB4
Input/Output
Data Bus in 4-Bit Mode
12
DB5
Input/Output
Data Bus in 4-Bit Mode
13
DB6
Input/Output
Data Bus in 4-Bit Mode
14
DB7
Input/Output
Data Bus in 4-Bit Mode
15
Vcc
-
For LCD Back Light
16
Vss
-
For LCD Back Light

FLOW CHART :

LCD in 4 bit mode with AVR



Simulation by Proteus .
Program:
#include <avr/io.h>
#include <util/delay.h>

#include "lcd.c"

int main()
{
unsigned char i;

//Initialize LCD module
LCDInit(LS_BLINK|LS_ULINE);

//Clear the screen
LCDClear();

//Simple string printing
LCDWriteString("Congrats ");

//A string on line 2
LCDWriteStringXY(0,1,"Loading ");

//Print some numbers
for (i=0;i<99;i+=1)
{
LCDWriteIntXY(9,1,i,3);
LCDWriteStringXY(12,1,"% ");
_delay_loop_2(0);
_delay_loop_2(0);
_delay_loop_2(0);
_delay_loop_2(0);

}

//Clear the screen
LCDClear();

//Some more text

LCDWriteString("Hello world");
LCDWriteStringXY(0,1,"By YourName Here");    // <--- Write ur NAME HERE !!!!!!!!!!!

//Wait
for(i=0;i<100;i++) _delay_loop_2(0);

//Some More ......
LCDClear();
LCDWriteString("  kannupandiyan");
LCDWriteStringXY(0,1," webs.com");

//Wait
for(i=0;i<100;i++) _delay_loop_2(0);

//Custom Chars ......
LCDClear();
LCDWriteString("Custom Char !!!");
LCDWriteStringXY(0,1,"%0%1%2%3 %4%5%6%7");
return 0;

}

DOWNLOAD THE CODE HERE : click here to download
* Note: The code tested in hardware also ., it work's perfectly 100% sure 

if u have any problem ., inform me ....




No comments:

Post a Comment