Electrónica‎ > ‎Arduino‎ > ‎

3 Wires LCD

Este esquema é totalmente baseado no da página http://www.arduino.cc/playground/Code/LCD3wires e bastante simples, desta forma 'poupamos' muitos pinos do Arduino, pois com apenas 3 pinos podemos controlar um LCD de 1 ou 2 linhas.

Utilizando o Shift Register HEF4094B temos o seguinte esquema:


A library está disponível em http://arduino.cc/playground/uploads/Code/LCD3WireLibrary.zip e podemos usar o exemplo que vem com a mesma:

// Example use of LCD3Wire library
// Almost a carbon-copy of LCD4BitExample.pde

#include <LCD3Wire.h> 

// Arduino pins
#define LCD_LINES 2  // number of lines in your display
#define DOUT_PIN  11  // Dout pin
#define STR_PIN   12  // Strobe pin
#define CLK_PIN   10  // Clock pin

#define LED_PIN   13 // we'll use the debug LED to output a heartbeat

//create object to control an LCD.  
LCD3Wire lcd = LCD3Wire(LCD_LINES, DOUT_PIN, STR_PIN, CLK_PIN); 

//some messages to display on the LCD
char msgs[6][15] = {"apple", "banana", "pineapple", "mango", "watermelon", "pear"};
int NUM_MSGS = 6;

void setup() { 
  lcd.init();
  
  //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
  //lcd.commandWrite(0x0F);//cursor on, display on, blink on.  (nasty!)
  
  pinMode(LED_PIN, OUTPUT);  
}

void loop() {  
  digitalWrite(LED_PIN, HIGH);  //light the debug LED

  //pick a random message from the array
  int pick = random(NUM_MSGS);
  char* msg = msgs[pick];
  
  lcd.clear();
  lcd.printIn(msg);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  
  //print some dots individually
  for (int i=0; i<3; i++){
    lcd.print('.');
    delay(100);
  }
  //print something on the display's second line. 
  if(LCD_LINES>1){
    lcd.cursorTo(2, 0);  //line=2, x=0.
    lcd.printIn("Score: 6/7");
    delay(1000);
  }
  
  //scroll entire display 20 chars to left, delaying 50ms each inc
  lcd.leftScroll(20, 50);
}


Resultado:




Para termos suporte a LCDs 20x4:

Com a ajuda do fórum do Arduino (na página http://arduino.cc/forum/index.php/topic,10539.0.html), podemos facilmente adaptar a library para usarmos um LCD 20x4.

Basta alterar o método "cursorTo" na library para:

void LCD3Wire::cursorTo(int line_num, int x){
  //first, put cursor home
  commandWrite(CMD_HOME);

  //if we are on a 1-line display, set line_num to 1st line, regardless of given
  if (lcd_lines==1){
    line_num = 1;
  }
  //offset 40 chars in if second line requested
  if (line_num == 2){
    x += 40;
  }
// add the following code for 4 line display
  if (line_num == 3) {   // In fact, line 3 is an extension of the line 1 (beyond the 20 first characters)
    x += 20;
  }
 
  if (line_num == 4) {   // Line 4 is an extension of line 2
    x += 60;
  }
  //advance the cursor to the right according to position. (second line starts at position 40).
  for (int i=0; i<x; i++) {
    commandWrite(0x14);
  }
}

No exemplo podemos adaptar da seguinte forma:

// Example use of LCD3Wire library
// Almost a carbon-copy of LCD4BitExample.pde

#include <LCD3Wire.h> 

// Arduino pins
#define LCD_LINES 4  // number of lines in your display
#define DOUT_PIN  11  // Dout pin
#define STR_PIN   12  // Strobe pin
#define CLK_PIN   10  // Clock pin

#define LED_PIN   13 // we'll use the debug LED to output a heartbeat

//create object to control an LCD.  
LCD3Wire lcd = LCD3Wire(LCD_LINES, DOUT_PIN, STR_PIN, CLK_PIN); 

//some messages to display on the LCD
char msgs[6][15] = {"Arduino", "LCD 20X4", "Testing", "GrcByte", "Almamater", "LCD Test"};
int NUM_MSGS = 6;

void setup() { 
  lcd.init();
  
  //optionally, now set up our application-specific display settings, overriding whatever the lcd did in lcd.init()
  //lcd.commandWrite(0x0F);//cursor on, display on, blink on.  (nasty!)
  
  pinMode(LED_PIN, OUTPUT);  
}

void loop() {  
  digitalWrite(LED_PIN, HIGH);  //light the debug LED

  //pick a random message from the array
  int pick = random(NUM_MSGS);
  char* msg = msgs[pick];
  
  lcd.clear();
  lcd.printIn(msg);
  delay(1000);
  digitalWrite(LED_PIN, LOW);
  
  //print some dots individually
  for (int i=0; i<3; i++){
    lcd.print('.');
    delay(100);
  }
  //print something on the display's second line. 
  if(LCD_LINES==1){
    lcd.cursorTo(1, 0);  //line=2, x=0.
    lcd.printIn("Score: 6/7");
    delay(1000);
  }
    if(LCD_LINES==2){
    lcd.cursorTo(2, 0);  //line=2, x=0.
    lcd.printIn("Score: 6/7");
    delay(1000);
  }
   if(LCD_LINES==3){
    lcd.cursorTo(3, 0);  //line=2, x=0.
    lcd.printIn("Score: 6/7");
    delay(1000);
  }
  if(LCD_LINES==4){
    lcd.cursorTo(2, 0);  //line=2, x=0.
    lcd.printIn("Linha 2");
    delay(2000);
    lcd.cursorTo(3, 0);  //line=3, x=0.
    lcd.printIn("Linha 3");
    delay(2000);
    lcd.cursorTo(4, 0);  //line=4, x=0.
    lcd.printIn("Linha 4 - Yeahhhh!!");
    delay(2000);
  }
  
  //scroll entire display 20 chars to left, delaying 50ms each inc
  lcd.leftScroll(20, 50);
}



Resultado:




Č
ċ
ď
Tiago GRC,
28/04/2011, 17:14
Comments