NPEDUCATIONS, Electronic circuits development, electronics tutorials, microcontroller tutorials and projects, advanced microcontroller (ARM) based tutorials and projects, Embedded c development, Embedded c for ARM cortex M, Intel IoT based projects, IoT projects, CC3200 launch pad projects, MSP430 Launchpad tutorials and projects, Tiva C launch pad tutorials and projects, 8051 tutorials and projects, sensor interfacing with microcontroller tutorials, data communications and networking tutorials, peripheral interfacing with microcontroller, led message scrolling display, arduino based tutorials and projects, intel galileo based tutorials and project, ADC interfacing tutorials, LED Blinking, LCD interfacing, Embedded System tutorials and projects, B.tech projects, M.tech projects, online Embedded C training

8051 based 16x2 LCD interfacing in 4-bit mode without using busy status flag



1. Introduction 4-bit LCD interface:

The 4-bit mode LCD interface requires four data lines and two or three control lines. In this tutorial, 16x2 LCD interfaced with 8051 microcontroller in 4-bit mode without using busy status flag. In 4-bit mode LCD interface, MCU sends the data or command byte in two 4-bit bus transfers to LCD as nibbles. A nibble is 4bit data, which is half a byte.

2. Hardware interface with 8051 Circuit:

Figure 1 LCD Hardware interface with 8051 circuit.

In the above figure, the port0 upper four lines of the 8051 microcontroller is connected to data lines (D4-D7) of the LCD. In 8051 microcontroller, the port0 doesn’t have the internal pull-up resistors and all these port0 pins are open drain configuration. So we need to connect an external pull-up resistor to each port pin to improve the driving capability of the port0. The pull-up resistor values should be between 4.7kohms to 10kohms as recommended in the data sheet of the microcontroller.

The control pins (Enable, R/W, RS) of the LCD are connected to port2 of the 8051MCU (P2.2, P2.1, P2.0) respectively.


A 10k preset is connected at 3rd pin of the LCD to vary the contrast of the LCD. The 10k value is better chosen that not to vary the contrast drastically (If we use 1k or below preset value, the variation of the contrast is very drastic which make the operation of preset more sensitive). The 1k resistor is connected in series with 10k preset, which will limit the maximum current flow when the preset wiper is at its minimum position. A reset circuit made up of resistor and capacitor which is connected at 9th pin of the microcontroller and it is named as power on reset. This reset circuit is used to apply a proper reset pulse after the power supply is settled down, hardly it takes 100 milliseconds (TC = 10uf*10K). A clock circuit of 12Mhz with two 33pF capacitors are connected at the XTAL1 and XTAL2 pins.

3. LCD interface timing diagrams:

Figure 1.2 Timing diagram of LCD interface without using busy flag shows the wastage of CPU time.

In the timing diagram as shown in the figure 1.2, the data can be sent to LCD in two different 4-bit transfers. Hence two enable pulses are shown for each byte transfer. During the data or command transfer to LCD, the higher nibble (D7-D4) of a byte should be transferred first. After the command or data byte is transferred, the LCD will take some time to process it. A time delay N milliseconds should be provided to LCD for internal processing. Here I provided 100 milliseconds as time delay between each byte transfer (Check out the source code below). If delay is not provided between each byte transfers, the LCD will not accept the second byte until the first byte is completed. Therefore the LCD will not show desire output to user.


The main disadvantage of this procedure is unnecessary wastage of CPU or MCU time, because there is no exact time provided in the data sheet that an LCD will take to process the command or data. This can be solved by using busy status flag which is discussed in next tutorial.
“8051 based 8-bit mode 16x2 LCD interfacing using busy status flag”

4. Description about the LCD functions used:

There are five functions are implemented in embedded c (keil c). In each function, the data byte is divided into two parts (nibbles) by using logical masking, and then transferred. The higher nibble is transferred first and then lower nibble.
1.      Send_cmd() à  Microcontroller send command to LCD using “send_cmd()” function, in which the RD and R/W signals both are at logic low.

2.      Send_string() à Data string can be sent to LCD using this “Send_string()” function, in which the RS should be at logic high and R/W should be at logic low. When the number of characters in a string is greater than display size (> 16 characters) then the function “send_string()” will automatically shifts the display to right side.

