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 8-bit mode without using busy status flag


1. Introduction LCD interface:

Interfacing 16x2 character LCD with 8051 microcontroller is simple and easy. There are two modes that 16x2 LCD can operate. 8-bit mode uses eight data lines and three control lines whereas 4-bit mode uses four data lines and two or three control lines. In this tutorial, 16x2 LCD interfaced with 8051 microcontroller in 8-bit mode without using any hardware busy status check. In 8-bit mode LCD interface, the data or command transferred via 8-bit bus lines of LCD (D0-D7).

2. Hardware interface with 8051 Circuit:


Figure 1.1 Circuit diagram of LCD interface with 8051 in 8-bit mode




In the above figure, the port0 of the 8051 microcontroller is connected to data lines (D0-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 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 sensitive). The 1k resistor is connected in series with 10k preset, which will limit the maximum current flow when the preset value is at its minimum position. A reset circuit made up of resistor and capacitor 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. A clock circuit of 12Mhz with two 33pF capacitors are connected at the XTAL1 and XTAL2 pins.

3. LCD interface timing diagrams:

In this tutorial we are not using any busy status flag, means no read operations. Hence only write operation timing diagrams are shown in figure 1.2.


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


The above timing diagram shows four signals (ENABLE, RS, R/W, D0-D7), with two types of information on the LCD bus lines.

1.      Command
2.      Data byte

The RS and R/W signals must be low while Command is sent to LCD, whereas during data byte transmission the RS signal must be high and R/W must be low as shown in the figure.
When command or data is sent to the LCD, it takes some time to process it internally. Hence, the microcontroller should wait N milliseconds and then send next command or data, for this purpose a delay of N milliseconds is introduced between each command or data byte transmission. Here, I have taken 100milliseconds time as delay between each byte transmission.
The main disadvantage of this procedure is unnecessary wastage of CPU or MCU time, why because there is no exact time 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:

There are two functions are implemented in embedded c (keil c).

    Send_cmd() à  this function sends  command  to LCD controller (HD44780U) in hexadecimal. When   command is to be written into LCD, the RS and R/W lines both should be at logic low and high to low strobe must be given at enable pin with enable pulse width greater than 450ns. The enable cycle time must be greater than 1000ns.

      Send_data() à this function sends string of characters to LCD controller, during which the RS should be at logic high and R/W should be at logic low. A high to low strobe must be given at enable pin (pulse width should be >450ns). This function is written in such a way that, when the number of characters in a string is greater than display size (> 16 characters) then it automatically right shifts the display.

      Send_char() à this function sends a single character at a time to LCD controller by making RS=1 and R/W =0. The negative edge (High to Low) triggering should be applied at enable pin.

   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.

     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.




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
0x38
Configuring LCD as 2 line 5x7 matrix
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
Table 1.1 list of  Basic LCD commands


6. 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 without using busy flag




7. Keil c code for LCD interface with 8051 microcontroller:
 
/***************************************************************************************************************************/
// http://www.npeducations.com
// LCDwithDelay.c - implementing the LCD interface in 8-bit mode 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
#define LCD_PORT P0 // define port

/********************************************* LCD function prototypes ************************************************/
void send_cmd(unsigned char);
void send_data(unsigned char*);
void send_char(unsigned char);
void LCD_init(void);
void delayms(unsigned int);
/********************************************* Main Funciton declaration ***********************************************/
void main()
{

LCD_PORT = 0x00; // Make the port as output port
  
 LCD_init();            // LCD initialization
 
 while(1)
 {
  send_cmd(0x83);     // Force cursor to beginning of 1st line, if the number is 0x83 then force the cursor to 53rd position
  delayms(100);    // Delay of 100millisec
  send_data("NPEDUCATIONS");  // Send data string
  delayms(500);    // Delay of 0.5sec
  send_cmd(0xC0);     // Force cursor to beginning of 2nd line
  delayms(100);    // Delay of 100millisec
  send_data("http://www.npeducations.com"); // send data string
  delayms(500);    // Delay of 0.5sec
  send_cmd(0x01);     // Clear display
  delayms(100);    // Delay of 100millisec
  send_cmd(0x80);    // Force cursor to beginning of 1st line
  delayms(100);    // Delay of 100millisec
  send_char('A');    // testing send_char position
  delayms(500);    // Delay of 0.5sec
  send_cmd(0x01);     // Clear display
  delayms(100);    // Delay of 100millisec
                        
 }

}


/********************************************* LCD Initialization Function declaration ********************************/

void LCD_init()
{
 send_cmd(0x38);      // configuring LCD as 2 line 5x7 matrix
 send_cmd(0x0E);      // Display on, Cursor blinking
 send_cmd(0x01);      // Clear Display Screen
 send_cmd(0x06);      // Increment Cursor (Right side)
}

void send_char(unsigned char character)
{
 LCD_PORT = character;
 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);   // 1 millisec delay
 Enable = 0;
 delayms(100);   // 100 millisec delay
 

}


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

