Following is the interfacing used between EFM32GG12 and 2x16 Alphanumeric LCD.
EN ----------> PA2
RS ----------> PA0
R/W ----------> PA1
D4 ----------> PE8
D5 ----------> PE9
D6 ----------> PE10
D7----------> PE11
The connectivity is shown below:
The left red board is MSP432P401R launch pad and right black board is EFM32GG12 Giant Gecko board from silicon Labs. 5V, Back light power to alphanumeric LCD are provided from MSP432P401R board.
Below is the sample code for initializing, writing command and data to LCD:
Configuring the pins of 2x16 Alphanumeric LCD:
//configuring the PA0 pin as output, PA0 shall be used to control RS pin
GPIO_PinModeSet(gpioPortA,0,gpioModePushPull,1);
//configuring the PA1 pin as output, PA0 shall be used to control R/W pin
GPIO_PinModeSet(gpioPortA,1,gpioModePushPull,1);
//configuring the PA2 pin as output, PA0 shall be used to control EN pin
GPIO_PinModeSet(gpioPortA,2,gpioModePushPull,1);
//configuring the PE8 pin as output, PE8 shall be used to control D4 pin
GPIO_PinModeSet(gpioPortE,8,gpioModePushPull,1);
//configuring the PE9 pin as output, PE9 shall be used to control D5 pin
GPIO_PinModeSet(gpioPortE,9,gpioModePushPull,1);
//configuring the PE10 pin as output, PE8 shall be used to control D6 pin
GPIO_PinModeSet(gpioPortE,10,gpioModePushPull,1);
//configuring the PE11 pin as output, PE11 shall be used to control D7 pin
GPIO_PinModeSet(gpioPortE,11,gpioModePushPull,1);
-----------------------------------------
Data to be input to LCD:
unsigned char str[20]={"Welcome to"};
unsigned char arr[20]={"Way2Know"};
-----------------------------------------
LCD intialization:
lcd_cmd(0x30);
delay(250);
lcd_cmd(0x30);
delay(250);
lcd_cmd(0x30);
delay(250);
lcd_cmd(0x20);
delay(250);
lcd_cmd(0x28); //4-bit mode, 2 Line, 5x7 dots
delay(250);
lcd_cmd(0x06);
delay(250);
lcd_cmd(0x01);
delay(250);
lcd_cmd(0x0F);
delay(250);
lcd_cmd(0x1);
delay(250);
lcd_cmd(0x80);
delay(250);
while(str[i]!='\0')
{
lcd_data(str[i]);
delay(250);
i++;
}
//lcd_cmd(0x1E); // Shift display to right
delay(10000);
//lcd_cmd(0x3C); //Activate Second line
delay(250);
lcd_cmd(0xC0); // Force cursor to beginning of 2nd line
delay(250);
for(j=0;arr[j]!='\0';j++)
{
lcd_data(arr[j]);
}
delay(250);
-----------------------------------------
LCD command write:
void lcd_cmd(unsigned char value)
{
unsigned char command;
//Sending upper nibble
command = value & 0xF0;
//pushing the command to LCD
GPIO_PortOutSetVal(gpioPortE, command<<4, 0x0F00);
//Clearing RS bit
GPIO_PinOutClear(gpioPortA, 0);
//Clearing RW bit
GPIO_PinOutClear(gpioPortA, 1);
//Setting EN bit
GPIO_PinOutSet(gpioPortA, 2);
delay(250);
//Clearing EN bit
GPIO_PinOutClear(gpioPortA, 2);
delay(250);
//Sending lower nibble
command = value & 0x0F;
//pushing the command to LCD
GPIO_PortOutSetVal(gpioPortE, command<<8, 0x0F00);
//Clearing RS bit
GPIO_PinOutClear(gpioPortA, 0);
//Clearing RW bit
GPIO_PinOutClear(gpioPortA, 1);
//Setting EN bit
GPIO_PinOutSet(gpioPortA, 2);
delay(250);
//Clearing EN bit
GPIO_PinOutClear(gpioPortA, 2);
delay(250);
}
-----------------------------------------
LCD Data Write:
void lcd_data(unsigned char value)
{
unsigned char data;
//Sending Upper Nibble
data = value & 0xF0;
//pushing the command to LCD
GPIO_PortOutSetVal(gpioPortE, data<<4, 0x0F00);
//Setting RS bit
GPIO_PinOutSet(gpioPortA, 0);
//Clearing RW bit
GPIO_PinOutClear(gpioPortA, 1);
//Setting EN bit
GPIO_PinOutSet(gpioPortA, 2);
delay(250);
//Clearing EN bit
GPIO_PinOutClear(gpioPortA, 2);
delay(250);
//Sending Lower Nibble
data = value & 0x0F;
//pushing the command to LCD
GPIO_PortOutSetVal(gpioPortE, data<<8, 0x0F00);
//Setting RS bit
GPIO_PinOutSet(gpioPortA, 0);
//Clearing RW bit
GPIO_PinOutClear(gpioPortA, 1);
//Setting EN bit
GPIO_PinOutSet(gpioPortA, 2);
delay(250);
//Clearing EN bit
GPIO_PinOutClear(gpioPortA, 2);
delay(250);
}
0 Comments