3.      Send_char()à Using this function, we can send single char at a time.

4.      delayms(1)à this function generates 1ms delay approximately and it is tested in keil software. It uses a new function _nop_(), which generates 1us time delay and it available in intrins.h header file.


5.      LCD_Init() àby using this function, LCD is configured as 2 line with 5x7 matrix. This function makes the LCD display ON with cursor blinking and also has automatic cursor increment to right side. The commands used in this function are 0x83, 0x01, 0xc0. 0x80. Refer table 1.1 for description about the commands.

5. LCD Commands used:

In this tutorial basic commands are used to display alpha numeric characters on LCD. A list of LCD commands used in this tutorial shown in the table 1.1

S.No
Command
Description
1
0x01
Clear Display Screen
2
0x28
Configuring LCD as 2 line 5x7 matrix in 4-bit mode
3
0x0E
Display on, cursor blinking
4
0x06
Increment cursor right side
5
0x80
Force cursor to beginning of 1st line, if the number is 0x85 then force the cursor to 5th position
6
0xC0
Force cursor to beginning of 2nd line
7
0x1C
Shift the display to right side
8
0x02
Return Home
9
0x30
Configure LCD as 1-line 5x7 matrix

6. Keil c code for LCD interface with 8051 microcontroller:
/******************************************************************************************************************************/
//http://www.npeducations.com
//LCDwithDelay.c - implementing the 4-bit mode LCD interface with 89s52 microcontroller using delay
// Author - lovakiranvarma, (M.tech)
/******************************************************************************************************************************/
/********************************************** Header Files Declaration ******************************************************/
#include
#include
#include

/********************************************* LCD control signals declaration *************************************************/

sbit RS = P2^0;     // Register Select line
sbit RW = P2^1;  // Read/write line
sbit Enable = P2^2; // Enable line
sbit LED = P2^5;
#define LCD_PORT P1

/********************************************* LCD function prototypes *********************************************************/

void send_cmd(unsigned char);
void send_string(unsigned char*);
void delayms(unsigned int);
void send_Char(unsigned char);
void LCD_Init(void);

/********************************************* Main Funciton declaration *******************************************************/

void main()
{

P1 = 0x00;
P2 = 0x00;
/********************************************* LCD reset Process sequence as per datasheet***************************************/
delayms(15); // wait for more than 15ms after supply rises to 4.5V
send_cmd(0x30);
delayms(4);  // wait more than 4.1ms
send_cmd(0x30);
delayms(1);  // wait more than 100us, but delayms(1) will provide 1ms
send_cmd(0x30);
delayms(1);
send_cmd(0x02); // return to home
delayms(1);

LCD_Init();
   

 while(1)
 {
  send_cmd(0x80);       // Force cursor to beginning of 1st line, if the number is 0x85 then force the cursor to 5th position
  delayms(1);
  //send_Char('A');    // displays at first line
  //delayms(5);
  send_string("npeducations");  
  delayms(50);
  send_cmd(0xC0);       // Force cursor to beginning of 2nd line
  delayms(1);
  send_string("http://www.npeducations.com"); // displays at first line
  delayms(20);
  send_cmd(0x01);       // Force cursor to beginning of 2nd line
                        
 }

}

void LCD_Init()
{

 send_cmd(0x28);       // configuring LCD as 2 line 5x7 matrix in 4-bit mode
 delayms(1);
 send_cmd(0x0C);       // Display on, Cursor blinking
 delayms(1);
 send_cmd(0x01);       // Clear Display Screen
 delayms(1);
 send_cmd(0x06);       // Increment Cursor (Right side)
 delayms(1);

}


/*********************************************LCD Command Sending Function declaration*******************************************/

