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

Thread Starter

Bigphil

Joined Sep 11, 2025
15
Hi all,

I'm trying to design and build a Rev. Counter for a Windmill to monitor the speed of the sails.
I'm using a Microchip Pic16F84 and a 1602 LCD display.
The unit needs to count from 0 to 12 RPM.
However when a send the Ascii value 8 and 9 the display goes blank, all other numbers (0 to 7) are OK.
I have replaced 8 and 9 with A and B and the display displays them.
I assumed the display was faulty and purchased another one from a different supplier but that does the same thing.

Any of you clever people got any ideas?

Regards,
Phil
 

Thread Starter

Bigphil

Joined Sep 11, 2025
15
Sorry I don't have a Circuit Diagram as my Schematic Editor does not have a model for the 1602 but it is connected as follows:-

Vo 10K pot to Vcc
Rs Port A bit 0
Rw Ground
E Port A bit 1
D0 to D7 to port B D0 to D7
Led+ Vcc via a 22 ohm
Led- Ground
Gnd Ground
Vcc Vcc

The Code is attached to the post above this one.

Regards

Phil
 

MrChips

Joined Oct 2, 2009
34,626
Sorry, I don't do PIC ASM.
However, I notice some inefficiencies in your code and I can make suggestions to help fix the problem.

Firstly, whenever you have to repeat the same code sequence, look for ways to create a single subroutine to simplify the coding.

For testing, create code to send one and only one character. Test it with the problematic characters.

Once that problem is resolved, create a subroutine to send a character string. In other words, you only need one call to a subroutine to display any text of any number of characters.
 

atferrari

Joined Jan 6, 2004
5,001
I am not sure how your "ASCII codes" look like
but 01H to 09H are non-printable characters. If some of them give an apparently valid result on the LCD, but those last two no, I would start revising what you are actually sending to the display controller.
 

MrChips

Joined Oct 2, 2009
34,626
There are all possible errors to be made. A systematic check of all steps will reveal the error.
Are you using 4-bit mode or 8-bit mode?

Here is my code snippet for 4-bit mode written in C.

C:
void LCD_init(void)
{
  LCD_ir(0x28);         // dual line, 4 bits
  LCD_ir(0x06);         // increment mode
  LCD_ir(0x0C);         // cursor turned off
  LCD_ir(0x10);         // cursor right
  LCD_ir(0x01);         // clear display
}

void LCD_ready(void)
{
  char busy;
  LCD_DDR = 0xF0;
  LCD_RW = 1;
  LCD_RS = 0;
  do
  {
    LCD_E  = 1;
    // high 4 bits read first
    // busy flag is D7 of LCD = bit 3 of P2IN
    busy = (LCD_IN & 0x08);
    LCD_E  = 0;
    LCD_E  = 1;
    LCD_E  = 0;
  } while (busy);
  LCD_OUT = 0;
  LCD_DDR = 0xFF;
}

void LCD_ir(char ch)
{
  LCD_ready();
  //LCD_RS = 0;      // not needed      // select instruction register
  //LCD_RW = 0;     // not needed
  LCD_OUT |= ((ch >> 4) & 0x0F);
  LCD_E = 1;
  LCD_E = 0;
  LCD_OUT = 0;
  LCD_OUT |= (ch & 0x0F);
  LCD_E = 1;
  LCD_E = 0;
}

void LCD_dr(char ch)
{
  LCD_ready();
  LCD_RS = 1;        // select data register
  //LCD_RW = 0;      // not needed
  LCD_OUT |= ((ch >> 4) & 0x0F);
  LCD_E = 1;
  LCD_E = 0;
  LCD_OUT = 0;
  LCD_RS = 1;
  LCD_OUT |= (ch & 0x0F);
  LCD_E = 1;
  LCD_E = 0;
}

void LCD_txt(char *s)
{
  while(*s) LCD_dr(*s++);
}
 

ericgibbs

Joined Jan 29, 2010
21,390
hi C,
He is using 8bit LCD.
When I run it in Oshonsoft I don't see what he is describing.
I get 'a T 1 3 5 7' in that sequence.

E

BCF PORTA,0 ;SEND COMMANDS
MOVLW B'00110000' ;8 BIT MODE 1 LINE 5x7 DOTS
CALL SEND2LCD
MOVLW B'00000001' ;CLEAR DISPLAY
CALL SEND2LCD
MOVLW B'00000010' ;RETURN HOME
CALL SEND2LCD
MOVLW B'00001100' ;DISPLAY ON NO CURSORR
CALL SEND2LCD
 

Thread Starter

Bigphil

Joined Sep 11, 2025
15
Thanks for all your help but I have now given up.
I modified the program to just display the number 8 (see attached) and checked all the data pins at the LCD with the 'scope. The ASCII code was correct for 8 (00111000) and good levels.
I then tried to do it using characters but several numbers were not displayed, one being TWO. The T and the W are displayed at the initial message (PLEASE WAIT) and the O displayed for ONE but when TWO - blank screen.
I now believe the LCD display technology is flawed and will have to resort to 7 Segment displays which is a shame because I hoped to run the unit from a 9 volt battery but as the 7 Segment displays take heavy current this will not be practical.

Regards
Phil.
 

Attachments

atferrari

Joined Jan 6, 2004
5,001
Thanks for all your help but I have now given up.
I modified the program to just display the number 8 (see attached) and checked all the data pins at the LCD with the 'scope. The ASCII code was correct for 8 (00111000) and good levels.
I then tried to do it using characters but several numbers were not displayed, one being TWO. The T and the W are displayed at the initial message (PLEASE WAIT) and the O displayed for ONE but when TWO - blank screen.
I now believe the LCD display technology is flawed and will have to resort to 7 Segment displays which is a shame because I hoped to run the unit from a 9 volt battery but as the 7 Segment displays take heavy current this will not be practical.

Regards
Phil.
I am sure that testing with sequences of different binary values every time could help you find what is wrong.

Sure it's your call to change the type of display, BUT, in doing so, you won't have learnt anything or increased your ability to troubleshoot a failure or advance on a new design. Just dodging...

Not to speak about the waste of time / efforts from YOU (and AAC members).
 

lichurbagan

Joined Jul 4, 2025
120
Hi all,

I'm trying to design and build a Rev. Counter for a Windmill to monitor the speed of the sails.
I'm using a Microchip Pic16F84 and a 1602 LCD display.
The unit needs to count from 0 to 12 RPM.
However when a send the Ascii value 8 and 9 the display goes blank, all other numbers (0 to 7) are OK.
I have replaced 8 and 9 with A and B and the display displays them.
I assumed the display was faulty and purchased another one from a different supplier but that does the same thing.

Any of you clever people got any ideas?

Regards,
Phil
You can find these links useful.
https://www.engineersgarage.com/displaying-ascii-characters-on-lcd-with-pic-microcontroller/
https://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller
https://cdn.sparkfun.com/assets/9/5/f/7/b/HD44780.pdf
https://www.pcbway.com/project/shareproject/Universal_HD44780_LCD_interface_e3f2df0c.html
 

MrChips

Joined Oct 2, 2009
34,626
There are four common issues with trying to get 1602 displays to work.

1) Adjusting and setting the contrast voltage properly.
2) Initializing the LCD.
3) Proper time delays when sending control signals.
4) Proper power supply decoupling.

Start by attempting to display a single character such as ’A’ or ‘0’.
The next step would be display a sequence of characters using an iterative loop.

For example, ’0’ to ‘9’.
‘0’ is 48 or 0x30.
Iterate ten times, incrementing the output register at each iteration.

If that works, try 16 characters from ‘A’ to ’P’.
 
Top