Para tener mas pines libres de salida de un pic es preferible usar la interfaz al LCD con 4 bits, en este ejemplo usamos el puerto B con los 4 bits mas altos(RB4-RB7) conectados a los pines mas altos (D4-D7)del LCD, de igual forma pongo todo el programa completo sin uso librerias.
;*******************************************
; 4 BIT LCD CON PIC16F84A
; RB7-RB4 = DB7-DB4 ; E=RB3 ; RW= RB2 ; RS=RB1
;*******************************************
list p=PIC16F84A
include "p16f84a.inc"
BIT_E EQU 3
BIT_RW EQU 2
BIT_RS EQU 1
TEMP EQU 0x020
reg1 EQU 0x021
reg2 EQU 0x022
org 0h
goto START
INITPIC ;Configuracion de puertos
bsf STATUS,RP0 ; vamos bank 1
movlw b'00000000'
movwf TRISB ;puerto b salida
bcf STATUS,RP0 ; vamos bank 0
clrf PORTB
return
INITLCD ;inicializar LCD
MOVLW 0xFE
CALL retardo1
MOVLW B'00111000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW 0x0A ;retardo 5ms
CALL retardo1
MOVLW B'00111000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW 0x02
CALL retardo1
MOVLW B'00111000'
MOVWF PORTB
BCF PORTB,BIT_E
CALL LCDBUSY
MOVLW B'00101000'
MOVWF PORTB
BCF PORTB,BIT_E
CALL LCDBUSY
MOVLW B'00101000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW B'10001000'
MOVWF PORTB
BCF PORTB,BIT_E
CALL LCDBUSY
MOVLW B'00001000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW B'11111000'
MOVWF PORTB
BCF PORTB,BIT_E
CALL LCDBUSY
MOVLW B'00001000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW B'00011000'
MOVWF PORTB
BCF PORTB,BIT_E
CALL LCDBUSY
MOVLW B'00001000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW B'01101000'
MOVWF PORTB
BCF PORTB,BIT_E
RETURN
LCDBUSY
BSF STATUS,RP0
MOVLW B'11110000'
MOVWF TRISB
BCF STATUS,RP0
BSF PORTB,BIT_RW
BCF PORTB,BIT_RS
BSF PORTB,BIT_E
MOVF PORTB,W
BCF PORTB,BIT_E
BSF PORTB,BIT_RW
BCF PORTB,BIT_RS
BSF PORTB,BIT_E
NOP
BCF PORTB,BIT_E
ANDLW 0x80
BTFSS STATUS,Z
GOTO LCDBUSY
BCF PORTB,BIT_RW
BSF STATUS,RP0
MOVLW 0x000
MOVWF TRISB
BCF STATUS,RP0
RETURN
LINE2
MOVLW B'11001000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW B'00001000'
MOVWF PORTB
BCF PORTB,BIT_E
RETURN
LCDWRITE
MOVWF TEMP
CALL LCDBUSY
MOVF TEMP,W
ANDLW B'11110000'
IORLW B'00001010'
MOVWF PORTB
BCF PORTB,BIT_E
SWAPF TEMP,W
ANDLW B'11110000'
IORLW B'00001010'
MOVWF PORTB
BCF PORTB,BIT_E
RETURN
DEMORA ;retardo 500uS con xt 4MHz
MOVLW D'165'
MOVWF reg1
DEMORA1
DECFSZ reg1, F
GOTO DEMORA1
RETURN
retardo1
MOVLW D'255'
MOVWF reg2
DEMORA2
CALL DEMORA
DECFSZ reg2, F
GOTO DEMORA2
RETURN
START
CALL INITPIC ;inicializar PIC
CALL INITLCD ;inicializar LCD
inicio
call retardo1
MOVLW D'80' ;P
CALL LCDWRITE
MOVLW D'82' ;R
CALL LCDWRITE
MOVLW D'79' ;O
CALL LCDWRITE
MOVLW D'89' ;Y
CALL LCDWRITE
MOVLW D'69' ;E
CALL LCDWRITE
MOVLW D'67' ;C
CALL LCDWRITE
MOVLW D'84' ;T
CALL LCDWRITE
MOVLW D'79' ;O
CALL LCDWRITE
MOVLW D'83' ;S
CALL LCDWRITE
MOVLW D'32' ;espacio en blanco
CALL LCDWRITE
MOVLW D'50' ;2
CALL LCDWRITE
MOVLW D'48' ;0
CALL LCDWRITE
MOVLW D'49' ;1
CALL LCDWRITE
MOVLW D'49' ;1
CALL LCDWRITE
MOVLW D'32' ;espacio en blanco
CALL LCDWRITE
SLEEP
END
El archivo HeX. probado y comprobado lo pueden bajar de este enlace:
http://www.4shared.com/file/SBnq3pu0/lcd4bit.html
;*******************************************
; 4 BIT LCD CON PIC16F84A
; RB7-RB4 = DB7-DB4 ; E=RB3 ; RW= RB2 ; RS=RB1
;*******************************************
list p=PIC16F84A
include "p16f84a.inc"
BIT_E EQU 3
BIT_RW EQU 2
BIT_RS EQU 1
TEMP EQU 0x020
reg1 EQU 0x021
reg2 EQU 0x022
org 0h
goto START
INITPIC ;Configuracion de puertos
bsf STATUS,RP0 ; vamos bank 1
movlw b'00000000'
movwf TRISB ;puerto b salida
bcf STATUS,RP0 ; vamos bank 0
clrf PORTB
return
INITLCD ;inicializar LCD
MOVLW 0xFE
CALL retardo1
MOVLW B'00111000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW 0x0A ;retardo 5ms
CALL retardo1
MOVLW B'00111000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW 0x02
CALL retardo1
MOVLW B'00111000'
MOVWF PORTB
BCF PORTB,BIT_E
CALL LCDBUSY
MOVLW B'00101000'
MOVWF PORTB
BCF PORTB,BIT_E
CALL LCDBUSY
MOVLW B'00101000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW B'10001000'
MOVWF PORTB
BCF PORTB,BIT_E
CALL LCDBUSY
MOVLW B'00001000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW B'11111000'
MOVWF PORTB
BCF PORTB,BIT_E
CALL LCDBUSY
MOVLW B'00001000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW B'00011000'
MOVWF PORTB
BCF PORTB,BIT_E
CALL LCDBUSY
MOVLW B'00001000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW B'01101000'
MOVWF PORTB
BCF PORTB,BIT_E
RETURN
LCDBUSY
BSF STATUS,RP0
MOVLW B'11110000'
MOVWF TRISB
BCF STATUS,RP0
BSF PORTB,BIT_RW
BCF PORTB,BIT_RS
BSF PORTB,BIT_E
MOVF PORTB,W
BCF PORTB,BIT_E
BSF PORTB,BIT_RW
BCF PORTB,BIT_RS
BSF PORTB,BIT_E
NOP
BCF PORTB,BIT_E
ANDLW 0x80
BTFSS STATUS,Z
GOTO LCDBUSY
BCF PORTB,BIT_RW
BSF STATUS,RP0
MOVLW 0x000
MOVWF TRISB
BCF STATUS,RP0
RETURN
LINE2
MOVLW B'11001000'
MOVWF PORTB
BCF PORTB,BIT_E
MOVLW B'00001000'
MOVWF PORTB
BCF PORTB,BIT_E
RETURN
LCDWRITE
MOVWF TEMP
CALL LCDBUSY
MOVF TEMP,W
ANDLW B'11110000'
IORLW B'00001010'
MOVWF PORTB
BCF PORTB,BIT_E
SWAPF TEMP,W
ANDLW B'11110000'
IORLW B'00001010'
MOVWF PORTB
BCF PORTB,BIT_E
RETURN
DEMORA ;retardo 500uS con xt 4MHz
MOVLW D'165'
MOVWF reg1
DEMORA1
DECFSZ reg1, F
GOTO DEMORA1
RETURN
retardo1
MOVLW D'255'
MOVWF reg2
DEMORA2
CALL DEMORA
DECFSZ reg2, F
GOTO DEMORA2
RETURN
START
CALL INITPIC ;inicializar PIC
CALL INITLCD ;inicializar LCD
inicio
call retardo1
MOVLW D'80' ;P
CALL LCDWRITE
MOVLW D'82' ;R
CALL LCDWRITE
MOVLW D'79' ;O
CALL LCDWRITE
MOVLW D'89' ;Y
CALL LCDWRITE
MOVLW D'69' ;E
CALL LCDWRITE
MOVLW D'67' ;C
CALL LCDWRITE
MOVLW D'84' ;T
CALL LCDWRITE
MOVLW D'79' ;O
CALL LCDWRITE
MOVLW D'83' ;S
CALL LCDWRITE
MOVLW D'32' ;espacio en blanco
CALL LCDWRITE
MOVLW D'50' ;2
CALL LCDWRITE
MOVLW D'48' ;0
CALL LCDWRITE
MOVLW D'49' ;1
CALL LCDWRITE
MOVLW D'49' ;1
CALL LCDWRITE
MOVLW D'32' ;espacio en blanco
CALL LCDWRITE
SLEEP
END
El archivo HeX. probado y comprobado lo pueden bajar de este enlace:
http://www.4shared.com/file/SBnq3pu0/lcd4bit.html