Tutorial.LCD8Bits History

Show minor edits - Show changes to markup

November 22, 2008, at 06:32 PM by David A. Mellis -
Added lines 1-2:
October 18, 2005, at 02:00 AM by 195.178.229.25 -
Changed lines 1-121 from:

http://static.flickr.com/25/53544993_3611fce234_o.jpg

to:

LCD Display - 8 bits

This example shows the most basic action to be done with a LCD display: to show a welcome message. In our case we have an LCD display with backlight and contrast control. Therefore we will use a potentiometer to regulate the contrast.

LCD displays are most of the times driven using an industrial standard established by Hitachi. According to it there is a group of pins dedicated to sending data and locations of that data on the screen, the user can choose to use 4 or 8 pins to send data. On top of that three more pins are needed to synchronize the communication towards the display.

The backdrop of this example is that we are using almost all the available pins on Arduino board in order to drive the display, but we have decided to show it this way for simplicity.

http://static.flickr.com/25/53544993_3611fce234.jpg

Picture of a protoboard supporting the display and a potentiometer

 
/* LCD Hola
 * --------
 *
 * This is the first example in how to use an LCD screen
 * configured with data transfers over 8 bits. The example
 * uses all the digital pins on the Arduino board, but can
 * easily display data on the display
 *
 * There are the following pins to be considered:
 * 
 * - DI, RW, DB0..DB7, Enable (11 in total)
 *
 * the pinout for LCD displays is standard and there is plenty
 * of documentation to be found on the internet.
 *
 * (cleft) 2005 DojoDave for K3
 *
 */

int DI = 12;
int RW = 11;
int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};
int Enable = 2;

void LcdCommandWrite(int value) {
 // poll all the pins
 int i = 0;
 for (i=DB[0]; i <= DI; i++) {
   digitalWrite(i,value & 01);
   value >>= 1;
 }
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);
 // send a pulse to enable
 digitalWrite(Enable,HIGH);
 delayMicroseconds(1);  // pause 1 ms according to datasheet
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);  // pause 1 ms according to datasheet
}

void LcdDataWrite(int value) {
 // poll all the pins
 int i = 0;
 digitalWrite(DI, HIGH);
 digitalWrite(RW, LOW);
 for (i=DB[0]; i <= DB[7]; i++) {
   digitalWrite(i,value & 01);
   value >>= 1;
 }
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);
 // send a pulse to enable
 digitalWrite(Enable,HIGH);
 delayMicroseconds(1);
 digitalWrite(Enable,LOW);
 delayMicroseconds(1);  // pause 1 ms according to datasheet
}

void setup (void) {
 int i = 0;
 for (i=Enable; i <= DI; i++) {
   pinMode(i,OUTPUT);
 }
 delay(100);
 // initiatize lcd after a short pause
 // needed by the LCDs controller
 LcdCommandWrite(0x30);  // function set:
                         // 8-bit interface, 1 display lines, 5x7 font
 delay(64);                      
 LcdCommandWrite(0x30);  // function set:
                         // 8-bit interface, 1 display lines, 5x7 font
 delay(50);                      
 LcdCommandWrite(0x30);  // function set:
                         // 8-bit interface, 1 display lines, 5x7 font
 delay(20);                      
 LcdCommandWrite(0x06);  // entry mode set:
                         // increment automatically, no display shift
 delay(20);                      
 LcdCommandWrite(0x0E);  // display control:
                         // turn display on, cursor on, no blinking
 delay(20);                      
 LcdCommandWrite(0x01);  // clear display, set cursor position to zero  
 delay(100);                      
 LcdCommandWrite(0x80);  // display control:
                         // turn display on, cursor on, no blinking
 delay(20);                      
}

void loop (void) {
  LcdCommandWrite(0x02);  // set cursor position to zero  
  delay(10);                     
  // Write the welcome message 
  LcdDataWrite('H');
  LcdDataWrite('o');
  LcdDataWrite('l');
  LcdDataWrite('a');
  LcdDataWrite(' ');
  LcdDataWrite('C');
  LcdDataWrite('a');
  LcdDataWrite('r');
  LcdDataWrite('a');
  LcdDataWrite('c');
  LcdDataWrite('o');
  LcdDataWrite('l');
  LcdDataWrite('a');
  delay(500);
}

October 18, 2005, at 01:53 AM by 195.178.229.25 -
Added line 1:

http://static.flickr.com/25/53544993_3611fce234_o.jpg

Share