Difference between revisions of "ARM Interfacing : Graphic LCD"
m |
m |
||
Line 37: | Line 37: | ||
*step4: Send a High-to-Low pulse on Enable PIN with some delay_us. | *step4: Send a High-to-Low pulse on Enable PIN with some delay_us. | ||
<html> | <html> | ||
− | <script src="https://gist.github.com/Amritach/ | + | <script src="https://gist.github.com/Amritach/9805fb05ece462313c7b.js"></script> |
</html> | </html> | ||
Revision as of 14:54, 30 May 2015
Amruta (talk) 13:21, 17 March 2015 (IST)
Contents
[hide]Basics
If you have done with simple 16x2 LCD and still want to do more with display, its time to have fun with Graphics LCD.
We all really enjoy animations kind of things and this is the stuff what we can do with GLCD.
GLCD is very similar to simple 16x2 LCD with additional features. To explore these features and functionality you would like to see our tutorial Graphics LCD Basics : KS0108 based JHD12864E
Schematic
Port Connection
This section shows how to configure the GPIO for interfacing the GLCD.
The below configuration is as per the above schematic. You can connect the GLCD to any of the PORT pins available on your boards and update this section accordingly
/* Configure the data bus and Control bus as per the hardware connection */ | |
#define GlcdDataBusPort LPC_GPIO1->FIOPIN | |
#define GlcdControlBusPort LPC_GPIO2->FIOPIN | |
#define GlcdDataBusDirnReg LPC_GPIO1->FIODIR | |
#define GlcdCtrlBusDirnReg LPC_GPIO2->FIODIR | |
#define GLCD_D0 20 | |
#define GLCD_D1 21 | |
#define GLCD_D2 22 | |
#define GLCD_D3 23 | |
#define GLCD_D4 24 | |
#define GLCD_D5 25 | |
#define GLCD_D6 26 | |
#define GLCD_D7 27 | |
#define GLCD_RS 0 | |
#define GLCD_RW 1 | |
#define GLCD_EN 2 | |
#define GLCD_CS1 3 | |
#define GLCD_CS2 4 |
GLCD Operation
In this section we are going to see how to send the data/cmd to the GLCD along with the timing diagrams. First lets see the timing diagram for sending the data and the command signals(RS,RW,EN), accordingly we write the algorithm and finally the code.
Timing Diagram
The below image shows the timing diagram for sending the data to the LCD.
As shown in the timing diagram the data is written after sending the RS and RW signals. It is still ok to send the data before these signals.
The only important thing is the data should be available on the databus before generating the High-to-Low pulse on EN pin.
Steps for Sending Command:
- step1: Send the I/P command to GLCD.
- step2: Select the Control Register by making RS low.
- step3: Select Write operation making RW low.
- step4: Send a High-to-Low pulse on Enable PIN with some delay_us.
/* Function to send the command to LCD */ | |
void Glcd_CmdWrite(char cmd) | |
{ | |
sendByte(cmd); //Send the command | |
GlcdControlBusPort &= ~(1<<GLCD_RS); // Send LOW pulse on RS pin for selecting Command register | |
GlcdControlBusPort &= ~(1<<GLCD_RW); // Send LOW pulse on RW pin for Write operation | |
GlcdControlBusPort |= (1<<GLCD_EN); // Generate a High-to-low pulse on EN pin | |
delay(1000); | |
GlcdControlBusPort &= ~(1<<GLCD_EN); | |
delay(10000); | |
} |
Steps for Sending Data:
- step1: Send the character to GLCD.
- step2: Select the Data Register by making RS high.
- step3: Select Write operation making RW low.
- step4: Send a High-to-Low pulse on Enable PIN with some delay_us.
The timings are similar as above only change is that RS is made high for selecting Data register.
/* Function to send the data to GLCD */ | |
void Glcd_DataWrite(char dat) | |
{ | |
sendByte(dat); //Send the data | |
GlcdControlBusPort |= (1<<GLCD_RS); // Send HIGH pulse on RS pin for selecting data register | |
GlcdControlBusPort &= ~(1<<GLCD_RW); // Send LOW pulse on RW pin for Write operation | |
LcdControlBusPort |= (1<<GLCD_EN); // Generate a High-to-low pulse on EN pin | |
delay(1000); | |
GlcdControlBusPort &= ~(1<<GLCD_EN); | |
delay(10000); | |
} |
Code
To display text
Let's start with displaying some text.
- #include "lpc17xx.h" // Device specific header file
- #include "glcd.h" // Explore Embedded GLCD library
- /*start of the main program*/
- int main()
- {
- /* Setup and initialize the microcontroller */
- SystemInit();
- /* Initialize the GLCD before use*/
- GLCD_Init();
- /*Display some data on GLCD*/
- GLCD_Printf("Wel-Cometo ARM Programming\n");
- GLCD_Printf("\n~~****~~****~~");
- GLCD_Printf("\n~~****~~****~~\n");
- GLCD_Printf("\nLet's have fun with GLCD");
- while(1);
- }
Lots of things are there which you would like to do with GLCD and we will cover it in the future tutorials. For now, you don't forget to comment.