Você está na página 1de 5

Why

LCD

4-Bit

Operation?

You may be Surprised why we using LCD in 4-Bit Mode and How its Possible? LCD in 4-Bit means we are 4 Lines of data bus instead of using 8 Line data bus. In this Method, we are Splitting Bytes of data in Nibbles. If you successfully interface Microcontroller with LCD with 4 Pins. Then we can save 4 Lines of Microcontroller, which pins we can used for other purpose. In this Article we are using 16 x 2 LCD. Same Process in Repeated For all Type of Character LCDs expect Minor Changes

Circuit

Pic

of

circuit

How
Lcd is

to
initialize in 4

initialize
bit mode. For

LCD
that 0x30

in
is the be

4
written 3

bit
times on

mode
lcd.

LCD

Pin

Description

Flow

Chart

Pin No
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Symbol
Vss Vcc Vee

I/O
-

Description
Ground +5V

Contrast Control
Input

RS R/W E DB0 DB1 DB2 DB3 DB4 DB5 DB6 DB7


Vcc Vss

Command/Data Register Read/Write Register Enable Not Used in 4-Bit Mode Not Used in 4-Bit Mode Not Used in 4-Bit Mode Not Used in 4-Bit Mode Data Bus in 4-Bit Mode Data Bus in 4-Bit Mode Data Bus in 4-Bit Mode Data Bus in 4-Bit Mode For LCD Back Light For LCD Back Light

Input Input/Output Input/Output Input/Output Input/Output Input/Output Input/Output Input/Output Input/Output Input/Output
-

Code in C
#include<reg51.h> #include<stdio.h> #define LCDPORT P2 sbit RS=LCDPORT^0; sbit RW=LCDPORT^1; sbit E =LCDPORT^2; bit status=0; #define lcd_delay 400 /* * * * * */ Function Name Input Output Description : delay : : :

value None This Function Gives Approximate Delay required For LCD Intilization

void delay(unsigned int j) { unsigned int i=0; for(i=0;i<j;i++); } /* * Function Name * Input * Output * Description */

lcd_init_write : value : None : Used For Initilize LCD

void lcd_init_write(unsigned char a) { RS=0; RW=0; LCDPORT=a; E=1; delay(lcd_delay); E=0; } /* * Function Name : * Input * Output * Description */ void lcd_com(unsigned char a) { unsigned char temp; if(status) { status=0; goto next; } RS=0; next: RW=0; temp=a; temp&=0xf0; LCDPORT&=0x0f; LCDPORT|=temp; E=1; delay(lcd_delay); E=0; temp=a<<4; temp&=0xf0; LCDPORT&=0x0f; LCDPORT|=temp; E=1; delay(lcd_delay); E=0; } /* * Function Name : * Input * Output * Description */

lcd_com : value : None : For Sending Commands and Data by checking Status Bit

// Mask Lower 4 Bits // Make No Affect on 0ther Port Pins // Send Higher Nibble to LCDPORT //Send Enable Signal to LCD //Left Shift Byte Four Times // Mask Higher 4 Bits // Make No Affect on 0ther Port Pins // Send Lower Nibble to LCDPORT // Send Enable Signal to LCD

lcd_data : value : None : For Sending Data By Setting Status Bit=1

void lcd_data(unsigned char a) { status=1; RS=1; lcd_com(a); } /* * Function Name : lcd_init * Input : None * Output : None * Description : For Intilization LCD in 4-Bit Mode */ void lcd_init(void) { delay(lcd_delay); lcd_init_write(0x30); //Special Sequence:Write Function Set. delay(lcd_delay); lcd_init_write(0x30); //Special Sequence:Write Function Set. delay(lcd_delay); lcd_init_write(0x30); //Special Sequence:Write Function Set. delay(lcd_delay); lcd_init_write(0x20); // 0x20 for 4-bit delay(lcd_delay); lcd_com(0x28); //Display Off, Cursor Off, Blink Off delay(lcd_delay); lcd_com(4); // Clear Screen & Returns the Cursor Home delay(lcd_delay); lcd_com(0x85); delay(lcd_delay); lcd_com(6); //Inc cursor to the right when writing and dont shift screen delay(lcd_delay); lcd_com(1); delay(lcd_delay); } /* * Function Name : lcd_puts * Input : String * Output : String * Description : Display String on LCD */ void lcd_puts(char *str) { unsigned int i=0;

for(;str[i]!=0;i++) lcd_data(str[i]); } /* * * * */ Function Name Input Output Description : : : : Main None None Display Character on LCD at Proper Location

void main() { lcd_init(); //Intilize LCD in 4-Bit Mode lcd_com(0X80); // Start Cursor From First Line lcd_puts("Hello"); //Print HELLO on LCD lcd_com(0XC0); // Start Cursor From Second Line lcd_puts("World"); //Print HELLO on LCD while(1); //Stay Forever Here }

Você também pode gostar