Está en la página 1de 13

LCD

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#include <Wire.h>
#include <LCD_I2C.h>
LCD_I2C lcd(0x20,16,2);
filas 16*2

//Indicamos la direccin de la pantalla LCD 0x20 y el numero

void setup()
{
lcd.init(); //Inicializamos la pantalla LCD
lcd.backlight(); //Activamos la iluminacin de la pantalla
//lcd.noBacklight(); //Desactivamos la iluminacin de la pantalla
lcd.setCursor(1,0);
lcd.print("Visitanos en:"); //Imprimimos un mensaje
lcd.setCursor(1,1);
lcd.print("Taller Arduino");
}
void loop()
{
}

LiquidCrystal
La librera LiquidCrystal te permite controlar displays LCD que sean
complatibles con el driver Hitachi HD44780. Hay muchos de ellos ah
fuera, y puedes comunicarte con ellos a travs del interfaz de 16
pines.
Este sketch de ejemplo imprime "Hello World!" en el LCD y muestra
el tiempo en segundos desde que Arduino fu reseteado por ltima
vez.

salida del sketch en un LCD de 2x16


El LCD tiene un interfaz paralelo, significando esto que el
microcontrolador tiene que manipular varios pines del interfaz a la
vez para controlarlo. El interfaz consta de los siguientes pines:
Un pin de seleccin de registro (RS) que controla en qu parte de la
memoria del LCD ests escribiendo datos. Puedes seleccionar bien
el regisro de datos, que mantiene lo que sale en la pantalla, o un
registro de instruccin, que es donde el controlador del LCD busca
las instrucciones para saber cual es lo siguiente que hay que hacer.
El pin de lectura/escritura (R/W)que selecciona el modo de lectura o
el de escritura.
Un pin para habilitar (enable) que habilita los registros.
8 pines de datos (D00-D07). Los estados de estos pines (nivel alto o
bajo) son los bits que ests escribiendo a un registro cuando
escribes, o los valores de lectura cuando ests leyendo.
Hay tambin un pin de contraste del display (Vo), pines de
alimentacin (+5V y GND) y pines de retro-iluminacin (Bklt+ y

Bklt-), que te permiten alimentar el LCD, controlar el contraste del


display, o encender y apagar la retro-iluminacin, respectivamente.
El proceso de controlar el display involucra la colocacin de los
datos que componen la imagen de lo que quieres mostrar, en los
registros de datos, y luego, colocar las instrucciones, en el registro
de instrucciones. La libreraLiquidCrystal te simplifica todo este
proceso de forma que no neesitas saber las instrucciones de bajo
nivel.
Los LCD-s compatibles con Hitachi pueden ser controlados de dos
modos: 4 bits u 8 bits. El modo de 4 bits requiere siete pines de E/S
de Arduino, mientras el modo de 8 bits requiere 11 pines. Para
mostrar texto en la pantalla, puedes hacer la mayora de las cosas
en modo 4 bits, por lo que el ejemplo muestra como controlar un
LCD de 2x16 en modo de 4 bits.
NOTA: La librera LiquidCrystal tiene revisiones venidas a menos
despus de la versin 0016 de Arduino. Gracias a Limor Fried por
reescribirla para incluir los modos de 4 y 8 bits y otras
funcionalidades. Estas notas hacen referencia a la versin actual
como es Arduino 0017.
Otros ejemplos de la librera LiquidCrystal

Hello World - muestra "hello world!" y los segundos desde el


ltio reset

Blink - control del cursor en forma de bloque.

Cursor - control del cursor en forma de guin bajo.

Display - limpieza rpida del display, sin perder lo que haba en


l.

Text Direction - controla en qu sentido fluye el texto desde el


cursor.

Autoscroll - scroll automtico del nuevo texto.

Serial input - acepta la entrada serie y la muestra.

SetCursor - establece la posicin del cursor.

Scroll - realiza un scroll del texto a la izquierda y a la derecha


Circuito

El pin RS del LCD conectado a la E/S digital en el pin 12

El pin enable del LCD conectado a la E/S digital en el pin 11.

Los pines D4 - D7 conectado a las E/S digitales desde el pin 5


hasta el 2.

Los pines de voltaje y tierra conectados a +5V y tierra.

El pin Vo, que controla el constraste, conectado a un


