/* Program to flash "HELLO" on LCD on Wytec EduBase/EduPad board * with Tiva TM4C123/MSP432. * The LCD controller is connected parallel in 4-bit data mode. * The connections are: * Pin 18 - Register select * Pin 35 - Enable * Pins 8, 13, 12, 11 - data 7-4 * Make sure the LCD interface selection jumper is set at "parallel". * * Energia 1.6.10E18 */ const int REG_SEL = 18; const int ENABLE = 35; const int D4 = 11; const int D5 = 12; const int D6 = 13; const int D7 = 8; const int dataBus[] = {D4, D5, D6, D7}; const int RS = 1; void setup() { LCD_init(); } void loop() { // Write "HELLO" on LCD LCD_data('H'); LCD_data('E'); LCD_data('L'); LCD_data('L'); LCD_data('O'); delay(1000); // clear LCD display LCD_command(1); delay(1000); } void LCD_init(void) { pinMode (REG_SEL, OUTPUT); pinMode (ENABLE, OUTPUT); digitalWrite(ENABLE, LOW); // Enable idles low pinMode (D4, OUTPUT); pinMode (D5, OUTPUT); pinMode (D6, OUTPUT); pinMode (D7, OUTPUT); // LCD controller reset sequence delay(20); LCD_nibble_write(0x30, 0); delay(5); LCD_nibble_write(0x30, 0); delay(1); LCD_nibble_write(0x30, 0); delay(1); LCD_nibble_write(0x20, 0); // use 4-bit data mode delay(1); LCD_command(0x28); // set 4-bit data, 2-line, 5x7 font LCD_command(0x06); // move cursor right LCD_command(0x01); // clear screen, move cursor to home LCD_command(0x0F); // turn on display, cursor blinking } // write 4 bits to LCD controller void LCD_nibble_write(char data, unsigned char select) { digitalWrite(REG_SEL, select ? HIGH : LOW); digitalGroupWrite(dataBus, 4, data >> 4); digitalWrite(ENABLE, HIGH); delayMicroseconds(1); digitalWrite(ENABLE, LOW); } // write a command to LCD controller void LCD_command(unsigned char command) { LCD_nibble_write(command & 0xF0, 0); // upper nibble first LCD_nibble_write(command << 4, 0); // then lower nibble if (command < 4) delay(2); // command 1 and 2 needs up to 1.64ms else delayMicroseconds(40); // all others 40 us } // write a byte of data to LCD controller // since the connection is 4-bit, it takes two writes for a byte void LCD_data(char data) { LCD_nibble_write(data & 0xF0, RS); // upper nibble first LCD_nibble_write(data << 4, RS); // then lower nibble delayMicroseconds(40); } // write to a group of output pins void digitalGroupWrite(const int* group, int length, int data) { for (int i = 0; i < length; i++) digitalWrite(group[i], data & (1 << i) ? HIGH : LOW); }