Tech News Today, Marshmallow Custom Rom, Huawei, Run Programs, Network, Chromebook, Bank Account

Senin, 21 Mei 2012

LCD 16x2 interfacing with 8051 4-bit mode

LCD 16x2 interfacing with 8051 4-bit mode - To all visitors of this blog, I say welcome and thank you for visiting the blog Tech News Today Look for all the things you need that are available on this blog. If not available, please leave suggestions and comments for the development of this blog. now we will discuss first about LCD 16x2 interfacing with 8051 4-bit mode we have collected a lot of information from sources to create this article, so please see.

Articles : LCD 16x2 interfacing with 8051 4-bit mode
full Link : LCD 16x2 interfacing with 8051 4-bit mode
Article Embedded Zone,

You can also see our article on:


LCD 16x2 interfacing with 8051 4-bit mode



Hi,
today we are interface LCD(16x2) with 4 bit mode.
hear we are using tow good software keil and proteus same as older post lcd interfasing.





This article explains interfacing of LCD with 8051 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.

The Data or command is sent in nibble form (1 nibble= 4 bit) in the 4-bit mode. The higher nibble is sent first followed by the lower nibble. The function of RS, RW and EN pins remains similar to 8-bit mode.

Circuit description: 
Connections of LCD with 8051 are shown in circuit diagram. In 4-bit mode, the Data lines must be connected with D4, D5, D6 and D7 pins of LCD module.

Initialization: 
The LCD can be configured in 4-bit mode by sending appropriate instruction which is called “Function set” to it. The Function set is hexadecimal instruction for LCD MPU unit, which selects working modes of LCD. The “Function Set” is mentioned in following table:

Instruction
Rs
Rw
D7
D6
D5
D4
D3
D2
D1
D0
Function set
0
0
0
0
1
DL
N
F
-
-
  
Description: 
DL - Data Length (DL = 1 8bit, DL = 0 4bit)
N - No. of Lines (N = 1 2Lines, N = 0 1Lines)
F - Fonts (F = 1 5x10 dots, F = 0 5x7 dots)

According to table, the value of Function Set for 4 –bit mode will be 0010 0000(0x20) because DL=0. The value “Function Set” for the LCD configuration 2 line (N=1), 5X7 dots (F=0) and 4-bit (DL=0) mode will be 0010 1000(0x28).

When the power supply is given to LCD, it remains in 8-bit mode. Now, if 0x20 is sent, lower nibble will not be received by LCD because four data lines (D4-D7) are connected, so 0x02 is sent instead of 0x20.

now simple program for LCD :

LCD.C

#include <reg51.h>
#include <lcd.h>

void main()
{

lcdinit();
lcddatas(1,"ramoliyabiren");
lcddelay(50);
lcdrotade(1,'r',"sihanandi.blogspot.com");
lcdblink(5,"Computer Zone");
while(1) {}


LCD.H

/*

Hi I am Ramoliya Biren.
this program is open use.
for using this hader file.
u need to add this lcd.h in you are source group in keil.
for using fxn

lcddatas(row no,"DATA which u need to desplay"); for desplay string on lcd

lcddata("data(only single char) which u need to desplay on lcd")

lcdblink(no of time u wont to blink data,"data which u wont to blink"); hear data desplay on row 1 only

lcdrotade (row no,'direction of rotaed l or r',"data which u wont to rotaed");

visit : http://sihanandi.blogspot.com/

*/

#ifndef _leddatas_H
#define _leddatas_H

#include <reg51.h>

sfr ldata = 0xA0;
sbit rs = P3^2;
sbit rw = P3^3;
sbit en = P3^4;

void lcddelay (unsigned int itime)
{
 unsigned int i,j;
 for(i=0;i<itime;i++)
 for(j=0;j<1275;j++);
}

void lcdcmd(unsigned char value)
{
 ldata = value;
 rs = 0;
 rw = 0;
 en = 1;
 lcddelay(1);
 en = 0;
}

void lcddata (unsigned char value)
{
 ldata = value;
 rs = 1;
 rw = 0;
 en = 1;
 lcddelay(1);
 en = 0;
}

void lcdinit()
{
 lcdcmd(0x0e);
 lcdcmd(0x01);
 lcdcmd(0x80);
 lcddelay(50);
}

void lcdrow(unsigned char no)
{
 if (no == 1)
 {
  lcdcmd(0x80);
 }
 if (no ==2)
 {
  lcdcmd(0xC0);
 }
}

void lcddatas (unsigned char row,unsigned char *lcdstring)
{
 lcdrow(row);
 while (*lcdstring) 
 {
  lcddata(*lcdstring++);
 }
}

void lcdblink(unsigned char no,unsigned char *lcdstring)
{
 unsigned char j;
 for(j=0;j<no;j++)
 {
 lcdcmd(0x01);
 lcddelay(50);
 lcddatas(1,lcdstring);
 lcddelay(50);
 }
}

void lcdrotade(unsigned char no,unsigned char dir,unsigned char *lcdstring)
{
 unsigned char i;
 lcddatas(no,lcdstring);
 if (dir == 'l')
 {
  for (i=0;i<16;i++)
  {
  lcddelay(100);
  lcdcmd(0x18);
  }
 }
 if (dir == 'r')
 {
  for (i=0;i<16;i++)
  {
  lcddelay(100);
  lcdcmd(0x1C);
  }
 }
}

#endif 


         U can also download all sour coda and also emulation file from here.

so keep exploring 8051.....

see video of emulation