potencimetro. Ajusta el potencimetro para que el texto tenga el
contraste que t quieras.
Nota: Este diagrama de wiring es diferente que el que haba en
anteriores versiones la de librera LiquidCrystal. Los pines de R/W
(lectura/escritura) estn conectado a tierra, y el pin de enable se
mueve al pin 11, liberando el pin E/S para otros usos.
pincha en la imagen para aumentarla

image developed using Fritzing. For more circuit examples, see the Fritzing
project page

Esquemtico:
pincha en la imagen para aumentarla

/*

LiquidCrystal Library - Hello World

Demonstrates the use a 16x2 LCD display. The LiquidCrystal


library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD
and shows the time.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5

*
*
*
*
*
*

LCD D5 pin to digital pin 4


LCD D6 pin to digital pin 3
LCD D7 pin to digital pin 2
10K resistor:
ends to +5V and ground
wiper to LCD VO pin (pin 3)

Library originally added 18 Apr 2008


by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 8 Feb 2010
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}

LiquidCrystal - "Hello World!"


The LiquidCrystal library allows you to control LCD displays that are
compatible with the Hitachi HD44780 driver. There are many of

them out there, and you can usually tell them by the 16-pin
interface.
This example sketch prints "Hello World!" to the LCD and shows the
time in seconds since the Arduino was reset.

output of the sketch on a 2x16 LCD


The LCDs have a parallel interface, meaning that the microcontroller
has to manipulate several interface pins at once to control the
display. The interface consists of the following pins:
A register select (RS) pin that controls where in the LCD's memory
you're writing data to. You can select either the data register, which
holds what goes on the screen, or an instruction register, which is
where the LCD's controller looks for instructions on what to do next.
A Read/Write (R/W) pin that selects reading mode or writing mode
An Enable pin that enables writing to the registers
8 data pins (D0 -D7). The states of these pins (high or low) are the
bits that you're writing to a register when you write, or the values
you're reading when you read.

There's also a display constrast pin (Vo), power supply pins (+5V
and Gnd) and LED Backlight (Bklt+ and BKlt-) pins that you can use
to power the LCD, control the display contrast, and turn on and off
the LED backlight, respectively.
The process of controlling the display involves putting the data that
form the image of what you want to display into the data registers,
then putting instructions in the instruction register.
The LiquidCrystal Library simplifies this for you so you don't need to
know the low-level instructions.
The Hitachi-compatible LCDs can be controlled in two modes: 4-bit
or 8-bit. The 4-bit mode requires seven I/O pins from the Arduino,
while the 8-bit mode requires 11 pins. For displaying text on the
screen, you can do most everything in 4-bit mode, so example
shows how to control a 2x16 LCD in 4-bit mode.
Hardware Required

Arduino Board

LCD Screen (compatible with Hitachi HD44780 driver)

pin headers to solder to the LCD display pins

10k Potentiometer

breadboard

hook-up wire
Circuit

Before wiring the LCD screen to your Arduino we suggest to solder a


pin header strip to the 14 (or 16) pin count connector of the LCD
screen, as you can see in the image above.
To wire your LCD screen to your Arduino, connect the following pins:

LCD RS pin to digital pin 12

LCD Enable pin to digital pin 11

LCD D4 pin to digital pin 5

LCD D5 pin to digital pin 4

LCD D6 pin to digital pin 3

LCD D7 pin to digital pin 2


Additionally, wire a 10K pot to +5V and GND, with it's wiper
(output) to LCD screens VO pin (pin3).
click the images to enlarge

Code
/*
LiquidCrystal Library - Hello World
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with
the
Hitachi HD44780 driver. There are many of them out there, and
you
can usually tell them by the 16-pin interface.

This sketch prints "Hello World!" to the LCD


and shows the time.
The circuit:
LCD RS pin to digital pin 12
LCD Enable pin to digital pin 11
LCD D4 pin to digital pin 5
LCD D5 pin to digital pin 4
LCD D6 pin to digital pin 3
LCD D7 pin to digital pin 2
LCD R/W pin to ground
10K resistor:
ends to +5V and ground
wiper to LCD VO pin (pin 3)

*
*
*
*
*
*
*
*
*
*

Library originally added 18 Apr 2008


by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with
0):

lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}

También podría gustarte