void send_cmd(unsigned char Command)
{
 unsigned char ch=0;

    LCD_PORT &= 0x00; // make upper bits of port as zero
 LCD_PORT =(Command);    //mask lower nibble and send upper nibble
 RS = 0;      // Select Command Register
 RW = 0;    // write operation
 Enable = 1;      // High to Low pulse provided on the enable pin with nearly 1ms(>450ns)
 delayms(1);
 Enable = 0;
 delayms(1);
 
 LCD_PORT &= 0x00; // make upper bits of port as zero
 
 LCD_PORT =(Command<<4); // upper nibble

 RS = 0;    // Select Data Register
 RW = 0;    // write operation
 Enable = 1;      // High to Low pulse provided on the enable pin with nearly 1ms(>450ns)
 delayms(1);
 Enable = 0;
 delayms(1);

}
/******************************************* LCD data sending Function declaration************************************************/

void send_string(unsigned char *String)
{
unsigned char i=0, ch=0, temp=0;

while(String[i]!='\0')
{
     
 temp = String[i++];

 LCD_PORT &= 0x00; // make upper bits of port as zero
 LCD_PORT = (temp);    //mask lower nibble and send upper nibble

 RS = 1;    // Select Data Register
 RW = 0;    // write operation
 Enable = 1;      // High to Low pulse provided on the enable pin with nearly 1ms(>450ns)
 delayms(1);
 Enable = 0;
 delayms(1);

 
 LCD_PORT &= 0x00; // make upper bits of port as zero
 
 LCD_PORT = ((temp<<4)); // lower nibble

 RS = 1;    // Select Data Register
 RW = 0;    // write operation
 Enable = 1;      // High to Low pulse provided on the enable pin with nearly 1ms(>450ns)
 delayms(1);
 Enable = 0;
 delayms(1);

 if(i>=16)
 send_cmd(0x1C);   
 delayms(100); 

}
 
 return;

}
/******************************************* LCD single character sending Function declaration************************************/

void send_Char(unsigned char character)
{
unsigned char ch=0;
             
 LCD_PORT &= 0x00; // make upper bits of port as zero
 LCD_PORT = (character);    //mask lower nibble and send upper nibble

 RS = 1;      // Select Command Register
 RW = 0;    // write operation
 Enable = 1;      // High to Low pulse provided on the enable pin with nearly 1ms(>450ns)
 delayms(1);
 Enable = 0;
 delayms(1);

 
 LCD_PORT &= 0x00; // make upper bits of port as zero
 
 LCD_PORT = ((character<<4)); // lower nibble
 RS = 1;    // Select Data Register
 RW = 0;    // write operation
 Enable = 1;      // High to Low pulse provided on the enable pin with nearly 1ms(>450ns)
 delayms(1);
 Enable = 0;
 delayms(1);

 delayms(100);
 

}

/******************************************* delayms Function declaration *******************************************************/
void delayms(unsigned int value)
{
 unsigned int i,j;
  
 for(i=0;i<=value;i++)
 {
  for(j=0;j<100;j++)
  _nop_();   // no operation produce 1us time delay
 }
 
}


7. Proteus simulation Circuit:

A Proteus simulation circuit output of LCD interface with 8051 microcontroller without using busy flag is shown in figure 1.3.
Figure 1.3 Proteus simulation circuit output of LCD interface with 8051 microcontroller in 4-bit mode without using busy flag


8. Assembly program:


