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 using busy status flag


1. Introduction LCD interfaces using busy status flag:

In this tutorial, LCD is interfaced to 8051 microcontroller using busy status flag. The advantage of using busy status flag method is there is no wastage of CPU time which is pre-dominant in other method. Here the LCD busy status flag will pull low during the internal processing of command or data, after completion of internal operation the status flag brings back to high. The microcontroller monitors the busy flag continuously, whenever it goes high then it will send the next byte to LCD.

2. Hardware interface with 8051 Circuit:

Figure1.1 LCD Hardware interface with 8051 circuit


In the above figure, the data lines (D7-D0) are connected to port0 with 10k pull up resistors, since in 8051 microcontroller the port0 pins are open collector configuration. You may use 4.7k – 10k pull ups as per datasheet. A power on reset circuit is designed with a capacitor and resistor whose values are C = 10uF and R = 10K. The power on reset circuit are provides some time for both power supply and oscillator are stabilized. The power on reset circuit is also useful when the supply voltage drops below the required, then automatically a reset is applied to the circuit. A preset is connected at pin3 of LCD to vary the contrast of LCD; the 1k resistor protects the LCD by not allowing large current when the preset is at its minimum value.
The control pins (Enable, R/W, RS) of the LCD are connected to port2 of the 8051 MCU (P2.2, P2.1, P2.0) respectively. The busy status of LCD is taken from the D7 line as shown in figure 1.1. During write operation the D7 pin acts as simple data line, whereas for read operation it provides the status of the LCD i.e., whether the LCD controller (HD44780) performing internal operation or not. If LCD completes the internal operation, the D7 pin goes LOW otherwise it is in logic HIGH. To get the busy status, the RS line should be low (RS = 1) and R/W should be high (R/W = 1).
Remember the LCD will not accept any instructions (commands) or data while it is performing internal operations. For this purpose, MCU check the busy flag state of LCD to know whether it completes internal operations or not. There is another method that MCU should wait certain amount of time until the LCD completes the internal operations, that’s we introduce some random delay after each command or data is sent. This method is not much efficient when comparing with busy status flag checking method, why because there is some wastage of CPU time will occur by introducing delay after each command or data.
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 using busy flag shows the no wastage of CPU time. 


C code to interface LCD to 8051 using busy flag
/**********************************************************************************************************************************/
// http://www.npeducations.com
//LCDwithDelay.c - implementing the LCD interface with 89s52 microcontroller using busy flag status
//author - lovakiranvarma
/**********************************************************************************************************************************/

/********************************************** Header Files Declaration *********************************************************/
#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;
sbit Busy_Flag = P2^3;

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

void send_cmd(unsigned char);
void send_String(unsigned char*);
void send_Char(unsigned char character);
void delayms(unsigned int);
void lcd_BusyCheck(void);
void lcd_ScrollData(unsigned char NumberOfTimes, unsigned char strlength);


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

void main()
{

P0 = 0x00;        // make P0 as output port

/********************************************* LCD initialization ***************************************************/
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)



 while(1)
 {
  send_cmd(0x83);       // Force cursor to beginning of 1st line, if the number is 0x85 then force the cursor to 5th position
  send_String("NPEDUCATIONS");    // displays at first line
  delayms(100);
  lcd_ScrollData(5,12);      // Scroll the text "npeducations" for 5 times
  delayms(100);
  send_cmd(0xC0);          // Force cursor to beginning of 2nd line
  send_String("http://www.npeducations.com"); // displays at first line
  delayms(100);
  send_cmd(0x01);         // Clear Display Screen
  
                    
 }

}


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

void send_cmd(unsigned char Command)
{
 P0 = Command;
 lcd_BusyCheck();
 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;

}

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

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

while(String[i]!='\0')
{
     
 P0 = String[i++];
 lcd_BusyCheck();
 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;
 if(i>=16)     // the following three instructions will shift the display right if the 
 send_cmd(0x1C);    //number of characters more than the 16(not fit on the screen)
 delayms(150); 


}
 
return;

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

void send_Char(unsigned char character)
{
             
 P0 = character;
 lcd_BusyCheck();
 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;
 return;

}

/********************************************* LCD Scrolling Function ******************************************************/
void lcd_ScrollData(unsigned char NumberOfTimes, unsigned char strlength)
{
unsigned char i;
send_cmd(0x02);

 while(NumberOfTimes>0) // scroll the text for given number of times
 {
  delayms(10);
  for(i=16-strlength;i>0;i--)
  {
   delayms(50);
   send_cmd(0x1C);   // left Shift 
  }
  delayms(10);

  for(i=16-strlength;i>0;i--)
  {
   delayms(50);
   send_cmd(0x18);   // Right Shift
  }

  
  
  NumberOfTimes--;
 }
}

/******************************************* BusyCheck Function declaration***********************************************/
void lcd_BusyCheck()
{
 Busy_Flag = 1;
 RS = 0;
 RW = 1;
 while(Busy_Flag == 1)
 {
  Enable = 0;
  delayms(1);
  Enable = 1;
 }

}

/******************************************* delayms Function declaration***********************************************/
void delayms(unsigned int value)
{
 unsigned int i,j;
 for(i=0;i<=value;i++)
 {
  for(j=0;j<100 data-blogger-escaped-j="j" data-blogger-escaped-pre="pre">

0 comments :

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

0 comments :

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