Vous êtes sur la page 1sur 6

El compilador PBP permite definir los pines del microcontrolador que se

conectan al LCD (pines tales como datos, enable, escritura, etc.) usando
la funcin DEFINE.
Tenemos las siguientes definiciones:
Tabla 1. Definicin de puerto y bits para el LCD.
DEFINE
DEFINE
DEFINE
DEFINE
DEFINE
DEFINE
DEFINE
DEFINE
DEFINE
DEFINE
DEFINE
DEFINE

LCD_DREG PORTA
LCD_DBIT 0
LCD_RSREG PORTA
LCD_RSBIT 4
LCD_EREG PORTB
LCD_EBIT 3
LCD_RWREG PORTE
LCD_RWBIT 2
LCD_BITS 4
LCD_LINES 2
LCD_COMMANDUS 2000
LCD_DATAUS 50

'Puerto de datos del LCD


'Inicio de datos del bit 0 o 4
'Seleccin del puerto del registro
'Seleccin del bit de registro
'Puerto del pin de habilitacin (enable)
'Pin de enable
'Puerto de Lectura y Escritura
'Pin de Lectura y Escritura
'Tamao del bus de datos: 4 o 8
'Nmero de lneas del LCD
'Tiempo de retardo de comandos
'Retardo de envo de datos

Una vez definidos los puertos y los pines del LCD, es necesario realizar
una pausa de medio segundo antes de enviar los datos al LCD, esto para
que tenga tiempo de inicializar la memoria RAM el dispositivo. Usamos la
funcin PAUSE.
A continuacin se muestra las sentencias para escritura del LCD, usando
LCDOUT:
Tabla 2. Comandos de escritura del LCD.
Comando

Operacin

$FE, 1

Limpia visor

$FE, 2

Vuelve a inicio (comienzo de la primera lnea)

$FE, $0C

Apagar cursor

$FE, $0E

Subrayado del cursor activo

$FE, $0F

Parpadeo del cursor activo

$FE, $10

Mueve cursor una posicin hacia la izquierda

$FE, $14

Mueve cursor una posicin hacia la derecha

$FE, $C0

Mueve cursor al comienzo de la segunda lnea

Asimismo, para escribir un dato en el LCD se usan funciones como DEC,


HEX, BIN, por ejemplo:
LCDOUT $FE, 1, DEC 25
LCDOUT $FE, $C0, BIN 25

Si se desea escribir en una posicin inicial especfica del LCD, se usa la


siguiente tabla para determinar dicha posicin:

Tabla 3. Cdigo de direcciones de caracteres (valores hexadecimales):


Display Position 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
DD RAM Address 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
DD RAM Address C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
Por ejemplo, para escribir desde la segunda celda de la segunda fila la
palabra "TEXTO" se usa:
LCDOUT $FE,$C1,"TEXTO"

O bien se puede escribir la direccin de memoria en formato decimal:


C1 hexadecimal es 193 decimal, por la tanto:
LCDOUT $FE,193,"TEXTO"

Es equivalente a la funcin precedente.


Fsicamente, el LCD de 16x2 se debe conectar como lo indica la siguiente
figura, para controlar el contraste de la pantalla:

Figura 1. Conexin del LCD junto al potencimetro de contraste.


Un ejemplo de aplicacin se muestra a continuacin:
' DEFINICIN DE REGISTROS PARA EL LCD
DEFINE LCD_DREG PORTB 'UTILIZAR 4 BITS DEL PUERTO B PARA TX DE DATOS
DEFINE LCD_DBIT 4 'DESDE EL BIT B.4 AL BIT B.7
DEFINE LCD_RSREG PORTB'SELECCIN DEL PUERTO DEL REGISTRO
DEFINE LCD_RSBIT 1 'EN EL BIT B.1
DEFINE LCD_EREG PORTB 'UTILIZAR EL ENABLE EN EL PUERTO B
DEFINE LCD_EBIT 2 'EN EL BIT B.2
' ESTABLECER EL PUERTO B COMO SALIDA

