[SOLVED] LCD on PIC16F887 not working

Status
Not open for further replies.

Luis Daniel Bolaños

Member level 2
Joined
Apr 4, 2014
Messages
47
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Activity points
342
Hi everybody!

I'm working on the PIC16F887 trying to make a temperature sensor using LM35 and displaying temperature on LCD 16x2. In the beginning I used 7 segments and it worked fine. Then, I copied some code I found online for LCD and it works on proteus simulation. However, when using hardware the LCD just shows some random pixels on... Here is the code I use just for the display

Code:
VISUALIZAR		
START_LCD
        call INICIA_LCD   ;LCD Configuration
        call M1           ;First message
        call LINEA2       ;Second line configuration
        call M2           ;Second message
        goto CONVERSION

;Mensaje a enviar
M1
        movlw ' '
		movwf PORTC
		call ENVIA
        movlw ' '
		movwf PORTC
		call ENVIA
        movlw 'T'       ;Mueve 'H' a W
		movwf PORTC       ;PORTC = W
		call ENVIA        ;Prints on LCD
		movlw 'e'
		movwf PORTC
		call ENVIA
		movlw 'm'
		movwf PORTC
		call ENVIA
		movlw 'p'
		movwf PORTC
		call ENVIA
		movlw 'e'
		movwf PORTC
		call ENVIA
        movlw 'r'
		movwf PORTC
		call ENVIA
		movlw 'a'
		movwf PORTC
		call ENVIA
		movlw 't'
		movwf PORTC
		call ENVIA
		movlw 'u'
		movwf PORTC
		call ENVIA
        movlw 'r'
		movwf PORTC
		call ENVIA
        movlw 'a'
		movwf PORTC
		call ENVIA
        movlw ':'
		movwf PORTC
		call ENVIA
        return
M2
        movf TMP3, W
        call DECO_LCD
		movwf PORTC
		call ENVIA
        movf TMP2, W
        call DECO_LCD
		movwf PORTC
		call ENVIA
		movf TMP1, W
        call DECO_LCD
		movwf PORTC
		call ENVIA
        movlw '°'
		movwf PORTC
		call ENVIA
        movlw 'C'
		movwf PORTC
		call ENVIA
        movlw ' '
		movwf PORTC
		call ENVIA
		movlw 'N'
		movwf PORTC
		call ENVIA
		movlw 'i'
		movwf PORTC
		call ENVIA
		movlw 'v'
		movwf PORTC
		call ENVIA
        movlw 'e'
		movwf PORTC
		call ENVIA
        movlw 'l'
		movwf PORTC
		call ENVIA
        movlw ':'
		movwf PORTC
		call ENVIA
        movlw ' '
		movwf PORTC
		call ENVIA
        btfss PORTE,0
        goto no
        movlw 'X'
        goto send
no      movlw 'O'
send    movwf PORTC
		call ENVIA
        return

;Subrutina para inicializar el lcd
INICIA_LCD
        bcf PORTD,0      ; RS=0 Instruction mode
        movlw 0x01		 ; Clear screen
		movwf PORTC
		call COMANDO     ; Se da de alta el comando
		movlw 0x0C       ; Selecciona la primera línea
		movwf PORTC
		call COMANDO     ; Se da de alta el comando
		movlw 0x3C       ; Se configura el cursor
		movwf PORTC
		call COMANDO     ; Se da de alta el comando
		bsf PORTD, 0     ; Rs=1 Data mode
        return

;Subrutina para enviar comandos
COMANDO
        bsf PORTD,1	    ; Pone la ENABLE en 1
        call demora      ; Tiempo de espera
        bcf PORTD, 1    ; ENABLE=0
		call demora
		return

;Subrutina para enviar un dato
ENVIA
		bsf PORTD,0     ; RS=1 MODO DATO
		call COMANDO    ; Se da de alta el comando
		return
;Configuración Lineal 2 LCD
LINEA2
       	bcf PORTD, 0    ; RS=0 MODO INSTRUCCION
        movlw 0xc0		; Selecciona linea 2 pantalla en el LCD
		movwf PORTC
		call COMANDO    ; Se da de alta el comando
        return

DECO_LCD        addwf PCL, F
                retlw b'00110000'
                retlw b'00110001'
                retlw b'00110010'
                retlw b'00110011'
                retlw b'00110100'
                retlw b'00110101'
                retlw b'00110110'
                retlw b'00110111'
                retlw b'00111000'
                retlw b'00111001'
                retlw b'00110000'
                retlw b'00110000'

On the configuration bits I turned OFF the WDT and LVP bits. What else can I try? What am I doing wrong?

In proteus I use the LM016L LCD 16x2 display. My LCD is the SSC2B16DLYY, and the datasheet is **broken link removed**

The connection I'm using on ISIS and breadboard is the following

 

hi

try to increase the delays after sending commands and data . also you need to use some resistor (fixed or variable ) at pin number 3 of the lcd as the proteus will show u the value but in real life u need to adjust the contrast.

thank you

mL
 

try to increase the delays after sending commands and data . also you need to use some resistor (fixed or variable ) at pin number 3 of the lcd as the proteus will show u the value but in real life u need to adjust the contrast.
mL

Now I use a potentiometer for contrast, and already tried with multiples delays, nothing works.
This is what happens



I can't understand how simulation works perfect, and nothing works on hardware :sad:
 

hi

simulation is good for testing
there are many things that need in actual hardware. if u connect a 12v supply in simulation at the supply points, nothing will happen. but in real hardware,the controller will go bad. are you sure that your lcd's are fine?
 

Never trust simulators - they assume things that may not be there is real life.

Your program will not work anyway, you need to read the data sheet of the LCD and note the delays you have to use after sending each data/command byte. Your program flow is basically correct but there are no delays so you feed the LCD much faster than it can digest information.

Incidentally, there are better ways of sending strings of characters to the LCD than loading them and writing them individually, look at using a table (DT directive if you are using MPLAB) and read the characters in a loop, the code will be much smaller.

Brian.
 


The subroutine demora actually has the delays. And I have tried already with 200 ms, which is way more that what the LCD needs.
 

Maybe the fuses or MCLR not connected in VCC.

This is the most common error (no MCLR)!!!
 

You need a long delay (~100mS) at the begining of 'INICIA_LCD' to allow the LCD to perform it's internal reset, otherwise it will ignore the configuration you send it.

Brian.
 

Maybe the fuses or MCLR not connected in VCC.

I already checked that haha.

You need a long delay (~100mS) at the begining of 'INICIA_LCD' to allow the LCD to perform it's internal reset

You mean before anything? Right after the call? I did try what you said, didn't work :-(
 
Last edited:

Where is the TRISx setting of the LCD port ?
 

I always like to write code with the settings in the file beginning with "includes" etc...

As it stands your code is confusing and maybe is missing part of the code!!!

See also the flowchart boot lcd ... and respect the times of each instruction!!!

 
Last edited:

Thank you all, I'm ashamed to say that it seems like the LCD is bad. I changed it and works!
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…