Está en la página 1de 14

;**********************************************************************

; Filename: LCD.asm *
; Date: 05/02/2011 *
; File Version: 0010 *
; *
; Author: Oscar Andr�s Pulido Casallas *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P16F877A.INC *
; *
;**********************************************************************
; *
; Notes: Este c�digo muestra el mensaje en una LCD 16X2 "Curso de *
; Micros SENA-MELI 2012" La LCD est� conectada al puerto B para los*
; bit de datos(D0-D7)y los puertos RC0(RS), RC1(RW) y RC2(E). *
;**********************************************************************
;**********************************************************************
;**********************************************************************
;****** *** *** *** *** *****************
;****** *** *** ******** ******** *** *** *** *****************
;****** *** *** ******** ******** *** *** *** *****************
;****** *** *** *** ******** *** * *******************
;****** *** ******** *** ******** *** *** ** ******************
;****** *** ******** *** ******** *** *** *** *****************
;****** *** *** *** *** *** **** ****************
;**********************************************************************
;**********************************************************************
list p=16f877a
#include <p16f877a.inc>
;
***********************************************************************************
*******************
ERRORLEVEL 0, -302; permite eliminar el mensaje de warning
; que indica el no cambio de banco para la
; configuraci�n los registros SPR
;
***********************************************************************************
*******************
; Palabra de configuraci�n que habilita o inhabilita la protecci�n
; del c�digo, watch dog timer, power on reset, tipo de oscilador,
; protecci�n de la memoria RAM, protecci�n de la memoria EEPROM,
; programaci�n a baja tensi�n.
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _XT_OSC & _WRT_OFF
& _LVP_OFF & _CPD_OFF
;
***********************************************************************************
*******************
;Podemos hacer un bloque que indique las variables
;cont_1 equ 0x20
;cont_2 equ 0x21
;cont_3 equ 0x22
;loop EQU 0x23
;
***********************************************************************************
*******************
;o podemos definir las variables con:
cblock 0x20; esta se usa para darle nombres a ubicaciones de memoria
; desde la posici�n indicada en los GPR
cont_1, cont_2, cont_3, loop
endc
;
***********************************************************************************
*******************
org 0x0000; Lleva el programa al vector de reset cada vez que se
; resetea el PIC
;
***********************************************************************************
*******************
clrf STATUS; Ingresamos al banco 0
clrf PORTA;Inicializamos latches porta
clrf PORTB;Inicializamos latches portb
clrf PORTC;Inicializamos latches portc
;
***********************************************************************************
*******************
bsf STATUS,5;ingreso al banco 1
movlw 0x06
movwf ADCON1
movlw 0x03
movwf TRISA
movlw 0x00;Cargamos w con 00000000
movwf PORTB;defi el portb como salida para los datos del LCD
movwf PORTC;defi el portc como salida para los pines de control de la LCD
bcf STATUS,5; ingresamos al banco 0
;
***********************************************************************************
*******************
clrf PORTB; portb=00000000
clrf PORTC; portc=00000000
;
***********************************************************************************
*******************
Inicio

INICIA_LCD

call delay_15ms; espera que llegue al m�ximo valor de tensi�n de la


; LCD
movlw 0x30; Function set 1
movwf PORTB; puerto b = 00110000
call enable
call delay_5ms; Retardo necesario para que se ejecute la
; Instrucci�n en la LCD
;
***********************************************************************************
*******************
movlw 0x30; Function set 2
movwf PORTB; puerto b = 00110000
call enable
call delay_200us; Retardo necesario para que se ejecute la
; Instrucci�n en la LCD
movlw 0x30; Function set 3
movwf PORTB; puerto b = 00110000
call enable
call delay_200us; Retardo necesario para que se ejecute la
; Instrucci�n en la LCD
;
***********************************************************************************
*******************
movlw 0x38
movwf PORTB; puerto b = 00111000 ******************************
call enable ; pone a 0 rs *fUNCTION SET 8 bits 2 LINEA *
; pone a 0 rw *5*8 DOTS
*
;
******************************
call delay_50us; Retardo necesario para que se ejecute la
; Instrucci�n en la LCD
;
***********************************************************************************
*******************
movlw 0x0f;
movwf PORTB; puerto b = 00001111 ******************************
bcf PORTC,0; pone a 0 rs *Display on, curson on, *
bcf PORTC,1; pone a 0 rw *parpadeo on *
call enable;
******************************
call delay_50us; Retardo necesario para que se ejecute la
; Instrucci�n en la LCD
;
***********************************************************************************
*******************
INICIO_1
;
***********************************************************************************
*******************
movlw 0x06;
*******************************
movwf PORTB; puerto b = 00000110 *Incrementa el direcciona- *
bcf PORTC,0; *miento en 1 y realiza el
*
bcf PORTC,1; *salto del curso a la derecha
*
call enable; * al tiempo de que se escribe
*
;
*******************************
call delay_50us; Retardo necesario para que se ejecute la
; Instrucci�n en la LCD
;
***********************************************************************************
*******************
INICIO_2
;
***********************************************************************************
*******************
movlw 0x01; clear display
movwf PORTB
call enable
call delay_2ms; Retardo necesario para que se ejecute la
; Instrucci�n en la LCD
;
***********************************************************************************
*******************
movlw 0x02; cursor at home
movwf PORTB
call enable
call delay_2ms; Retardo necesario para que se ejecute la
; Instrucci�n en la LCD
;
***********************************************************************************
*******************
Final_inicializaci�n
;
***********************************************************************************
*******************
;
***********************************************************************************
*******************
;
***********************************************************************************
*******************
;****** *** *** *** ***
*************************************************
;****** *** *** ******** ******** *** *** ***
*************************************************
;****** *** *** ******** ******** *** *** ***
*************************************************
;****** *** *** *** ******** *** *
***************************************************
;****** *** ******** *** ******** *** *** **
**************************************************
;****** *** ******** *** ******** *** *** ***
*************************************************
;****** *** *** *** *** *** ****
************************************************
;
***********************************************************************************
*******************
;
***********************************************************************************
*******************
;
***********************************************************************************
*******************
texto_desplaza
;
***********************************************************************************
*******************
btfss PORTA,1
goto texto_desplaza

