PDA

View Full Version : Strange LCD problem with PIC16F876A



Glenn
- 14th October 2009, 22:23
Today I started to build a project with a variant of PIC I never used before, 16F876A, but since its the little brother of my old fauvorite pic 16F877A I didnt think it would be any problems..

HOWEVER..

I got LCD-problems, and they are so strange. ..To boil it down I wrote a short test program..




@ DEVICE PIC16F876A,HS_OSC,LVP_OFF,WDT_OFF,PROTECT_OFF

DEFINE OSC 20 ' Lets work at 20 MHz

' DEFINE LCD_DREG PORTA ' Set LCD Data port
' DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
' DEFINE LCD_RSREG PORTA ' Set LCD Register Select port
' DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit
' DEFINE LCD_EREG PORTB ' Set LCD Enable port
' DEFINE LCD_EBIT 3 ' Set LCD Enable bit
' DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
' DEFINE LCD_LINES 2 ' Set number of lines on LCD
' DEFINE LCD_COMMANDUS 1500 ' Set command delay time in us
' DEFINE LCD_DATAUS 44 ' Set data delay time in us


pause 2000 ' Gracetime for the LCD

Main:

toggle PORTB.5
LCDOUT $FE, 1, "Hello"
LCDOUT $FE, $C0, "World"
pause 2000
LCDOUT $FE, 1, "1234567890123456"
pause 500
LCDOUT $FE, 1, "ABCDEFGHIJKLMNOP"
pause 500
LCDOUT $FE, 1, "abcdefghijklmnop"
pause 500

goto main:

End


..The result is:

First the display says

Hello
World

..Waits 2 seconds and then

34567890123456
waits .5 sec
CDEFGHIJKLMNOP
waits .5 sec
cdefghijklmnop
waits .5 sec
llo
World

..and then continue..

Why is it eating the two leading chars ? ..I tried the display on another breadboard with an
16F877A, works perfectly fine..

I tried to add all defines, and tweak some values (currently commented out in the code), no difference.

Any ideas ?

Darrel Taylor
- 14th October 2009, 22:36
Hi Glen,

Try increasing LCD_COMMANDUS
DEFINE LCD_COMMANDUS 2000
Most of the displays I have take at least 1.6mS to complete a clear screen.
<br>

Glenn
- 14th October 2009, 22:44
Try increasing LCD_COMMANDUS
DEFINE LCD_COMMANDUS 2000
Most of the displays I have take at least 1.6mS to complete a clear screen.
<br>

Yes, that fixed the problem.

STRANGE.. I never had to change this value before ? I can't understand why the same
test program works on the same display, with the same pins, at the same frequency on a 16F877A ?

Well, as long as it works I'm happy :) thanks alot! :)

Acetronics2
- 15th October 2009, 08:56
Hi,

Melabs changed the default value from 2000 to 1500 with release 2.50 ... WHY ??? , Good question !!!

note you also can avoid resetting the LCD for each printed line ...

by using LCDOUT $FE,2 .... ( home command )

or LCDOUT $FE, $80 ... ( beginning of first line )

and overwrite the existing displayed characters.

Alain