PDA

View Full Version : 8x2 Lcd



rshaver
- 10th July 2007, 04:18
Hi
I am new to PIC's and Picbasic and am trying to get an 8x2 LCD working in 4 bit mode. I am using the following code and it works with a 16x2. The controllers are the same and the starting address of each line are the same. Is there something else I need to do or just start check the wiring again. All that shows are 8 blocks on the first line. I am not reading a pot at this time just trying to get it to display, pot= . I forget where the code came from so sorry to who ever wrote it for not getting your name in here.


' For PIC16F88 and melabs PICBASIC PRO Compiler
'
' Read pot and display on LCD

' Define LCD pins
Define LCD_DREG PORTA
Define LCD_DBIT 4
Define LCD_RSREG PORTB
Define LCD_RSBIT 6
Define LCD_EREG PORTB
Define LCD_EBIT 3

' Allocate variables
x Var Byte


ANSEL = %00010000 ' Make the pot analog and rest digital
CMCON = 7 ' Set PORTA to digital

Pause 100 ' Wait for LCD to start


mainloop: Adcin 4, x ' Read the pot

Lcdout $fe, 1, "pot=", #x ' Send value to LCD

Pause 100 ' Do it about 10 times a second

Goto mainloop ' Do it forever

End




Thanks
Ron

Darrel Taylor
- 10th July 2007, 04:53
The first thing to do is make sure that the display uses an HD44780 controller.
You should see the number on one of the chips if it does.

If it does, then the problem may be due to timing differences.

Try this ...

DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 5000
DEFINE LCD_DATAUS 500

PAUSE 3000
LCDOUT $FE,1
PAUSE 2000

LCDOUT $FE,1,"HELLO:",$FE,$C0,"WORLD!"

STOPAnd if by chance it works, start reducing the numbers until it stops working, then add a little back in for safety.

paul borgmeier
- 10th July 2007, 06:15
Define LCD_DREG PORTA
Define LCD_DBIT 4
...
ANSEL = %00010000 ' Make the pot analog and rest digital
...
mainloop: Adcin 4, x ' Read the pot

Looks to me you are using RA4 as both a data line digital output for the LCD and an analog input for the pot - pick one and move the other. Your ANSEL has it as the analog input now ... makes sense the LCD is not working.

paul borgmeier
- 10th July 2007, 06:48
Looking into my crystal ball a bit more ... you do not have many defines for the LCD (see manual). Are you relying on the default values for those you have not shown? (not the best of practices if you are)

I am predicting that

Define LCD_DBIT 4
should be

Define LCD_DBIT 0
(only if you have the four data lines on RA0-RA3). If not, RA5 is input only and also will be causing you grief.

Let us know....

rshaver
- 10th July 2007, 13:00
Darrel

I will give that a try when I get home this afternoon.

Paul

I have tried Define LCD_DBIT 0 with the same results. But will set it back to this when I try it again.

Thanks to both of you for the suggestions. I'll let you know how it goes.

Ron

paul borgmeier
- 10th July 2007, 17:58
Use 0 if your four data lines are RA0-RA3
Use 4 if your four data lines are RA4-RA7 (but this will not work as noted above)

If you still have issues, you might want to post a schematic and the rest of your code (if there is more) - more and better info usually means more and better help

Good Luck

rshaver
- 10th July 2007, 22:33
Thanks for the help.. It is up and working. Don't really know what happened. The code looks the same except for:

DEFINE LCD_LINES 2
ANSEL = %00000000

and:

Define LCD_DBIT 0

I had tried the LCD_DBIT 0 before but no help.. And ANSEL =%00000000. So maybe the LCD_LINES 2... I did not think that made a difference. But I greatly appreciate the help. It made me look at things and I did learn some more.

Ron