30 comments :

  1. code for 4 bit is working. only following change
    [ _nop_(); ==> unsigned int b = 0;]

    ReplyDelete
    Replies
    1. hi kavita! did you face any problem with my code. Actually i placed this code after testing. it works fine for me. If any problems please reply me

      Delete
  2. Barbecue beef brisket is the national dish of the Republic of Texas. Here's the recipe for how to cook it the way the BBQ champions abd BBQ restaurants cook it. Learn how to grill Brisket steak in best weather now!

    ReplyDelete
  3. hello... as you said that There is a natural way to lose weight and it is a combination of diet and exercise. But don't you think that weight loss supplement or diet pills also helpful???

    ReplyDelete
  4. I have read you post, Great work you really did it very well. Keep working like this and sharing informative posts like
    this one. keep it up. I'm waiting for your next post...
    grimsby real estate

    ReplyDelete
  5. Great tips I have noted all in my diary I'll use your all tips as you mentioned I really like your article I was searching on this topic as I'm working on this topics too.you can see my work but yours is too good I personally appreciate you for this. Keep working like this.thatshirt.com/local/toronto

    ReplyDelete
  6. Really nice one.. Thanks Indian Movie for sharing this type of useful content..

    ReplyDelete
  7. The App was in the past known as TVTAP App UKTV Now will be presently refreshed and rebranded as TVTap.

    ReplyDelete
  8. Want some extra features on youtube app. Newpipe is there for your rescue. It offers all of original youtube and much more extra features. Go check it out.
    Also Cotomovies is an app that offers you free tv shows and movies to watch on your smart device. go check it out. Great post. Thanks for sharing.
    Newpipe apk CotoMovies Appflix

    ReplyDelete
  9. CotoMovies for Android offer latest CotoMovies for PC and unavoidable video content from various sources.

    ReplyDelete
  10. Tvtap proficient application serves you the best spouting foundation for Live TV on TVTAP PRO watching films, sports, and structure programs. Furthermore, the TvTap Pro progression free application gives you the stunning video nature of the customers

    ReplyDelete
  11. thank you so much i am waiting for your new post,you really did great work and very nice and useful information you can also check this

    ReplyDelete
  12. Here we will talk in purposes of enthusiasm of GB Whatsapp incorporates, downloading and acquainting method GBWhatsapp apk and how with use GB WhatsApp over the work territory

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Now we are offering the TVTap Apk for free for our users.

    ReplyDelete
  15. RedBox TV is a free live TV APK that offers you to watch your most cherished live TV channels at whatever point
    REDBOX TV APK This APK has more than 1000 channels from 15 unmistakable countries.

    ReplyDelete
  16. To exhibit the distant applications like CRowns Lite on an Android deal with, the central concern you ought to do is switch Crowns App on the elective Unknown Sources on the contraption.

    ReplyDelete
  17. The thought for which Pandora ONE Apk Mod is made was to make a different playlist of the radio station for individual Pandora clients with zero awful music. Pandora is a mechanized music suggestion application that offers music proposals for music like the one you pick pandora one apk

    ReplyDelete
  18. GBWhatsapp apk Download Latest Version 2018. Download Latest GB Whatsapp for Use 2 Whatsapp in One Mobile.  GBWhatsApp APK

    ReplyDelete
  19. 192.168.0.1 is a private IP address of IPv4 mastermind It's for the most part called host addresses in programming structuring 19216801

    ReplyDelete
  20. A remarkable opportunity to make your very own exceptional hostgator coupon encouraging errand by using most of the impeccable resources that HostGator propels.

    ReplyDelete
  21. Our vision is to build up a T – shirt plan and deals organization whose brand won't just be acknowledged in the United States of America, yet additionally in different parts of the world. eruthu T shirts

    ReplyDelete
  22. In case you are a substance creator, you possess into a person from the BlueStacks Affiliate stage and you can start getting money Bluestacks for PC for all substance where you talk about BlueStacks.

    ReplyDelete
  23. Thank you for this excellent read!! I definitely loved every little bit of it. Cheers for the information. This is the perfect blog for anyone who wants to know about this topic. You know so much it's almost hard to argue with you

    ReplyDelete
  24. hopefuls that are a solid match for the job and furthermore to consider competitors responsible on the off chance that they are not performing basic obligations that are required in the job. latest govt jobs

    ReplyDelete
  25. A few sites guarantee that a Russian gathering called Orphan Safe Communications is the engineer of freedom

    ReplyDelete

Thanks for visiting NPEDUCATIONS. We will contact you soon

30 comments :

kavita Rane said...

code for 4 bit is working. only following change
[ _nop_(); ==> unsigned int b = 0;]

Lovakiranvarma Myla said...

hi kavita! did you face any problem with my code. Actually i placed this code after testing. it works fine for me. If any problems please reply me

how to cook a brisket said...

Barbecue beef brisket is the national dish of the Republic of Texas. Here's the recipe for how to cook it the way the BBQ champions abd BBQ restaurants cook it. Learn how to grill Brisket steak in best weather now!

products said...

I really like this coding :)

mortgage & tax arrears said...

hello... as you said that There is a natural way to lose weight and it is a combination of diet and exercise. But don't you think that weight loss supplement or diet pills also helpful???

Julia Jhonson said...

I have read you post, Great work you really did it very well. Keep working like this and sharing informative posts like
this one. keep it up. I'm waiting for your next post...
grimsby real estate

