LIST P = 18F87J50 ;PIC a utilizar
INCLUDE <P18F87J50.INC>
;************************************************************
;Configuración de fusibles
CONFIG FOSC = HS
CONFIG DEBUG = OFF
CONFIG XINST = OFF
;***************************************************
;Ubicación de los pines de EN y RS en Miuva
#define LCD_EN PORTE,3
#define LCD_RS PORTE,1
#define LCD_RW PORTE,2
CBLOCK
NIBBLE ;Variable para escribir en la LCD
Ret1 ;Variables para crear retardos
Ret2
ENDC
ORG 0x00 ;Iniciar el programa en el registro 0x00
movlw 0x00
movwf TRISE ;Configurar puerto D como salida
bcf LCD_RW
LCD_Init
bcf LCD_EN ;Enable = LOW
call Retardo15ms
bcf LCD_RS ;RS = LOW
;Inicia secuencia de inicialización
;Function set
movlw b'00110000'
movwf PORTE
bsf LCD_EN ;Activa el bit de ENABLE
call Retardo100us
bcf LCD_EN ;Lee Function set
call Retardo4_1ms
;Function set
movlw b'00110000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN ;Lee Function set
call Retardo100us
;Function set
movlw b'00110000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN ;Lee Function set
call Retardo4_1ms
;Function set
movlw b'00100000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN ;Lee Function set
call Retardo4_1ms
;Function set
movlw b'00100000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
movlw b'11100000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
;Display off
movlw b'00000000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
movlw b'10000000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
;Display clear
movlw b'00000000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
movlw b'00010000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
;Entry mode set
movlw b'00000000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
movlw b'01100000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
;DDRAM ACCES
movlw b'10000000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
movlw b'00000000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
;Display on
movlw b'00000000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
movlw b'11000000'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
;MANDAR LETRA I
bsf LCD_RS
; movlw b'00100100'
movlw b'01000010'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
; movlw b'00101001'
movlw b'10010010'
movwf PORTE
bsf LCD_EN
call Retardo100us
bcf LCD_EN
call Retardo4_1ms
BUCLE
goto BUCLE
Retardo15ms
movlw .255
movwf Ret1
movlw .40
movwf Ret2
Ret15ms
decfsz Ret1, F
bra Ret15ms
decfsz Ret2, F
bra Ret15ms
return
Retardo40ms
movlw .255
movwf Ret1
movlw .105
movwf Ret2
Ret40ms
decfsz Ret1, F
bra Ret15ms
decfsz Ret2, F
bra Ret15ms
return
Retardo5ms
movlw .255
movwf Ret1
movlw .14
movwf Ret2
Ret5ms
decfsz Ret1,F
bra Ret5ms
decfsz Ret2,F
bra Ret5ms
return
Retardo4_1ms
movlw .255
movwf Ret1
movlw .11
movwf Ret2
Ret4_1ms
decfsz Ret1, F
bra Ret15ms
decfsz Ret2, F
bra Ret15ms
return
Retardo100us
movlw .67
movwf Ret1
Ret100us
decfsz Ret1, F
return
Retardo40us
movlw .27
movwf Ret1
Ret40us
decfsz Ret1,F
return
END