Sie sind auf Seite 1von 4

// El presente código envía la frase SENATI al LCD.

Para controlar el envio, no se cuenta el numero de caracteres


// sino se emplea un carácter como fin de texto, el cual se compara antes de enviar un nuevo carácter( si el
// carácter es # se asume se llego al final del mensaje).
//Pines empleados RB7..RB4 conectado a DB7..DB4, E->RA0, RSRA1, RW=GND.
List P=16f84a
INCLUDE "P16F84A.INC"
__CONFIG _XT_OSC & _CP_OFF & _PWRTE_ON & _WDT_OFF
org 0x00
goto inicio
org 0x05

PTAB_T EQU 0X06


PTAA_T EQU 0X05
ESTADO EQU 0X03
PCL EQU 0X02

CBLOCK 0X0C
DATO
DATO1
tiempo
tiempo1
tiempo2
libre
BYTE_ALTO
BYTE_BAJO
ENDC

inicio bsf ESTADO,5


clrf PTAB_T
clrf PTAA_T
bcf ESTADO,5
call inicializa_lcd
call LCD_CURSOR_ON ; Debe encenderse el LCD luego de inicializaese.
call envia_msj
bucle goto bucle

; //////////Envia el mensaje de la tabla

envia_msj
clrf libre ; contador de posiciones.
sig_dato
movf libre,0 ; lIBRE SE CARGA A W ( INDICE DE LA LETRA A ENVIAR)
call TABLA
movwf DATO ; SE ALMACENA TEMPORALMENTE EL DATO A ENVIAR AL LCD
sublw '#' ; w-'#'=>w
btfss ESTADO,2
goto seguir ; Enviar letra
RETURN ; se termino el envio.

seguir movf DATO,0 ; DATO --> W


call envia_dato_lcd
incf libre,1
goto sig_dato
;////// Funcion que envia un dato /////
;///// ///// antes de llamar a esta funcion el dato debe estar en w ////////////
;/// aqui habra 2 variables BYTE_ALTO, BYTE_BAJO

envia_dato_lcd
movwf BYTE_ALTO
swapf BYTE_ALTO,0
movwf BYTE_BAJO
bsf PTAA_T,0 ; RS=1
bcf PTAA_T,1 ; E=0
;///////////////////
movfw BYTE_ALTO ;enviando la parte alta
movwf PTAB_T
bsf PTAA_T,1 ; E=1; Inicio escrtura
bcf PTAA_T,1 ; E=0
call retardo_40microseg ; Debe durar 50 microsegundos
movfw BYTE_BAJO ;enviando la parte BAJA
movwf PTAB_T
bsf PTAA_T,1 ; E=1; Inicio escrtura
bcf PTAA_T,1 ; E=0
call retardo_40microseg ; Debe durar 50 microsegundos
return

;/// funcion que inicializa el lcd

inicializa_lcd
;----------------------------------
bcf PTAA_T,0 ; RS=0
bcf PTAA_T,1 ; E=0
;----------------------------------
movlw b'00110000'
movwf PTAB_T
bsf PTAA_T,1 ;E=1
bcf PTAA_T,1 ;E=0
call retardo_4.1ms
;-----------------------------------------
movlw b'00110000' ;Rb7 Rb6 Rb5 Rb4 Rb3 Rb2 XXX = DB7 DB6 DB5 DB4 RS E
XX
movwf PTAB_T
bsf PTAA_T,1 ;E=1
bcf PTAA_T,1 ;E=0
call retardo_100microseg ; deberia ser 200microseg
; ----------------------------------------
movlw b'00110000'
movwf PTAB_T
bsf PTAA_T,1 ;E=1
bcf PTAA_T,1 ;E=0
;------------------------------------------
CALL retardo_40microseg
movlw b'00100000'
movwf PTAB_T
bsf PTAA_T,1 ;E=1
bcf PTAA_T,1 ;E=
CALL retardo_40microseg
;-----------------------------------------
; BUS DE 4 BITS, 2 LINEA,CARACTER 5X7
;CONF. A ENVIAR b'00101000'
movlw b'00101000' ;enviando la parte alta
movwf PTAB_T
bsf PTAA_T,1 ; E=1; Inicio escrtura
bcf PTAA_T,1 ; E=0
call retardo_1.7mseg
movlw b'10000010' ;enviando la parte BAJA
movwf PTAB_T
bsf PTAA_T,1 ; E=1; Inicio escrtura
bcf PTAA_T,1 ; E=0
call retardo_1.7mseg
return
; FIN DE INICIALIZACION

;---------------------------------------------------------------------
;DISPLAY CONTROL --> formato=0000 1 D C B
; D=1 Display se enciende c=0 cursor no se visualiza b=0 no hay efecto de parpadeo

LCD_CURSOR_ON ; byte a envar=0000 1100


bcf PTAA_T,0 ; RS=0
bcf PTAA_T,1 ; E=0
movlw b'00001100'
movwf PTAB_T
bsf PTAA_T,1 ; E=1 ; Inicio escrtura
bcf PTAA_T,1 ; E=0
call retardo_1.7mseg ; Tiempo q tarda en escribirse un comando
movlw b'11000000'
movwf PTAB_T
bsf PTAA_T,1 ; E=1 ; Inicio escrtura
bcf PTAA_T,1 ; E=0
call retardo_1.7mseg ; Tiempo q tarda en escribirse un comando
; ------------------------------------------------
return

;############ RUTINAS DE TIEMPOS ###################


;//////////////// ; aproxmadamente 1700 microseg =17x100, TARDA 1,74mseg ////////
retardo_1.7mseg
movlw d'16'
movwf tiempo1
t171 movlw d'35'
movwf tiempo
t17 decfsz tiempo,1
goto t17
decfsz tiempo1,1
goto t171
return

;//////////////// ; aproxmadamente 15,8 mseg ////////


retardo_15ms
movlw d'9'
movwf tiempo2
t15 call retardo_1.7mseg
decfsz tiempo2,1
goto t15
return

;//////////////// ; aproxmadamente 5.25 ms////////

retardo_4.1ms
movlw d'3'
movwf tiempo2
t4.1 call retardo_1.7mseg
decfsz tiempo2,1
goto t4.1
return

;//////////////// ; aproxmadamente 121 microseg ////////


retardo_100microseg
movlw d'40'
movwf tiempo
t100 decfsz tiempo,1
goto t100
return

;//////////////// se logra exactamente 40microseg si d=13 ////////


retardo_40microseg
movlw d'13'
movwf tiempo
t40 decfsz tiempo,1
goto t40
return

;/////////////////// MENSAJE A ENVIAR AL LCD////////77


;/////////////// EL CARÁCTER # SIRVE COMO LIMITADOR DE FIN DE TEXTO ////
;//// EL PROGRAMA ENVIARA EL TEXTO HASTA ENCONTRAR #.
TABLA addwf PCL,1
DT " SENATI#"
END

Das könnte Ihnen auch gefallen