Julia Jhonson said...

Great tips I have noted all in my diary I'll use your all tips as you mentioned I really like your article I was searching on this topic as I'm working on this topics too.you can see my work but yours is too good I personally appreciate you for this. Keep working like this.thatshirt.com/local/toronto

Best Game for US said...

Really nice one.. Thanks Indian Movie for sharing this type of useful content..

seetha mohan said...

The App was in the past known as TVTAP App UKTV Now will be presently refreshed and rebranded as TVTap.

Daku said...

Want some extra features on youtube app. Newpipe is there for your rescue. It offers all of original youtube and much more extra features. Go check it out.
Also Cotomovies is an app that offers you free tv shows and movies to watch on your smart device. go check it out. Great post. Thanks for sharing.
Newpipe apk CotoMovies Appflix

Pradeep Kumar said...

gb instagram apk
tvtap apk
spotify premium apk
sms bomber android app
kingroot apk
blackmart alpha apk

Unknown said...

It was an amazing read :)
Himalyan Trips
Himalayan Musafir
Himalayan Trips Holidays

deependra kumawat said...

CotoMovies for Android offer latest CotoMovies for PC and unavoidable video content from various sources.

thamaraiselvan s said...

Tvtap proficient application serves you the best spouting foundation for Live TV on TVTAP PRO watching films, sports, and structure programs. Furthermore, the TvTap Pro progression free application gives you the stunning video nature of the customers

NTS Test Result said...

thank you so much i am waiting for your new post,you really did great work and very nice and useful information you can also check this

Unknown said...

Here we will talk in purposes of enthusiasm of GB Whatsapp incorporates, downloading and acquainting method GBWhatsapp apk and how with use GB WhatsApp over the work territory

Roman Reigns said...
This comment has been removed by the author.
Roman Reigns said...

Now we are offering the TVTap Apk for free for our users.

mirrorworksdubai said...

RedBox TV is a free live TV APK that offers you to watch your most cherished live TV channels at whatever point
REDBOX TV APK This APK has more than 1000 channels from 15 unmistakable countries.

mirrorworksdubai said...

To exhibit the distant applications like CRowns Lite on an Android deal with, the central concern you ought to do is switch Crowns App on the elective Unknown Sources on the contraption.

homemadeelectric said...

The thought for which Pandora ONE Apk Mod is made was to make a different playlist of the radio station for individual Pandora clients with zero awful music. Pandora is a mechanized music suggestion application that offers music proposals for music like the one you pick pandora one apk

Mani Randhawa said...

GBWhatsapp apk Download Latest Version 2018. Download Latest GB Whatsapp for Use 2 Whatsapp in One Mobile.  GBWhatsApp APK

merrychristmasgif said...

192.168.0.1 is a private IP address of IPv4 mastermind It's for the most part called host addresses in programming structuring 19216801

seetha mohan said...

A remarkable opportunity to make your very own exceptional hostgator coupon encouraging errand by using most of the impeccable resources that HostGator propels.

terthutsh said...

Our vision is to build up a T – shirt plan and deals organization whose brand won't just be acknowledged in the United States of America, yet additionally in different parts of the world. eruthu T shirts

BlueStacks Download said...

In case you are a substance creator, you possess into a person from the BlueStacks Affiliate stage and you can start getting money Bluestacks for PC for all substance where you talk about BlueStacks.

Apartment Cleaning Services said...

Thank you for this excellent read!! I definitely loved every little bit of it. Cheers for the information. This is the perfect blog for anyone who wants to know about this topic. You know so much it's almost hard to argue with you

latgovtjobs said...

hopefuls that are a solid match for the job and furthermore to consider competitors responsible on the off chance that they are not performing basic obligations that are required in the job. latest govt jobs

subhasini laksh said...

A few sites guarantee that a Russian gathering called Orphan Safe Communications is the engineer of freedom

Daku said...

Know how to type degree symbol on any device Degree Symbol Mac Degree Symbol
Silent Ghost HD

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

If you really like this tutorial, Don't forget to give the comment or please subscribe to the RSS feed by submitting your E-mail or like our Facebook page.

 
Powered by Blogger