PDA

View Full Version : Simple LCD code not working..



davewanna
- 23rd April 2008, 13:36
Hi all,

I have a couple of projects with 16F877a's and 4 line LCD panels working fine.

I wanted to do something smaller scale, and have a 16F84a and a 2x16 LCD. I have used this LCD in the past and it was fine. I have written a very short program just to get the LCD going, but alas it doesn't show anything... Below is my code:



define osc 4

' Define LCD registers and bits
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3

TRISA = %11111

butup var porta.0
butdn var porta.1
light var portb.1

light = 0

pause 1000
light = 1


lcdout $fe,1

Start:

lcdout $fe,$80,"line one"
lcdout $fe,$C0,"line two"

pause 500
toggle light

goto Start


On turn-on, the LCD enables (1st row black boxes, 2nd row blank) then waits the 1000 and clears the LCD. After that, I get nothing at all on the LCD, but the led blinks away happily.

I've done this before on a 16F88 I think (albeit a while ago) which is why it is frustrating me so.

Can anyone point out anything I've done wrong in the code? Do I need to declare anything else, etc? I have checked and rechecked the wiring many times, if no-one can point out anything I will have to source and test another LCD incase that is the problem.

Thanks in advance.

Dave

mister_e
- 23rd April 2008, 14:55
In theory it has to work, you may have one of those LCD timing problem OR LVP mode set to on. try

for 16F877a

@ __CONFIG _XT_OSC & _LVP_OFF
define OSC 4

' Define LCD registers and bits
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 3
DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us

Play with the contrast pot, make sure the R/W pin is tied to low. Not better, you may need to play with COMMANDUS and DATAUS values.

For the 16F88 you may need to disable some Analog feature.


HTH

sayzer
- 23rd April 2008, 15:32
What about a line saying

TRISB = 0

mister_e
- 23rd April 2008, 15:43
;) Even if it's always a good practice, LCDOUT handle it for you.

LCDOUT "a"

.LST


0006 1683 02798 bsf STATUS, RP0 ; Point to trises
0007 1186 02799 bcf LCD_EREG, LCD_EBIT ; Set E to output
0008 1205 02800 bcf LCD_RSREG, LCD_RSBIT ; Set RS to output
0009 1205 02801 bcf LCD_RWREG, LCD_RWBIT ; Set RW to output
02802 if ((LCD_BITS) == 8)
02803 clrf LCD_DREG ; Set port to all output
02804 else
MPASM 5.14 A.ASM 4-23-2008 10:43:15 PAGE 3


LOC OBJECT CODE LINE SOURCE TEXT
VALUE

02805 if ((LCD_DBIT) == 0)
000A 30F0 02806 movlw 0f0h
02807 else
02808 movlw 0fh
02809 endif
000B 0585 02810 andwf LCD_DREG, F ; Set proper half of port to output

sayzer
- 23rd April 2008, 15:59
As an apprentice, I , respect masters always.



---------------

davewanna
- 24th April 2008, 03:53
Thanks all for the replies.. I originally had the TRISB = 0, but removed it to simplify, added it back in, no difference. Added the cammandus & dataus lines, still no difference.

I'm using the 16F84a for now, so no A/D, no LVP, I've made sure it has XT OSC.

And have fiddled the contrast pot, I know it's right now tho, as the blocks come up on the first line, and then when I LCDOUT $fe,1.... The screen clears.

I even measured continuity between the data pins on my pic, and the pins on the LCD incase I had a problem on my breadboard.

I think I'm going to have to get another LCD panel to rule that out as being the problem...

Any more suggestions I'd be happy to hear, but I now presume it's a hardware fault, seeings how it doesn't seem I stuffed up any of the code.

Thanks again,

Dave

edit - R/W is also tied low... I know this as when I first connected it, I tied it high, and nothing happened, when I tied it low, it now clears...

davewanna
- 28th April 2008, 12:39
Just a follow up...

I got another LCD the same, connected it, it came up with crazy characters on the screen... In desperation I swapped the cable I was using (IDE HDD cable) and low and behold it works.

On closer inspection, the cable I was using originally, has more conductors in it than pins on the plug. I pulled the plug apart, and there is a big copper bus-bar that connects certain pins to each other, and also I assume to ground. Must give some kind of shielding effect.

Anyway all sorted.

Thanks to everyone that helped...

Cheers
Dave

skimask
- 28th April 2008, 13:55
On closer inspection, the cable I was using originally, has more conductors in it than pins on the plug. I pulled the plug apart, and there is a big copper bus-bar that connects certain pins to each other, and also I assume to ground. Must give some kind of shielding effect.
Info you: Older IDE cables had 40 pins, newer ones have 80 pins, 40 normal + 40 grounds/shields, for use with the higher DMA speeds and transfer rates in the newer ATA spec's.