ARM LPC2138/48 Mini Development Board – LCD Interfacing
ARM LPC2138/48 Mini Development Board comes interfaced with an LCD module (2×16). Based on the number of data lines (4 or 8) used, LCD can work either in 4 or 8 bit mode. Here, the circuit is designed to work in 4-bit mode. Contrast can be adjusted by using the on-board potentiometer connected to pin3 of LCD. Control lines (RS, R/W ,E) are respectively connected to port pins P1.17, P1.18, P1.19 and data lines (D4-D7) to port pins P1.20, P1.21, P1.22 & P1.23.
Schematic
Sample Code
The sample code given below gives LCD display output ” RhydoLABZ ” in line 1 and “Cochin” in line 2 .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
/**************************************************************************** HEADER FILE *****************************************************************************/ #include<lpc21xx.h> #define RS 0x00020000 /* RS - P1.17 */ #define RW 0X00040000 /* R/W - P1.18 */ #define EN 0X00080000 /* E - P1.19 */ #define CLR 0X00FE0000 /**************************************************************************** * Function : PORT_Initial * * * * Description : Function for PORT Initialization * * * * Parameters : None * *****************************************************************************/ void PORT_Initial(void) { IO1DIR = 0x00FE0000; /* LCD pins set as o/p */ IO0DIR = 0x002F0000; PINSEL0 = 0x00000000; PINSEL1 = 0x05000000; PINSEL2 = 0x00000000; } /**************************************************************************** * Function : Delay * * * * Description : Function for Delay * * * * Parameters : x - Delay time * *****************************************************************************/ int Delay(unsigned int x) { x=x*8000; while(x!=0) { x--; } return 0; } /**************************************************************************** * Function : LCD_Command * * * * Description : Function to give command to LCD * * * * Parameters : command - command to be given * *****************************************************************************/ void LCD_Command(char command) { int Temp; IO1CLR = CLR; /* Clearing the port pins */ IO1SET = EN; /* Enable pin high */ IO1CLR = RS; /* RS=0 for command register */ IO1CLR = RW; /* R/W=0 for write */ Temp = (command & 0xF0) << 16; /* Taking the first nibble of command */ IO1SET = IO1SET | Temp; /* Writing it to data line */ Delay(2); IO1CLR = EN; /* Enable pin low to give H-L pulse */ } /**************************************************************************** * Function : LCD_Command1 * * * * Description : Function to give command to LCD * * * * Parameters : command1 - command to be given * *****************************************************************************/ void LCD_Command1(char command1) { int Temp; IO1CLR = CLR; /* Clearing the port pins */ IO1SET = EN; /* Enable pin high */ IO1CLR = RS; /* RS=0 for command register */ IO1CLR = RW; /* R/W=0 for write */ Temp = (command1 & 0xF0); /* Taking the first nibble of command */ Temp = Temp << 16; /* Shift it 16 bits to left */ IO1SET = IO1SET | Temp; /* Writing it to data line(P1.20-P1.23) */ Delay(2); IO1CLR = EN; /* Enable pin low to give H-L pulse */ IO1CLR = CLR; /* Clearing the port pins */ IO1SET = EN; /* Enable pin high */ IO1CLR = RS; /* RS=0 for command register */ IO1CLR = RW; /* R/W=0 for write */ Temp = (command1 & 0x0F); /* Taking the second nibble of command */ Temp = Temp << 20; /* Shift it 20 bits to left */ IO1SET = IO1SET | Temp; /* Writing it to data line */ Delay(2); IO1CLR = EN; /* Enable pin low to give H-L pulse */ } /**************************************************************************** * Function : LCD_Data * * * * Description : Function to display single character on LCD * * * * Parameters : data - Character to be displayed * *****************************************************************************/ void LCD_Data(char data) { int Temp; IO1CLR = CLR; /* Clearing the port pins */ IO1SET = EN; /* Enable pin high */ IO1SET = RS; /* RS=1 for data register */ IO1CLR = RW; /* R/W=0 for write */ Temp = (data & 0xF0); /* Taking the first nibble of data */ Temp = Temp << 16; /* Shift it 16 bits to left */ IO1SET = IO1SET | Temp; /* Writing it to data line */ Delay(2); IO1CLR = EN; /* Enable pin low to give H-L pulse */ IO1CLR = CLR; /* Clearing the port pins */ IO1SET = EN; /* Enable pin high */ IO1SET = RS; /* RS=1 for data register */ IO1CLR = RW; /* R/W=0 for write */ Temp = (data & 0x0F); /* Taking the second nibble of data */ Temp = Temp << 20; /* Shift it 20 bits to left */ IO1SET = IO1SET | Temp; /* Writing it to data line */ Delay(2); IO1CLR = EN; /* Enable pin low to give H-L pulse */ } /**************************************************************************** * Function : LCD_String * * * * Description : Function to display string on LCD * * * * Parameters : String to be displayed * *****************************************************************************/ void LCD_String(unsigned char *dat) { while(*dat!='\0') /* Check for termination character */ { LCD_Data(*dat); /* Display the character on LCD */ dat++; /* Increment the pointer */ } } /**************************************************************************** * Function : LCD_Init * * * * Description : Function to initialize LCD * * * * Parameters : None * *****************************************************************************/ void LCD_Init(void) { Delay(15); LCD_Command(0x30); Delay(10); LCD_Command(0x30); Delay(5); LCD_Command(0x30); LCD_Command(0x20); LCD_Command1(0x28); LCD_Command1(0x01); /* Clear display */ LCD_Command1(0x06); /* Auto increment */ LCD_Command1(0x0C); /* Cursor off */ } /**************************************************************************** MAIN FUNCTION *****************************************************************************/ int main() { PORT_Initial(); /* Initialize port */ LCD_Init(); /* Initialize LCD */ LCD_String(" RhydoLABZ "); LCD_Command1(0xC0); /* 2nd row, 1st location */ LCD_String(" Cochin "); while(1); } /**************************** END OF PROGRAM ******************************/ |
Topics related to ARM LPC2138/4848 Mini Development Board
- ARM LPC2138/48 Mini Development Board – Overview
- ARM LPC2138/48 Mini Development Board – LED Interfacing
- ARM LPC2138/48 Mini Development Board – LCD Interfacing
- ARM LPC2138/48 Mini Development Board – UART0 Interfacing
- ARM LPC2138/48 Mini Development Board – UART1 Interfacing
- ARM LPC2138/48 Mini Development Board – Switches Interfacing
- ARM LPC2138/48 Mini Development Board – BUZZER Interfacing
- ARM LPC2138/48 Mini Development Board – POT Interfacing (ADC)
- ARM LPC2138/48 Mini Development Board – Temperature Sensor Interfacing(ADC)
- ARM LPC2138/48 Mini Development Board – Interfacing Servo motor
- ARM LPC2138/48 Mini Development Board – Internal Real Time Clock (RTC)
- ARM LPC2148 Mini Development Board – USB Interfacing (Human Interface Device)
Resources
- Softwares
- Datasheets
How to buy?
- Click here to buy rhydoLABZ ARM LPC2129 Development board-Mini
- Click here to buy rhydoLABZ ARM LPC2138 Development Board-Mini
- Click here to buy rhydoLABZ ARM LPC2148 Development Board-Mini
Support
Please share your ideas with us, visit our forum for discussion
Leave a Reply
You must be logged in to post a comment.