; LCD 16X1 4BITS.ASM
; utiliza una interfaz de solo 4 bits de datos para la conexión
; al LCD. Permite liberar líneas del puerto B para otros usos, y
; usar menos pines (10) en el conector del LCD.
; escribe el mensaje "EDUPIC 16F84"
;Datos on RB4...RB7 [DB4...DB7]
;RA1 para RS
;RA2 para E
;Tierra en RW

STOREL		EQU	H'0D'
STOREM		EQU	H'0E'
STORE3		EQU	H'0F'

	include "p16f84a.inc"
	list	p=PIC16f84A
	__CONFIG _CP_OFF & _PWRTE_OFF & _WDT_OFF & _XT_OSC

	movlw	b'00000000'
	TRIS	06		; PORTB salidas
	movlw	b'11111001'
	TRIS	05		; PORTA RA1,RA2 salidas

	call	DELAY
	call	DELAY
	bcf	PORTA,1		; RS=0 => empiezan comandos
	
	movlw 	0x30		; despierta LCD
	movwf	PORTB
	call	EPULSE
	call	DELAY
	call	EPULSE
	call	DELAY
	call	EPULSE
	call	DELAY

	movlw	b'00100000'	; comienza envio en cuatro bits
	movwf	PORTB
	call	EPULSE		; 2
	call	DELAY
	movlw	b'00100000'
	movwf	PORTB
	call	EPULSE		; 2
	call	DELAY
	movlw	b'10000000'	
	movwf	PORTB
	call	EPULSE		; 8	; un renglon partido en dos
	call	DELAY

	movlw	b'00000000'
	movwf	PORTB
	call	EPULSE		; 0
	call	DELAY
	movlw	b'11100000'
	movwf	PORTB
	call	EPULSE		; E
	call	DELAY


	movlw	b'00000000'
	movwf	PORTB		; 0
	call	EPULSE
	call	DELAY
	movlw	b'00010000'
	movwf	PORTB
	call	EPULSE		; 1
	call	DELAY	
	
	movlw	b'00000000'
	movwf	PORTB
	call	EPULSE		; 0
	call	DELAY
	movlw	b'01100000'
	movwf	PORTB
	call	EPULSE		; 6
	calL	DELAY

	bsf	PORTA,1		; RS=1 => terminan comandos, empiezan datos

;========================================
;	INIT ABOVE
;========================================

	movlw	b'00100000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'00000000'	;  ' '
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	movlw	b'00100000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'00000000'	;  ' '
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	movlw	b'01000000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'01010000'	;  E
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	movlw	b'01000000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'01000000'	;  D
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	movlw	b'01010000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'01010000'	;  U
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	movlw	b'01010000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'00000000'	;  P
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	movlw	b'01000000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'10010000'	;  I
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	movlw	b'01000000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'00110000'	;  C
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	bcf	PORTA,1		; empieza comando
	movlw	b'11000000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'00000000'	;  set line 2.... [C0h]
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY
	bsf	PORTA,1		; termina comando

	movlw	b'00100000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'00000000'	;  ' '
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	movlw	b'00110000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'00010000'	;  1
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	movlw	b'00110000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'01100000'	;  6
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	movlw	b'01000000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'01100000'	;  F
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

	movlw	b'00110000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'10000000'	;  8
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY


	movlw	b'00110000'
	movwf	PORTB
	call	EPULSE		 
	movlw	b'01000000'	;  4
	movwf	PORTB		;
	call	EPULSE		;
	call	DELAY

relop
	nop
	goto relop

EPULSE
	bsf	PORTA,2
	call	DELAY
	bcf	PORTA,2
	return

DELAY	movlw	0XFF	; 195.841 milisegundos
	movwf	STOREM
mallaM:	movwf	STOREL
mallaL:	decfsz	STOREL,f
	goto	mallaL	
	decfsz	STOREM,f
	goto	mallaM
	return	

	END






