PDA

View Full Version : Is this code not initialising the LCD properly?



Platypus
- 28th January 2010, 20:49
Hi,

I have been trying to get a standard 44780 LCD to work but all I get is Lines 1 & 3 lit up with solid blocks, and nothing on Lines 2 & 4. See Photo.



The PIC is a16F886 and the set-up is all correctly wired and has been proven to work using a HEX file given to me by a friend who programs in ASM. Unfortunately he knows nothing about PicBasic...

The Code I've tried is;


'************************************************* ******************************
'* 20 x 4 LCD for Display *
'* *
'* LCD connected as follows: *
'* LCD PIC PWR *
'* 01 Vss Ground *
'* 02 Vdd 5 volts *
'* 03 Vo Ground (contrast) *
'* 04 RS 24 PortB.3 *
'* 05 RW Ground *
'* 06 E 23 PortB.2 *
'* 07 DB0 No connect *
'* 08 DB1 No connect *
'* 09 DB2 No connect *
'* 10 DB3 No connect *
'* 11 DB4 25 PortB.4 *
'* 12 DB5 26 PortB.5 *
'* 13 DB6 27 PortB.6 *
'* 14 DB7 28 PortB.7 *
'* 15 A 5 volts (backlight) *
'* 16 K Ground (backlight) *
'* *
'************************************************* ******************************

' Defines
'************************************************* ******************************

DEFINE OSC 4 'using a 4 MHz oscillator
DEFINE LCD_DREG PORTB 'LCD data port
DEFINE LCD_DBIT 4 'LCD data starting bit 0 or 4
DEFINE LCD_RSREG PORTB 'LCD register select port
DEFINE LCD_RSBIT 3 'LCD register select bit
DEFINE LCD_EREG PORTB 'LCD enable port
DEFINE LCD_EBIT 2 'LCD enable bit
DEFINE LCD_RWREG PORTB 'LCD read/write port (Not Used This Time)
DEFINE LCD_RWBIT 1 'LCD read/write bit (Not Used This Time)
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE LCD_LINES 4 'Number lines on LCD
DEFINE LCD_COMMANDUS 1500 'Command delay time in us
DEFINE LCD_DATAUS 44 'Data delay time in us


' Main Program
'************************************************* ******************************
PAUSE 500 ' Wait .5 second for PIC and LCD to boot

ADCON1 = 7 ' disable A/D converters
ANSEL = 0 ' disable analog converters

high portc.4 'Turn on LED to show PIC works
pause 500
flags = 0 'Put in in case LCD not initialised on power-up
pause 500
lcdout $FE,1 ' Clear LCD
LCDout "Some words for test"
END

The PIC is working OK (LED lights-up)
Can you see what I'm doing wrong?

tekart
- 28th January 2010, 20:59
Nice LCD! :)

Do you have your data pins connected to the HIGH 4 bits of the display?? I made the mistake of using the LOW 4 bits once.

And check your R/W hookup too.

Platypus
- 28th January 2010, 22:08
Yes the High bits are connected (orange wires, LCD Pin1 is on the left)
I have pulled the R/W pin to ground for permanent write mode.

It's so frustrating!

Bruce
- 28th January 2010, 22:14
Add ANSELH = 0 to disable PORTB analog.

WOZZY-2010
- 29th January 2010, 02:38
Also,

Here is something else to look at, that frustrated me for a while.

Note on the specs that the Vo LCD voltage may be specified relative to the supply voltage (Vdd) and not ground.

Use a 20K pot wired as a voltage divider to feed the Vo and check that the output voltage is close to the spec. a 5k or 10k pot will work too.

On mine at least, there was a fairly narrow range, where the LCD was readable.

It turned out that mine was working all along, I just didn't know it.

Bob

Archangel
- 29th January 2010, 05:11
RW bit ? are you going to read from the LCD memory to the PIC ? IF not
just tie it to ground, I do the same for the contrast bit, pin 3. I NEVER use a contrast pot and have yet to need one.
You might try adding FLAGS = 1 into your code, at least until you are sure everything is working. Check the Data Sheet and see if that PIC has comparators on portB and turn them off if so. And Finally TRISB=0
so your PIC knows the LCD requires outputs.

"PIC working ok LED lights up"
That's because the HIGH command will manipulate the TRIS register, I think probably the TRISB = 0 or TRISB = %00000000 will make it work.
Oh BTW I see you are new here, WELCOME !

Platypus
- 29th January 2010, 10:20
Thanks all for the suggestions, I'll give them a go when I get home from work.

Cheers

Platypus
- 29th January 2010, 18:37
Thanks all,

The solution was ANSELH
I had thought ANSEL covered this chip but I guess there is a high register that needs setting.:rolleyes:

Back to the datasheet...........

Archangel
- 30th January 2010, 19:14
Thanks all,

The solution was ANSELH
I had thought ANSEL covered this chip but I guess there is a high register that needs setting.:rolleyes:

Back to the datasheet...........

And Thank You for the feedback, It adds to my arsenal of experience.