![]() Void msdelay(unsigned int time) // Function for creating delay in milliseconds. Sbit e = P3^4 //E pin connected to pin 4 of port 3 Sbit rw = P3^3 // RW pin connected to pin 3 of port 3 Sbit rs = P3^2 //RS pin connected to pin 2 of port 3 #define display_port P2 //Data pins connected to port 2 on microcontroller Program for LCD Interfacing with 8051 Microcontroller (AT89S52) We have used the lcd_init() function to get the LCD ready by using the preset command instructions (explained above). Function msdelay() has been created to create delay in milliseconds and called frequently in the program, it is called so that LCD module can have sufficient time to execute the internal operation and commands.Ī while loop has been created to print the string, which is calling the lcd_data function each time to print a character until the last character (null terminator- ‘\0’). Also when sending data (function lcd_data) to LCD we have set RS=1, RW=0 and a HIGH to LOW pulse is given to E by making it 1 to 0. I have tried to explain the code through comments (in code itself).Īs I have explained earlier about command mode and data mode, you can see that while sending command (function lcd_cmd) we have set RS=0, RW=0 and a HIGH to LOW pulse is given to E by making it 1, then 0. Middle leg of the variable resistor is connected to PIN 3 and other two legs are connected to voltage supply and Ground. Pin 3(V0) is connected to voltage (Vcc) through a variable resistor of 10k to adjust the contrast of LCD. PIN 2(VDD) and PIN 15(Backlight supply) of LCD are connected to voltage (5v), and PIN 1 (VSS) and PIN 16(Backlight ground) are connected to ground. And control pins RS, RW and E to the pin 12,13,14 (pin 2,3,4 of port 3) of microcontroller respectively. So besides these above pins we have connected the data pins (D0-D7) of LCD to the Port 2 (P2_0 – P2_7) microcontroller. If you don’t have any idea about that then I recommend you to read this Article LED Interfacing with 8051 Microcontroller before going through LCD interfacing. Some important command instructions are given below:Ĭircuit diagram for LCD interfacing with 8051 microcontroller is shown in the above figure. If you have basic understanding of 8051 then you must know about EA(PIN 31), XTAL1 & XTAL2, RST pin(PIN 9), Vcc and Ground Pin of 8051 microcontroller. There are some preset command instructions in LCD, we have used them in our program below to prepare the LCD (in lcd_init() function). That transition from HIGH to LOW makes the module ENABLE. ![]() Only one instruction “Get LCD status”, need to be read some times.Į: This pin is used to enable the module when a high to low pulse is given to it. Generally this is set to 0, because we do not have need to read data from LCD. And set it to 1, if we are reading from LCD module. ![]() RW: This is Read/write pin, we will set it to 0, if we are going to write some data on LCD. And we will set it to 0 if we are sending some command instruction like clear the screen (hex code 01). We need to set it to 1, if we are sending some data to be displayed on LCD. We can divide it in five categories, Power Pins, contrast pin, Control Pins, Data pins and Backlight pins.Ĭontrast Setting, connected to Vcc thorough a variable resistor.Įnable, a high to low pulse need to enable the LCDĭata Pins, Stores the Data to be displayed on LCD or the command instructionsĪll the pins are clearly understandable by their name and functions, except the control pins, so they are explained below: So first let's understand the 16 pins of LCD module. Although it may be time taking because you need to understand and connect 16 pins of LCD to the microcontroller. Interfacing LCD with 8051 microcontroller might look quite complex to newbies, but after understanding the concept it would look very simple and easy. In this tutorial we are going to connect 16X2 LCD module to the 8051 microcontroller (AT89S52). 16x2 LCD means that there are two rows in which 16 characters can be displayed per line, and each character takes 5X7 matrix space on LCD. ![]() 16x2 LCD is one of the most used display unit. Display units are the most important output devices in embedded projects and electronics products.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |