Anyone on the forum know about PIC16F84 ASM and 1602 LCD displays?

MrChips

Joined Oct 2, 2009
35,279
BSF and BCF should be ok to use. But let’s try something differently.

Instead of the same routine to write to the LCD, we will use two separate routines, one for commands and another for characters.

Edit: I am rusty with PIC ASM code, so maybe someone else can see if my code is correct.

Code:
; pass command in CMD
SEND_CMD
            MOVLF   0x00
            MOVWF PORTA
            MOVLF    CMD
            MOVWF    PORTB
            CALL    DELAY_3
            MOVLF    0x02
            MOVWF   PORTA
            CALL    DELAY_3
            MOVLF   0x00
            MOVWF   PORTA
            RETURN

;pass character in CHAR
SEND_CHAR
            MOVLF   0x01
            MOVWF PORTA
            MOVLF    CHAR
            MOVWF    PORTB
            CALL    DELAY_3
            MOVLF    0x03
            MOVWF   PORTA
            CALL    DELAY_3
            MOVLF   0x01
            MOVWF   PORTA
            RETURN
 

MrChips

Joined Oct 2, 2009
35,279
Normally, for problems of this kind, the way we would tackle this is with an oscilloscope. We would be looking at voltage levels, timing, and noise.

Before trying the code changes I posted in post #41, try this first.
Apply a weak pullup, about 33 kΩ from the RS signal to Vcc.
 

MrChips

Joined Oct 2, 2009
35,279
If all you have is a DVM (digital voltmeter), you can conduct this static test. Using your code that works, display ‘0’ followed by ‘8’.

The first ‘0’ is to establish that the LCD has been initialized.
In the code to display ‘8’ halt the program before and then after toggling the E signal. Measure the voltages on all control and data signals at the LCD.

(Since there is no HALT instruction on the PIC16F84, you will have to use a GOTO on to itself.)
 

Thread Starter

Bigphil

Joined Sep 11, 2025
15
BSF and BCF should be ok to use. But let’s try something differently.

Instead of the same routine to write to the LCD, we will use two separate routines, one for commands and another for characters.

Edit: I am rusty with PIC ASM code, so maybe someone else can see if my code is correct.

Code:
; pass command in CMD
SEND_CMD
            MOVLF   0x00
            MOVWF PORTA
            MOVLF    CMD
            MOVWF    PORTB
            CALL    DELAY_3
            MOVLF    0x02
            MOVWF   PORTA
            CALL    DELAY_3
            MOVLF   0x00
            MOVWF   PORTA
            RETURN

;pass character in CHAR
SEND_CHAR
            MOVLF   0x01
            MOVWF PORTA
            MOVLF    CHAR
            MOVWF    PORTB
            CALL    DELAY_3
            MOVLF    0x03
            MOVWF   PORTA
            CALL    DELAY_3
            MOVLF   0x01
            MOVWF   PORTA
            RETURN
MrChips - I have incorporated your changes into the .asm with slight modifications, see attached .asm.
It works but unfortunately has the same problem i.e. displays 'PLEASE WAIT' but the moment it sends character 8 the display goes blank.
Re. your post 42 if you check my post 13 you will see that I have already been round it with the 'scope.
I checked that it was sending the correct ascii code for 8, also checked the levels and timings and couldn't see any noise.

WHOOPS - forgot about the weak pullup - will try that tomorrow.
 

Attachments

MrChips

Joined Oct 2, 2009
35,279
MrChips - I have incorporated your changes into the .asm with slight modifications, see attached .asm.
It works but unfortunately has the same problem i.e. displays 'PLEASE WAIT' but the moment it sends character 8 the display goes blank.
Re. your post 42 if you check my post 13 you will see that I have already been round it with the 'scope.
I checked that it was sending the correct ascii code for 8, also checked the levels and timings and couldn't see any noise.

WHOOPS - forgot about the weak pullup - will try that tomorrow.
I suggested weak pullup with the assumption that you did not have an oscilloscope.

If you did have an oscilloscope I would like to believe that that is all you need to diagnose this problem. The oscilloscope would show whether signal loading or noise is the problem.

There is something going on that neither you nor I can pinpoint.
As far as I can see your E sequence is incorrect and yet your code works.
I have given you my suggested code which you said does not work.

In my line of work (over 50 years as an electronics engineer) I would pursue this with an oscilloscope and not give up until the problem is resolved. This is important to me because my line of work relies on SW and HW working reliably as expected with no surprises. The next job depends on every step working as expected.

I am sorry that this is frustrating for you.
 

MrChips

Joined Oct 2, 2009
35,279
Also, I am sorry that at this point we are grasping at straws.
I am not at my homebase otherwise I would have been able to try and duplicate your HW and SW in order to pinpoint this issue. Many others have successfully interfaced PICs with 1602 LCD.
 

Thread Starter

Bigphil

Joined Sep 11, 2025
15
I suggested weak pullup with the assumption that you did not have an oscilloscope.

If you did have an oscilloscope I would like to believe that that is all you need to diagnose this problem. The oscilloscope would show whether signal loading or noise is the problem.

There is something going on that neither you nor I can pinpoint.
As far as I can see your E sequence is incorrect and yet your code works.
I have given you my suggested code which you said does not work.

In my line of work (over 50 years as an electronics engineer) I would pursue this with an oscilloscope and not give up until the problem is resolved. This is important to me because my line of work relies on SW and HW working reliably as expected with no surprises. The next job depends on every step working as expected.

I am sorry that this is frustrating for you.
Well - I have re-invented the wheel and checked it again using the 'scope.
The sequence of events is exactly as the datasheet states, all the timing paramaters far exceed the minimum requirements (their is no maximum requirements) and no sign of any noise.
I have even checked using the number 7 which it quite happily displays and sequence is identical, different ASCII data of course.
I have also tried to generate a number 8 using custom characters and that didn't work.
I used the video at the link below to assist me as the datasheet doesn't provide much imformation :-

Maybe it's time to admit that I'm beaten and go the 7 segment display route.

Thanks for all your help.

Phil.
 

ericgibbs

Joined Jan 29, 2010
21,625
Hi BP,
This is program written using Oshonsoft.
The zip file includes the Asm,Lst and Hex files.
If you are able to use the Hex file to program your PIC, when run it will display
"Ready"
Ref the Asm file you may need to edit in order to compile on your PC.

Running this program should give a test result on your circuit build.
E

Added: lcdtest1.txt [ the Basic file ] for reference

ScreenHunter 03.gif
 

Attachments

Last edited:

Embededd

Joined Jun 4, 2025
212
@Bigphil

I usually work in C language, not assembly. I’ve noticed two common issues when working with LCD 16*2

1) Setting the contrast voltage properly
2) Initializing the LCD correctly

The second one LCD initialization seems to be the real troublemaker. There were times when my code was working perfectly before, showing text on the display. But later, when I ran the same exact code again, nothing showed up on the LCD.

At first, I thought it must be a wiring or loose connection issue, but after some checking, I realized the problem was actually with the LCD initialization function. Sometimes the LCD doesn’t initialize properly
 
Top