PDA

View Full Version : LCD -- melabs sample program



Michael
- 10th June 2017, 15:25
I've written code far more complex that this but for the very first time I need to engage an LCD and LCDOUT. Believe it or not, I've been in electronics for years but never had the need for an LCD display.

SO --

As a very basic introduction, I looked at the sample program here --

http://melabs.com/samples/PBP-mixed/lcd.htm

What could be simpler right ?

BUT --

It doesn't work and I've triple checked everything. Only to see that in the code, Port A4 and port B3 AREN'T EVEN REFERENCED IN THE FRIGGIN'
PROGRAM ! They're setup to connect to register select and enable on the LCD BUT why in the hell would they be assigned to a port and then not even used ! ?? And as a sidenote how about making mention of the backlight pins 15 and 16 on the LCD? Think that might be worth mentioning?

Melabs documentation (to me) has always been piss poor but please, could someone explain why you would connect these pins to A4 and B3 and then do NOTHING with those ports ??? !!! *&$%&()

Michael
- 10th June 2017, 15:36
I do realize that the ports default low and maybe that's what RS and E need so perhaps that's why they aren't referenced. Whatever is going on with this, i can't get it to work.
using a 16C72 so I put in adcon1 = 7 and define osc 4 I even tried every combination of RS and E high/low

HenrikOlsson
- 10th June 2017, 15:38
Backlight is not part of the LCD controler (HD44780 or compatible) so it's got nothing to do with the LCDOUT command.

As far as the ports goes I'm not sure I follow. What do you mean by not even used? Have you looked in the generated assembly listing and determined they'r not used or do you mean in the the PBP program?

They ARE used, behind the scenes, by the LCDOUT command. And what the comments in the example program shows are the default Connection pinout. This can be changed by using a series of DEFINE directives, see the LCDOUT command in the manual.

There are several reasons for it not working. What chip are you using? Make sure all the pins used for the LCD are configured as digital pins (comparator(s) turned off, digital buffers enabled).

/Henrik.

richard
- 10th June 2017, 15:38
ever heard of default settings ?

from the book

PBP assumes the LCD is connected to specific pins unless told otherwise using DEFINEs. It assumes the LCD will be used with a 4-bit bus with data lines DB4 - DB7 connected to PIC MCU PORTA.0 - PORTA.3, Register Select to PORTA.4 and Enable to PORTB.3.


have you set port a to be digital ?

Michael
- 10th June 2017, 17:13
As I said, never picked up an LCD display in my life so yes, knowing the backlight pins beforehand would have been nice. Who's to say the backlight wasn't powered through the Vdd and Vss? If you're new to something, best to spell it all out, right?

My bad on not considering the code within the command LCDOUT and A4 and B3 being part of it's instruction set.

It would have been nice to see that in larger print or part of the example. We all are newbies at one point with everything so no need to -- well, you know.

Thanks kindly for the reply. It must be the fact I'm using a 16c72 but like I say, ADCON1 = 7 sets all pins to digital and it has Ports A & B as most PICs do.

Everything compiles fine also -- I'll get there. Spent too much time on it yesterday.

Michael
- 10th June 2017, 17:13
I'll have to look at ADCON1 -- maybe it doesn't influence Port A -- who knows.

mark_s
- 10th June 2017, 17:26
I hope you know the pic16"C"72 is a one time programmable pic vs. pic16"F"72. So you only get one shot to make it work. Also a common beginner's LCD problem is the contrast control.

Michael
- 10th June 2017, 20:46
contrast is fine.

I have a few thousand 16c72.

just a beginner with LCDOUT. It's using default ports is something you don't think of.

Michael
- 10th June 2017, 22:27
Ok, I give up. Hours spent on this. Maybe someone could be so kind as to look at the code and see why this doesn't function. Something simple perhaps. I realize the 16C72 is an antiquated part but I have a ton of them. I even used another LCD (yes hd44780's) -- even tried another xtal etc. Mclr is high to Vdd, ADCON1 is making pins digital. Changed the defaults because A4 isn't TTL on the 16C72 so used B7 and C7 for RS and E to avoid conflicts -- even did a TRIS on all the pins. Power supply is fine -- this is crazy.

DEFINE OSC 4 '16C72
ADCON1 = 7
TRISA = %00000000
TRISB = %00000000
TRISC = %00000000

DEFINE LCD_DREG PORTA
DEFINE LCD_DBIT 0 'a0 thru a3
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 7
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 7
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

Pause 1000 ' Wait for LCD to startup

mainloop:
Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Hello" ' Display Hello
Pause 500 ' Wait .5 second

Lcdout $fe, 1 ' Clear LCD screen
Lcdout "World"
Pause 500 ' Wait .5 second

Goto mainloop ' Do it forever

End

Michael
- 10th June 2017, 22:28
and for what it's worth all I get are a group of 16 squares on the 2nd line

richard
- 10th June 2017, 23:47
do you have the unused data pins 4 to 7 tied to gnd along with the r/w pin ?

richard
- 11th June 2017, 00:35
do you have the unused data pins 4 to 7 tied to gnd along with the r/w pin ?
I think that should be
do you have the unused lcd data pins 0 to 3 tied to gnd along with the r/w pin ?
can't remember don't use them much . point is the pins should not be left floating

Scampy
- 11th June 2017, 09:44
The only difference I can see between your example code and the code I use for LCD in my projects is that my code has


DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us


After the definition for LCD_Lines



DEFINE LCD_DREG PORTB ' LCD Data port
DEFINE LCD_DBIT 0 ' starting Data bit (0 or 4)
DEFINE LCD_EREG PORTB ' LCD Enable port
DEFINE LCD_EBIT 5 ' Enable bit (on EasyPIC 5 LCD)
DEFINE LCD_RSREG PORTB ' LCD Register Select port
DEFINE LCD_RSBIT 4 ' Register Select bit (on EasyPIC 5 LCD)
DEFINE LCD_BITS 4 ' LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 4 ' number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Command delay time in us
DEFINE LCD_DATAUS 50 ' Data delay time in us


I always use PORTB as I have an EasyPIC development board and that's the default wiring for the LCD, so can't comment on using pins on other ports for the enable / reset lines, but in theory, if they are set to digital it should be OK

Michael
- 11th June 2017, 17:44
Yes Scampy, I had that in the code as well but commented it out -- tried it both ways. No go. This is so weird. And yes, I have rw tied to ground but not the unused data pins on the LCD -- heading to the workbench to try that.

Michael
- 11th June 2017, 17:58
always something embarrassing -- in my frustration to try everything, forgot to move data to db0 - db3. it was still on the default of db4 -- db7

head in sand.

andybarrett1
- 19th June 2017, 13:42
always something embarrassing -- in my frustration to try everything, forgot to move data to db0 - db3. it was still on the default of db4 -- db7

head in sand.

I did exactly the same the other day......Any room in that sand ???

Andy