Vous êtes sur la page 1sur 4

Wednesday, September 14, 2011

mCard MICROPROCESSOR PRESENTATIONS EMBEDDED LINUX NEWS TUTORIALS / ARTICLES CODE BANK QUERY ABOUT US FAQ

SITE SEARCH mCARD

INFOLETTER

because inform ation m atters

Tutorials | Infoletters | New s | Search

Liquid Crystal Display LCD 4-Bit Operation


LCD 4-BIT OPERATION Why LCD 4-Bit Operation Circuit Flow Chart Code in C Dow nload Code Interface LCD in 4 bit mode, LCD in 4 bit mode, Interfacing LCD w ith microcontroller

In the recent years LCD, is finding in daily use replacing LEDs which may be Single, Seven Segment or Multi Segment LEDs Because of Declining Pricing of LCD and ability to display numbers, characters and graphics. Another advantage of LCD is that, Incorporation of refreshing controller in to LCD for relieving the CPU of the task of refreshing LCD. Download Code (KEIL Project) (Zip Format)

Digital Oscilloscopes Digital Oscilloscopes now from Rohde&Schwarz. Get Details Here! www.scope-of-the-art.com/RTO Embedded Microcontroller Search Thousands of Catalogs for Embedded Microcontroller www.globalspec.com Custom and Std LCDs Get the best LCD solutions from us Fast, efficient, delightful service
www.crystalimage-lcd.com

Why LCD 4-Bit Operation?


LG CINEMA 3D Monitor
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

Comfortable Battery Free 3D glasses Electron Free Comfortable Eyes

www.lg.com /in/3d-m onitor

Circuit

Pic of circuit

How to initialize LCD in 4 bit mode


Lcd is initialize in 4 bit mode. For that 0x30 is the be written 3 times on lcd.

LCD Pin Description


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
-

Flow Chart

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 : delay

Download Code (KEIL Project) (Zip Format)

: :

value None

* */

Description

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 : lcd_com * Input : value * Output : None * Description : For Sending Commands and Data by checking Status Bit */ 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 */

// 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);

} /* * Function Name * Input * Output * Description */ void lcd_puts(char *str) { unsigned int i=0; for(;str[i]!=0;i++) lcd_data(str[i]); } /* * Function Name * Input Output * Description */

lcd_com(1); delay(lcd_delay);

: :

: :

lcd_puts String String Display String on LCD

: :

: :

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 }

Best view ed in 1024x768 pixels

[Home] [Query] [FAQ] [Aboutus] [Contact us] [Sitemap] [Privacy Policy] [Advertise ]

RSS FEED

Logos and brand names used in this site are belonging to their respected ow ners. We have used them here only for the purpose of information. Enable Active X control from internet options of internet explorer to view all element of this site.

Vous aimerez peut-être aussi