void send_cmd(unsigned char Command)
{
 LCD_PORT = Command;
 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);   // 1 millisec delay
 Enable = 0;

}

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

void send_data(unsigned char *String)
{
unsigned char i=0;

 while(String[i]!='\0')
 {
     
  LCD_PORT = String[i++];
  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);   // 1 millisec delay
  Enable = 0;
  if(i>=16)   // If the number of characters in the string > 16, then the below command automatically 
  send_cmd(0x1C);  // Shift the display right side 
  delayms(100);   // 100 millisec delay
 }
 
}

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

OUTPUT on 16x2 LCD:



14 comments :

  1. Can you please send me your code regarding the interface with display with RS232? The one that you showed your website URL on the display.
    I appreciate.

    Henri

    henriaghaei@gmail.com

    ReplyDelete
  2. 125 lines of coding! cool why not use bascom, hardly 10 lines required for the output.

    ReplyDelete
  3. Config Lcdpin = Pin , Db4 = P2.4 , Db5 = P2.5 , Db6 = P2.6 , Db7 = P2.7 , E = P2.3 , Rs = P2.2
    Do
    Cls
    Lcd "Hi Vishal"
    Lowerline
    Lcd "How are you"
    Wait 1
    Loop

    ReplyDelete
  4. Kite projects Is providing construction, engineering and facilities management to provide edge protection, vertical access and hand railing solutions to Industries in United Kingdom!

    ReplyDelete
  5. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you.best travel nurse companies

    ReplyDelete
  6. Using a stocks tip list like this is a smart move to make if you are inexperienced or don’t have the time to put towards analytics yourself like hardly any of us do.washing machine repairs perth

    ReplyDelete
  7. Guys please share with us your new post… I hope you shared with us your new posting... This post is also really good but we still waiting your new post.nightgale

    ReplyDelete
  8. I love reading through a post that will make men and women think. Also, thanks for allowing me to comment!pre-tied bow ties

    ReplyDelete
  9. This is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog

    ReplyDelete
  10. The purpose of giving gifts is to bring joy to both the giver and receiver, promote goodwill, and make for a closer relationship.san francisco sql training class

    ReplyDelete
  11. This type of blare is often a well known shade so that you can apprehend so that you can events.minneapolis wordpress developer

    ReplyDelete
  12. A new triumphant swimming kitty condition wish to be summit survey too numerous perquisite.Lithium polymer battery

    ReplyDelete
  13. Truly impressive article. This type of wonderful assortment of new thoughts. I'll certainly return. Thanks for sharing ideas.wdi reports

    ReplyDelete
  14. this post is awesome, great msg for us, plz update ur blog for daily basis, i am regular visitor of this site, so keep posting for us.thanks click the below links to create backlink:-40 year mortgage

    ReplyDelete

Thanks for visiting NPEDUCATIONS. We will contact you soon

14 comments :

Henri Aghaei said...

Can you please send me your code regarding the interface with display with RS232? The one that you showed your website URL on the display.
I appreciate.

Henri

henriaghaei@gmail.com

Vishal kumar said...

125 lines of coding! cool why not use bascom, hardly 10 lines required for the output.

Vishal kumar said...

Config Lcdpin = Pin , Db4 = P2.4 , Db5 = P2.5 , Db6 = P2.6 , Db7 = P2.7 , E = P2.3 , Rs = P2.2
Do
Cls
Lcd "Hi Vishal"
Lowerline
Lcd "How are you"
Wait 1
Loop

materials said...

Kite projects Is providing construction, engineering and facilities management to provide edge protection, vertical access and hand railing solutions to Industries in United Kingdom!

best travel nurse companies said...

I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you.best travel nurse companies

washing machine repairs perth said...

Using a stocks tip list like this is a smart move to make if you are inexperienced or don’t have the time to put towards analytics yourself like hardly any of us do.washing machine repairs perth

nightgale said...

Guys please share with us your new post… I hope you shared with us your new posting... This post is also really good but we still waiting your new post.nightgale

pre-tied bow ties said...

I love reading through a post that will make men and women think. Also, thanks for allowing me to comment!pre-tied bow ties

personalized t shirts canada said...

This is just the information I am finding everywhere. Thanks for your blog, I just subscribe your blog. This is a nice blog

san francisco sql training class said...

The purpose of giving gifts is to bring joy to both the giver and receiver, promote goodwill, and make for a closer relationship.san francisco sql training class

minneapolis wordpress developer said...

This type of blare is often a well known shade so that you can apprehend so that you can events.minneapolis wordpress developer

Lithium polymer battery said...

A new triumphant swimming kitty condition wish to be summit survey too numerous perquisite.Lithium polymer battery

wdi reports said...

Truly impressive article. This type of wonderful assortment of new thoughts. I'll certainly return. Thanks for sharing ideas.wdi reports

40 year mortgage said...

this post is awesome, great msg for us, plz update ur blog for daily basis, i am regular visitor of this site, so keep posting for us.thanks click the below links to create backlink:-40 year mortgage

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.
Related Posts Plugin for WordPress, Blogger...

 
Powered by Blogger