Documente Academic
Documente Profesional
Documente Cultură
INC" ****************************
*******
;
;
===================================================================
;
Del libro "MICROCONTROLADOR PIC16F84. DESARROLLO DE PROYECTOS"
;
E. Palacios, F. Remiro y L. Lpez.
;
Editorial Ra-Ma. www.ra-ma.es
;
===================================================================
;
; Estas subrutinas permiten realizar las tareas bsicas de control de un mdulo LCD
de 2
; lneas por 16 caracteres, compatible con el modelo LM016L.
;
; El visualizador LCD est conectado al Puerto B del PIC mediante un bus de 4 bits
. Las
; conexiones son:
;
- Las 4 lneas superiores del mdulo LCD, pines <DB7:DB4> se conectan a las 4
;
lneas superiores del Puerto B del PIC, pines <RB7:RB4>.
;
- Pin RS del LCD a la lnea RA0 del PIC.
;
- Pin R/W del LCD a la lnea RA1 del PIC, o a masa.
;
- Pin Enable del LCD a la lnea RA2 del PIC.
;
; Se utilizan llamadas a subrutinas de retardo de tiempo localizadas en la libre
ra RETARDOS.INC.
;
; ZONA DE DATOS ****************************************************************
*****
CBLOCK
LCD_Dato
LCD_GuardaDato
LCD_GuardaTRISB
LCD_Auxiliar1
LCD_Auxiliar2
ENDC
LCD_CaracteresPorLinea EQU
lla.
#DEFINE
#DEFINE
#DEFINE
#DEFINE
LCD_PinRS
LCD_PinRW
LCD_PinEnable
LCD_BusDatos
.16
PORTA,0
PORTA,1
PORTA,2
PORTB
bcf
LCD_PinRW
bcf
LCD_PinEnable
bcf
call
movlw
call
call
movlw
call
call
movlw
call
movlw
call
LCD_PinRS
Retardo_20ms
b'00110000'
LCD_EscribeLCD
Retardo_5ms
b'00110000'
LCD_EscribeLCD
Retardo_200micros
b'00110000'
LCD_EscribeLCD
b'00100000'
LCD_EscribeLCD
E=0.
; Activa el Modo Comando poniendo RS=0.
; Escribe el dato en el LCD.
; Interface de 4 bits.
LCD_2Lineas4Bits5x7
os.
call
LCD_Borra
principio
call
LCD_CursorOFF
call
LCD_CursorIncr
return
b'11110000'
LCD_Dato
LCD_BusDatos,W
b'00001111'
LCD_Dato,F
bsf
movf
movwf
movlw
andwf
PORTB,F
bcf
STATUS,RP0
; Acceso al Banco 0.
movf
movwf
bsf
LCD_Dato,W
LCD_BusDatos
LCD_PinEnable
dejan
alida.
;
e un pequeo
bcf
miento del LCD.
bsf
valor en
movf
movwf
bcf
return
LCD_PinEnable
STATUS,RP0
LCD_GuardaTRISB,W
PORTB
STATUS,RP0
;
LCD_EnviaComando
bcf
LCD_PinRS
; Activa el Modo Comando, poniendo RS=0.
goto
LCD_Envia
LCD_Caracter
bsf
LCD_PinRS
; Activa el "Modo Dato", poniendo RS=1.
call
LCD_CodigoCGROM ; Obtiene el cdigo para correcta visualizacin.
LCD_Envia
movwf LCD_GuardaDato
; Guarda el dato a enviar.
call
LCD_EscribeLCD
; Primero enva el nibble alto.
swapf LCD_GuardaDato,W
; Ahora enva el nibble bajo. Para ello pa
sa el
; nibble bajo del dato a enviar a parte
alta del byte.
call
LCD_EscribeLCD
; Se enva al visualizador LCD.
btfss LCD_PinRS
; Debe garantizar una correcta escritura
manteniendo
call
Retardo_2ms
; 2 ms en modo comando y 50 s en modo crac
ter.
call
Retardo_50micros
return
; Subrutina "LCD_CodigoCGROM" ---------------------------------------------------------;
; A partir del carcter ASCII nmero 127 los cdigos de los caracteres definidos en la
; tabla CGROM del LM016L no coinciden con los cdigos ASCII. As por ejemplo, el cdig
o
; ASCII de la "" en la tabla CGRAM del LM016L es EEh.
;
; Esta subrutina convierte los cdigos ASCII de la "", "" y otros, a cdigos CGROM par
a que
; que puedan ser visualizado en el mdulo LM016L.
;
; Entrada:
En (W) el cdigo ASCII del carcter que se desea visualizar.
; Salida:
En (W) el cdigo definido en la tabla CGROM.
LCD_CodigoCGROM
movwf LCD_Dato
si es
LCD_EnheMinuscula
sublw ''
btfss STATUS,Z
goto
LCD_EnheMayuscula
movlw b'11101110'
movwf LCD_Dato
goto
LCD_FinCGROM
LCD_EnheMayuscula
movf
LCD_Dato,W
sublw ''
btfss STATUS,Z
goto
LCD_Grado
movlw b'11101110'
movwf LCD_Dato
goto
LCD_FinCGROM
LCD_Grado
movf
LCD_Dato,W
sublw ''
btfss STATUS,Z
goto
LCD_FinCGROM
movlw b'11011111'
movwf LCD_Dato
LCD_FinCGROM
movf
LCD_Dato,W
return
swapf LCD_Auxiliar2,W
call
LCD_Nibble
LCD_VisualizaBajo
movf
LCD_Auxiliar2,W
;
call
LCD_Nibble
;
return
===================================================================
Del libro "MICROCONTROLADOR PIC16F84. DESARROLLO DE PROYECTOS"
E. Palacios, F. Remiro y L. Lpez.
Editorial Ra-Ma. www.ra-ma.es
===================================================================