INSTITUTO POLITÉCNICO NACIONAL
Nombre de la Escuela: Escuela Superior de Ingeniería Mecánica y Eléctrica “ESIME” MICROPROCESADORES
Practica 3: Display 3: Display LCD
Profesor: Agustín Vázquez Zarate
Grupo: 6CV1
Objetivo: Programar el pic 18F4550 para que muestre una oración en un display
Introducción: Cuando los simples indicadores luminosos con led ya no son suficientes, habitualmente el siguiente paso para todo programador es ir por una pantalla lcd 16×2. Llegados a este punto, encontramos que existen módulos LCD que facilitan la interfaz con este periférico. El estándar en la industria para estos módulos con “controlador a bordo” es el chipset HD44780 (y otros más compatibles desarrollados a partir de este), para los cuales encontramos soporte en prácticamente cualquier plataforma: Arduino, PIC, AVR, MSP430, etc. En esta entrada introducimos la librería de control altamente portable a cualquier microcontrolador, la cual puede ser utilizada tanto para PIC, como AVR y prácticamente cualquier otro microcontrolador o computadora embebida que se nos ocurra. Nuestra foto de portada para el artículo muestra módulos LCD con iluminación azul y letras color blanco. Conexiones básicas de una pantalla lcd 16×2 El HD44780 permite conectarse a través de un bus de 4 u 8 bits. El modo de 4 bits permite usar solo 4 pines para el bus de datos, dándonos un total de 6 o 7 pines requeridos para la interfaz con el LCD, mientras que el modo de 8 bits requiere 10 u 11 pines. El pin RW es el único que puede omitirse si se usa la pantalla en modo de solo escritura y deberá conectarse a tierra si no se usa. En este caso el microcontrolador no puede leer desde el chip controlador de pantalla, pero en la mayoría de las situaciones esto no es necesario y nuestra librería no implementa aun esta funcionalidad. Notese que todas estas configuraciones son ilustrarivas, la pantalla se puede conectar a cualquier combinación de pines posible, ya que nuestra librería soporta usar cualquier pin como parte del bus de datos y señales de control. Diagrama para modo de 4 bits Las conexiones para el módo de 4 bits en un PIC16F88 se muestran a continuación. Se utilizan los primeros 4 bits del puerto A (RA0-RA3) como bus de datos. RB0 como señal de habilitación (E) y RB1 como señal de selección de registro (RS).
2
Diagrama para modo de 8 bits Las conexiones para el módo de 8 bits son algo más complicadas, ya que requerimos las 8 lineas de datos activas. En este caso utilizaremos los 8 bits del puerto B, aunque se puede usar cualquier combinación de pines con nuestra librería. RA0 ahora funciona como señal de selección de registro (RS) y RA1 como señal de habilitación (E).
3
Desarrollo:
Código: ;*************************************************************************************************** ; This file is a basictemplateforassemblycodefor a PIC18F4550. Copy ; this file intoyourprojectdirectory and modifyoradd to it as needed. ; ; The PIC18FXXXX architectureallowstwointerruptconfigurations. This ; templatecodeiswrittenforpriorityinterruptlevels and the IPEN bit ; inthe RCON registermust be set to enableprioritylevels. If IPEN is ; left in its default zerostate, onlytheinterrupt vector at 0x008 will ; beused and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables willnot ; beneeded. ; ; Refer to the MPASM User'sGuideforad ditionalinformationonthe * ; features of theassembler. ; ; Refer to the PIC18FXX50/XX55 Data Sheetforadditional ; informationonthearchitecture and instruction set. ; ;*************************************************************************************************** ; ; Filename: PlantillaASM * ; Date: 12/01/11 ; File Version: 1.0 ; ; Author: Ing. Alejandro Vicente Lugo Silva ; Company: Acad. Computación ICE - ESIME Zac. ; ;*************************************************************************************************** ;
* * * * * * * * * * * * * * * * * * * * * * *
4
; Files required: P18F4550.INC ; ;***************************************************************************************************
* *
LIST P=18F4550, F=INHX32 ;directive to define processor #include
;processorspecific variable definitions ;*************************************************************************************************** ;Configuration bits CONFIG PLLDIV = 5 ;(20 MHz crystalon PICDEM FS USB board) CONFIG CPUDIV = OSC1_PLL2 CONFIG USBDIV = 2 ;Clocksourcefrom 96MHz PLL/2 CONFIG FOSC = HSPLL_HS CONFIG FCMEN = OFF CONFIG IESO = OFF CONFIG PWRT = OFF CONFIG BOR = ON CONFIG BORV = 3 CONFIG VREGEN = ON ;USBVoltageRegulator config WDT = OFF config WDTPS = 32768 config MCLRE = ON config LPT1OSC = OFF config PBADEN = OFF ;NOTE: modifyingthisvalueherewon'thaveaneffect ;ontheapplication. Seethe top of themain() function. ;By default the RB4 I/O pin isused to detectifthe ;firmwareshouldenterthebootloaderorthemainapplication ;firmwareafter a reset. In order to do this, itneeds to ;configure RB4 as a digital input, therebychangingitfrom ;theresetvalueaccording to thisconfiguration bit. config CCP2MX = ON config STVREN = ON config LVP = OFF config ICPRT = OFF config XINST = OFF config CP0 = OFF config CP1 = OFF config CP2 = OFF config CP3 = OFF config CPB = OFF config CPD = OFF config WRT0 = OFF config WRT1 = OFF config WRT2 = OFF config WRT3 = OFF config WRTB = OFF config WRTC = OFF config WRTD = OFF config EBTR0 = OFF config EBTR1 = OFF config EBTR2 = OFF config EBTR3 = OFF config EBTRB = OFF
; Dedicated In-CircuitDebug/Programming ; Extended Instruction Set
; Boot Block WriteProtection
5
;*************************************************************************************************** ;Variabledefinitions ; These variables are onlyneedediflowpriorityinterrupts are used. ; More variables may be needed to store otherspecialfunctionregistersused ; intheinterruptroutines.
;*************************************************************************************************** ;Reset vector ; Thiscodewillstartexecutingwhen a resetoccurs. RESET_VECTOR ORG goto
0 Main
;go to start of maincode
;*************************************************************************************************** ;*************************************************************************************************** ;Start of mainprogram ; Themainprogramcodeis placed here. ORG 0x1000 CALL CONFIGPUERTOS Main ; *** maincodegoeshere ** CALL Inicializa_LCD ;inicializamoslcd MOVLW CLEAR ;INSTRUCCION PARA LLEGAR AL LCD MOVWF DATO ;MOVEMOS AL PARAMETRO DATO CALL Comando_LCD MOVLW DDRAM_L1 ; INSTRUCCION PARA MOVERSE A LA LINEA 1 ;SUMAMOS 6 PARA DESPLAZARNOS 6 CARACTERES Y CENTRAR EL TEXTO MOVWF DATO ;MOVEMOS AL PARAMETRO DATO CALL Comando_LCD MOVLW 'Y' MOVWF DATO CALL Dato_LCD MOVLW 'A' MOVWF DATO CALL Dato_LCD MOVLW ' ' MOVWF DATO CALL Dato_LCD MOVLW 'P' MOVWF DATO CALL Dato_LCD MOVLW 'R' MOVWF DATO CALL Dato_LCD MOVLW 'O' MOVWF DATO CALL Dato_LCD MOVLW 'F' MOVWF DATO CALL Dato_LCD MOVLW '!' MOVWF DATO CALL Dato_LCD MOVLW '!'
6
MOVWF DATO CALL Dato_LCD MOVLW '!' MOVWF DATO CALL Dato_LCD MOVLW ' ' MOVWF DATO CALL Dato_LCD MOVLW ':' MOVWF DATO CALL Dato_LCD MOVLW '(' MOVWF DATO CALL Dato_LCD CLRF PORTD ;LIMPIAMOS PUERTO D GOTO Main ; end of main ;***************************************************************************************************; Start of subrutines CONFIGPUERTOS CLRF WREG MOVLW H'0F' MOVWF ADCON1 CLRF TRISD CLRF PORTD #include ;*************************************************************************************************** ;*************************************************************************************************** ;End of program END
;*************************************************************************************************** ; Autor: VAZQUEZ ZARATE AGUSTIN ; Fecha: 24 de Noviembre de 2015 ; Archivo: LCD.INC ; Biblioteca para el display LCD ;*************************************************************************************************** ;Acciones del display CLEAR EQU H'01' CURSOR_HOME EQU H'02' ;Control del display DISPLAY_CONTROL DON CURSOR_ON BLINK_ON
* * * *
EQU H'08' EQU H'04' EQU H'02' EQU H'01'
;Modo de entrada DISPLAY_MODE EQU H'04' INCREMENT EQU H'02' SHIFT EQU H'01' ;Shift_Cursor Display SHIFT_CUR_LEFT
EQU H'13'
7
SHIFT_CUR_RIGHT SHIFT_DISP_LEFT SHIFT_DISP_RIGHT
EQU H'17' EQU H'1B' EQU H'1F'
;Function Set FUNCTION_SET EQU H'20' EIGHT_BIT EQU H'10' LINE_5x7 EQU H'03' LINE_5x10 EQU H'07' LINES_5x7 EQU H'0B' DDRAM_L1 EQU H'80' DDRAM_L2 EQU H'C0' DDRAM_L3 EQU H'90' DDRAM_L4 EQU H'D0' ;Acciones del display CLEAR CURSOR_HOME
EQU H'01' EQU H'02'
;Control del display DISPLAY_CONTROL EQU H'08' DON EQU H'04' CURSOR_ON EQU H'02' BLINK_ON EQU H'01' ;Modo de entrada DISPLAY_MODE EQU H'04' INCREMENT EQU H'02' SHIFT EQU H'01' ;Shift_Cursor Display SHIFT_CUR_LEFT SHIFT_CUR_RIGHT SHIFT_DISP_LEFT SHIFT_DISP_RIGHT
EQU H'13' EQU H'17' EQU H'1B' EQU H'1F'
;Function Set FUNCTION_SET EQU H'20' EIGHT_BIT EQU H'10' LINE_5x7 EQU H'03' LINE_5x10 EQU H'07' LINES_5x7 EQU H'0B' DDRAM_L1 EQU H'80' DDRAM_L2 EQU H'C0' DDRAM_L3 EQU H'90' DDRAM_L4 EQU H'D0' ;Variables necesarias para el funcionamiento del LCD alfanumérico. cblock 0x50 DATO DATOTEMP RTMUL RETARDO1 RETARDO2 endc ;Funciones para escritura y configuración del LCD alfanumérico. Delay1K
8
retardo0 DECFSZ RTMUL goto retardo1 gotofinretardo retardo1 MOVLW .137 MOVWF RETARDO1 ciclo1 DECFSZ RETARDO1 GOTO retardo2 GOTO retardo0 retardo2 MOVLW .10 MOVWF RETARDO2 ciclo2 DECFSZ RETARDO2 GOTO ciclo2 GOTO ciclo1 finretardo RETURN Comando_LCD: MOVFF DATO, DATOTEMP RRCF DATO RRCF DATO RRCF DATO RRCF DATO MOVFF DATO, PORTD BCF PORTD, RD4 BCF PORTD, RD5 BSF PORTD, RD6 MOVLW .60 MOVWF RTMUL CALL Delay1K BCF PORTD, RD6 MOVFF DATOTEMP, PORTD BCF PORTD, RD4 BCF PORTD, RD5 BSF PORTD, RD6 MOVLW .60 MOVWF RTMUL CALL Delay1K BCF PORTD, RD6 RETURN Dato_LCD: , DATOTEMP RRCF DATO RRCF DATO RRCF DATO RRCF DATO MOVFF DATO, PORTD BSF PORTD, RD4 BCF PORTD, RD5 BSF PORTD, RD6 MOVLW .60
9
MOVWF RTMUL CALL Delay1K BCF PORTD, RD6 MOVFF DATOTEMP, PORTD BSF PORTD, RD4 BCF PORTD, RD5 BSF PORTD, RD6 MOVLW .60 MOVWF RTMUL CALL Delay1K BCF PORTD, RD6 RETURN Inicializa_LCD: MOVLW .137 MOVWF RTMUL CALL Delay1K MOVLW 0x02 ;no puede ser 2 db ser MOVWF PORTD BSF PORTD, RD6 MOVLW .60 CALL Delay1K BCF PORTD, RD6 MOVLW .187 MOVWF RTMUL CALL Delay1K MOVLW FUNCTION_SET IORLW LINES_5x7 MOVWF DATO CALL Comando_LCD MOVLW DISPLAY_CONTROL IORLW DON MOVWF DATO CALL Comando_LCD MOVLW CLEAR MOVWF DATO CALL Comando_LCD MOVLW DISPLAY_MODE IORLW INCREMENT MOVWF DATO CALL Comando_LCD RETURN
Conclusiones: En esta práctica se dificulto debido a que teníamos que manejar una nueva biblioteca para el funcionamiento del LCD , tuvimos que aplicar nuevos comandos para llegar al LCD y moverlo de línea , además de que hubo pequeñas dificultades al conectar el LCD debido a una conexión errónea.
10