TRISB=0
' TAMAO DE VARIABLES DEL CONTADOR
B0 VAR BYTE
B1 VAR BYTE
' PAUSA DE INICIO DEL LCD
PAUSE 500
'-------------------------------------------------------LCDOUT $FE, 1 ' LIMPIAR LCD
LCDOUT $FE, 1, "MICRO 2014" 'ESCRIBIR EN LA PRIMERA LNEA
LCDOUT $FE, $C0, "FIEE" 'ESCRIBIR EN LA SEGUNDA LNEA
PAUSE 1000
' MOSTRAR DATOS DECIMALES Y BINARIOS
LCDOUT $FE, 1, DEC 25
LCDOUT $FE, $C0, BIN 25
'-------------------------------------------------------'MOSTRAR LETRA POR LETRA
PAUSE 500
LCDOUT $FE, 1 ' LIMPIAR LCD
FOR B0 = 0 TO 13
LOOKUP B0,["MICRO 2012"],B1
LCDOUT $FE,$0C,B1
PAUSE 500
NEXT
LCDOUT $FE, $C0 'COLOCAR EL CURSOR EN LA SEG LNEA
FOR B0 = 0 TO 13
LOOKUP B0,["PROMO 2014"],B1
LCDOUT $FE,$0C,B1
PAUSE 500
NEXT
'-------------------------------------------------------'DESPLAZAMIENTO DE TEXTO EN LCD
FOR B0 = 144 TO 128 STEP -1
LCDOUT $FE, 1 ' LIMPIAR LCD
LCDOUT $FE,B0,"MICRO FIEE 2014"
PAUSE 200
NEXT
END

LCDOUT command
LCDOUT Item {,Item...}
Display Items on an intelligent Liquid Crystal Display. PBP supports LCD modules
with a Hitachi 44780 controller or equivalent. These LCDs usually have a 14- or 16pin single- or dual-row header at one edge.

If a pound sign (#) precedes an Item, the ASCII representation for each digit is
sent to the LCD. LCDOUT can also use any of the modifiers used with SEROUT2.
See the section on SEROUT2 for this information.
A program should wait for at least half a second before sending the first command
to an LCD. It can take quite a while for an LCD to start up.
Commands are sent to the LCD by sending a $FE followed by the command. Some
useful commands are listed in the following table:
Command

Operation

$FE, 1

Limpia display

$FE, 2

Retorna a Casa (comienzo de la 1ra linea)

$FE, $0C

Cursor apagado

$FE, $0E

Enciende cursor Subrayado (on)

$FE, $0F

Enciende cursor parpadeante (on)

$FE, $10

Mueve el cursor una posicin a la


izquierda

$FE, $14

Mueve el cursor una posicin a la derecha

$FE, $C0

Mueve el cursor al comienzo de la


segunda lnea

Note that there is a command to move the cursor to the beginning of the second
line of a 2-line display. For most LCDs, the displayed characters and lines are not
consecutive in display memory - there can be a break in between locations. For
most 16x2 displays, the first line starts at $0 and the second line starts at $40. The
command:
LCDOUT $FE, $C0
sets the display to start writing characters at the beginning of the second line. 16x1
displays are usually formatted as 8x2 displays with a break between the memory
locations for the first and second 8 characters. 4-line displays also have a mixed up
memory map.
See the data sheet for the particular LCD device for the character memory locations
and additional commands..
LCDOUT $FE, 1, "Hello" Clear display and show "Hello"
The LCD may be connected to the PICmicro using either a 4-bit bus or an 8-bit bus.
If an 8-bit bus is used, all 8 bits must be on one port. If a 4-bit bus is used, it must
be connected to either the bottom 4 or top 4 bits of one port. Enable and Register
Select may be connected to any port pin. R/W should be tied to ground as the
LCDOUT command is write only.

PICBASICPRO ASUME QUE EL LCD ESTCONECTADO A


LOS PINES ESPECIFICOS, A MENOS QUE SE DIGA LO
CONTRARIO.

ASUME QUE EL LCD SER USADO CON BUS DE 4 BITS


CON LAS LINEAS DE DATOS DB4-DB7 Y AL CONECTAR
AL PIC EN EL PUERTO PORTA,0 PORTA,3.
EL REGISTRO SELECCIONADO AL PORTA,4 Y
ACTIVARLO AL PORTB,3. TAMBIN INICIALIZA UN
LCD DE 2 LINEAS EN EL DISPLAY. TO INITIALIZE THE
LCD TO A 2 LINE DISPLAY.
That's it....! Now try the same thing in assembly language, and you'll quickly begin
to understand the real power & time savings you'll experience when you use
PicBasic.

Looks pretty darn simple doesn't it..? That's because PicBasic takes care of all the
details for controlling the LCD for you.
Notice the spare I/O-pins left over on the PIC16F84..? You have seven I/O-pins left
to control additional circuitry, and if you're even just a little creative here you can

design your very own Serial LCDs' at a fraction of the cost of purchasing them off
the shelf..
Using the simple serin command in PicBasic you can receive serial data on any I/Opin with the PIC16F84 controlling your LCD, and very easily create your own serial
LCDs'.

Vous aimerez peut-être aussi