movlw 'C';escribir la C
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'u';escribir la u
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'r';escribir la r
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 's';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'o';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw ' ';escribir


movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'd';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'e';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw ' ';escribir


movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'M';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'i';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'c';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'r';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'o';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 's';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw ' ';escribir


movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

;
***********************************************************************************
*******************
movlw 0xc0 ;Permite cambiar a la segunda linea.
movwf PORTB
bcf PORTC,0
bcf PORTC,1
bsf PORTC,2
bcf PORTC,2
call delay_50us ; Tiempo requerido para ejecutar la instrucci�n en la LCD
;
***********************************************************************************
*******************

movlw 'S';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'E';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'N';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'A';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
movlw '-';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'M';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'E';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'L';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw 'I';escribir
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw ' ';escribir


movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw '2';escribir el 2
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw '0';escribir el 0
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw '1';escribir el 1
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms

movlw '2';escribir el 2
movwf PORTB
call escribe
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
call delay_15ms
;
***********************************************************************************
*******************
movlw 0x07 ; Instrucci�n que permite el desplazamiento del texto
movwf PORTB ; al mismo tiempo que se escribe en la LCD
call enable
call delay_50us ; Tiempo requerido para que se ejecute la instrucci�n en la
LCD
;
***********************************************************************************
*******************
movlw .16
movwf loop
correr
decfsz loop,1
goto uno
goto INICIO_1
uno
call ESPACIO
goto correr; ciclo desplazamiento

;
***********************************************************************************
*******************
;
***********************************************************************************
*******************
;****** *** *** *** ***
*************************************************
;****** *** *** ******** ******** *** *** ***
*************************************************
;****** *** *** ******** ******** *** *** ***
*************************************************
;****** *** *** *** ******** *** *
***************************************************
;****** *** ******** *** ******** *** *** **
**************************************************
;****** *** ******** *** ******** *** *** ***
*************************************************
;****** *** *** *** *** *** ****
************************************************
;
***********************************************************************************
*******************
;
***********************************************************************************
*******************
;
***********************************************************************************
*******************
;SUBRRUTINA QUE PERMITE ESCRIBIR ESPACIOS
;Y HACE QUE SE VAYA DESPLAZANDO EL TEXTO
;DE LA LCD.
;
***********************************************************************************
*******************
ESPACIO
movlw ' ';escribir espacio
movwf PORTB
call escribe
call delay_120ms
return

;**********************************************************************************
;SUBRUTINA DEL PULSO DE HABILITACI�N
;PARA INICIALIZACI�N Y CONFIGURACI�N
;**********************************************************************************
enable
bcf PORTC,0; pone a 0 rs
bcf PORTC,1; pone a 0 rw
bsf PORTC,2; pone a 1 E
bcf PORTC,2;
return
;**********************************************************************************
;SUBRUTINA DEL PULSO DE HABILITACI�N
;PARA INICIALIZACI�N Y CONFIGURACI�N
;**********************************************************************************
escribe

bsf PORTC,0
bcf PORTC,1
bsf PORTC,2; pone a 1 E
bcf PORTC,2;
return
;**********************************************************************************
; SUBRUTINAS DE RETARDOS
;**********************************************************************************
delay_50us

movlw .15
movwf cont_1
rep_0
decfsz cont_1,1
goto rep_0
return
;**********************************************************************************
delay_200us

movlw .65
movwf cont_1
rep_1
decfsz cont_1,1
goto rep_1
return
;**********************************************************************************
delay_2ms

movlw .50
movwf cont_1
rep_8
movlw .12
movwf cont_2
rep_9
decfsz cont_2,1
goto rep_9
decfsz cont_1,1
goto rep_8
return
;**********************************************************************************
delay_5ms

movlw .147
movwf cont_1
rep_4
movlw .10
movwf cont_2
rep_5
decfsz cont_2,1
goto rep_5

decfsz cont_1,1
goto rep_4
return
;**********************************************************************************
delay_15ms

movlw .246
movwf cont_1
rep_2
movlw .19
movwf cont_2
rep_3
decfsz cont_2,1
goto rep_3

decfsz cont_1,1
goto rep_2
return
;**********************************************************************************
delay_37ms

movlw .50
movwf cont_1
rep_6
movlw .245
movwf cont_2
rep_7
decfsz cont_2,1
goto rep_7

decfsz cont_1,1
goto rep_6
return
;**********************************************************************************
delay_120ms

movlw .155
movwf cont_1
rep_10
movlw .255
movwf cont_2
rep_11
decfsz cont_2,1
goto rep_11
decfsz cont_1,1
goto rep_10
return
;**********************************************************************************
end

;
***********************************************************************************
*******************
;
***********************************************************************************
*******************
;****** *** *** *** ***
*************************************************
;****** *** *** ******** ******** *** *** ***
*************************************************
;****** *** *** ******** ******** *** *** ***
*************************************************
;****** *** *** *** ******** *** *
***************************************************
;****** *** ******** *** ******** *** *** **
**************************************************
;****** *** ******** *** ******** *** *** ***
*************************************************
;****** *** *** *** *** *** ****
************************************************
;
***********************************************************************************
*******************
;
***********************************************************************************
*******************

También podría gustarte