This post will provide a tutorial of how to interface LCD 16x2 or 20x4 with PIC32 microcontroller. You may download code and schematic from the download section at the bottom of this page. I am using custom designed PIC32 I/O board in this particular example for simulating code practically. The code is written in C language using XC32 compiler and MPLAB X IDE. PIC32 is running at 80MHz on its Maximum performance.
In this post I supposed that you must know following if not then please read them before proceeding further:
As mentioned above you may download code and schematic from the download section at the bottom of this page. I am using MPLAB X IDE, XC32 Compiler. This code is written in C Language and will work on all PIC32 (32bit microcontroller by Microchip) by slightly changing the code according to their features.
I have an external high speed crystal of 8MHz and my system clock is adjusted to 80MHz using PLL multipliers by setting appropriate configuration bits.
As this microcontroller is not available for simulation in Proteus, therefore I go for practical simulation. So this is my custom designed PIC32 I/O board with all necessary components on board and has a very small footprint as compare to my pervious DsPIC33 I/Oboard. I am using PIC32MX460F256L in this particular example. In this PIC32 I/O board I have placed a 16 pin connector at one side of this board to interface LCD which is directly one to one connected to LCD. Remember that LCD is working on 5.0VDC and PIC32 is working on 3.3VDC. But I didn’t use level shifter or level translators. I used my brain and put a smart solution over here. I connected LCD Power and Backlight pins to 5.0VDC and all data pins and control pins directly to PIC32. This solution is working perfectly hence I am able to eliminate the need of level shifters. But remember that I used 5.0VDC tolerant pins. So I connected data pins to lower 8 bits of PORTE while enable pin is connected to RG12 and RS pin is connected to RG13. In the following figure I have an LCD display with my PIC32 I/O board
|Figure 1. LCD with PIC32 I/O Board.|
As mentioned earlier in this post the code is written in C language using MPLAB X IDE and XC compiler and can be downloaded from the downloads section at the bottom of this page. In the following figure 2. We have a main C file in which I first configure the system to its maximum performance without overclocking my PIC32. The function named “SYSTEMConfig()” is used to do this. Then I called a function named “Initialize_LCD()”. This function initializes the LCD. Which is explained later in this post. Then I moved the cursor and displayed some strings on four lines one by one.
|Figure 2. main function LCD interfacing with PIC32.|
In the following figure 3. I defined some macros, Pins and PORTs in “LCD.h”. You may go through the details of them in my previous post about Core Timers.
|Figure 3. #defines for LCD function.|
In the following figure 4. We have a function named “Initialize_LCD()” responsible of initialing LCD data and control pins direction as well as configure LCD by sending commands for Function set, Display shifting OFF, Blink OFF and Cursor OFF etc.
|Figure 4. Initialize LCD function.|
In the following figure 5. We have a function to toggle LCD Enable pin every time that the data or command is written to Data bus of LCD as mentioned in datasheet of LCD.
|Figure 5. toggling Enable function LCD interfacing with PIC32.|
In the following figure 6. We have two functions one is to send command to LCD in which RS pin is cleared. And second function is for sending data that we want to display them on LCD in which RS pin is set.
|Figure 6. Data and command send functions LCD interfacing with PIC32.|
The schematic with code is also available for download, in the download section. In this schematic some of the basic connections recommended for running this code are shown in the following figure 7.
|Figure 7. Schematic LCD interfacing with PIC32.|
You can download Code (MPLAB X and XC32 compiler Schematic is also given). Click here
For all topics Click here:
That’s all for this post hope you will learn please comment if you have any questions for upcoming posts please subscribe or follow.
All the text and graphics contained on this blog belongs to owner except otherwise mentioned. Other parties' trademarks and service marks that may be referred to herein are the property of their respective owners. Reproducing or distributing text and graphics on your own site is strictly not allowed without proper linking to original content and before publishing that you should ask for permission.
© Copyright 2013 IbrahimLabs. All rights reserved.