PDA

View Full Version : New user frustration (16F688 + LCD)



wcpesp
- 3rd February 2013, 02:27
Hello, I'm new to PIC's and still on my trial period using PBP3. I have a fairly good understanding of electronics, and have written alot of programs in BASIC (about 30 years ago!). PBP3 seems like a great program, and I got off to a good start with simple LED control programs and testing my tweaks.

But today, I have spent 6+ frustrating hours and really havent gotten anywhere. My confidence and ambition is on the floor, so I'm reaching out for help....

All I want to do, is get the 4-bit "Hello World" LCD display program, provided by PBP as an example, to run with my 16F688.

I believe the root problem is that the LCDOUT command is set up to use PortB.3 for the LCD Enable signal. But, 16F688 doesnt have a PortB, it only has PortA and PortC. I tried to add a statement to DEFINE PORTC.0 (Pin-10 on the 16F688) but I keep getting ASM Error 113 (symbol not defined). I've tried many other things, too....some generating errors, some not. I put an LED lighting command inside the loop, to make sure its working, and it is. I just get nothing on the display except for solid black boxes on power-up.

Would someone please give me a hand? I could really use the help, to get moving forward again.

Heres the raw/original sample program I am trying to use, its straight from the PBP3 website. It was apparently written for Ver 2.6 and I have Ver 3.0.6.1

' Name : LCD.pbp
' Compiler : PICBASIC PRO Compiler 2.6
' Assembler : PM or MPASM
' Target PIC : 16F or 18F
' Hardware : LCD display
' Oscillator : Any internal or external
' Keywords : LCDOUT
' Description : PICBASIC PRO program to demonstrate operation of an LCD in 4-bit mode.
'

' LCD should be connected as follows:
' LCD PIC
' DB4 PortA.0
' DB5 PortA.1
' DB6 PortA.2
' DB7 PortA.3
' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.3 <============ 16F688 doesnt have a Port B
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)
' DB0-3 No connect

Pause 500 ' 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


Thanks for any help on this!

Bill :confused:

prstein
- 3rd February 2013, 06:16
You can use the DEFINE statements as in the manual. E.g.,


' Set LCD Enable port
DEFINE LCD_EREG PORTX


Also, have a look at the LCD_AnyPin thread (http://www.picbasic.co.uk/forum/showthread.php?t=7038).

Best Regards,
Paul

HenrikOlsson
- 3rd February 2013, 08:24
Hi,
The 16F688 has both an ADC and a comparator connected to some of its pins. These peripherals can interfere when trying to use the pin as digital I/O. On some devices these peripherals are disabled by default, on some they are not. On the 16F688 they are NOT disabled so you need to turn them off. How to turn them off also varies across chips but it's quite easy to find in the datasheet. For the the 16F688 you'd do:

CMCON = 7 'Disable both comparators
ANSEL = 0 ' Set all analog pins to digital

Then Paul showed you how to remap the pins used by the LCDOUT command. I suggest you do it the standard way with the DEFINE directive as shown in the manual before starting to play with special stuff like the LCD_AnyPin code. If you can't get it to work can you post a schematic of your setup?

/Henrik.

wcpesp
- 3rd February 2013, 11:55
Thank you Paul and Henrik, for trying to help.

Henrik, I tried the CMCON = 7 command, but it generated a syntax error and wouldnt compile. I searched the web for similar topics, and it was suggested to use CMCON0 = 0, and that compiled without any error. However, the LCD still doesnt work.

In my search, I found this thread http://www.picbasic.co.uk/forum/archive/index.php/t-4896.html , which mentions a patch for PBP, which fixes 16F688 register issues. I wonder if thats what I need to do?

Here is my current program, which only produces a line of black boxes on the LCD. The LED does blink, as expected....


CMCON0 = 7 'Disable both comparators
ANSEL = 0 ' Set all analog pins to digital

' Set LCD Enable port
DEFINE LCD_EREG PORTC

' Set LCD Enable bit
DEFINE LCD_EBIT 0

LED VAR PORTC.1 ' Pin-9 on 16F688

Pause 500 ' Wait for LCD to startup

mainloop:
Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Hello" ' Display Hello

high LED

Pause 500 ' Wait .5 second

Lcdout $fe, 1 ' Clear LCD screen
Lcdout "World"

LOW led

Pause 500 ' Wait .5 second

Goto mainloop ' Do it forever

End


Thanks for any other further help or ideas.

Bill

wcpesp
- 3rd February 2013, 13:21
Here is my schematic....

6833

Thanks again,

Bill

HenrikOlsson
- 3rd February 2013, 15:28
Hi,
Yeah, sorry about that, it should of course be CMCON0 = 7 and ANSEL = 0.

You have D7 on the LCD connected to RA3 which is also the MCLR pin on the 16F688. There are two issues with that.
1) The MCLR functionallity would have to be disabled via the CONFIG bits in order for that pin to work as anything but MCLR.
2) On the 16F688, even with MCLR disabled, RA3 can only work as an inputs as it lacks output driver circuitry.

You'll be better off moving the datalines to PortC.0-3, put the Enable signal on PortC.4 and RS on PortC.5. Use the DEFINE directive to change the pin-mapping, just as you did for the Enable signal.

/Henrik.

wcpesp
- 3rd February 2013, 15:51
Hi Henrik,

Yes, in the period of time since I posted my schematic, I learned that RA3 is input-only. I was in the process of re-mapping all of my PortA connections to PortC, which is also what you suggested. Now I have high hopes that this may work! I will post an update after testing......

Thanks again,

Bill

tasmod
- 3rd February 2013, 16:08
If you get LCD working.

I'm not on PBP3 but shouldn't it be:

LCDOUT $FE,$C0,"Hello."

and

LCDOUT $FE,$C0,"World."

HenrikOlsson
- 3rd February 2013, 16:29
Depends on what you want to do. $FE, $1 clears the display while $FE, $C0 moves the cursor to the second line. Neither is wrong...
Either way it has nothing to do with the version of PBP, it's the way the HD44780 controller on the LCD works.

wcpesp
- 3rd February 2013, 16:35
Hey hey, it works! :)

Henrik, I changed all of the ports over to PortC (0-5) as you suggested. When I powered-up, the display said "ello" and "orld", in the upper-left corner. It was obviously dropping the first character, but to me that was 99.999% success!

Tasmod, I put your code in, and now the display says "Hello." and "World." in the lower-left corner. So, you were right.

You guys helped me get over my first MAJOR hurdle, now I can work on the LCD text formatting and other smaller issues. I learned alot through this, mostly that each PIC device must be studied very closely and its ports set/configured properly. I know I have a long way to go, but its a great relief to be moving forward again.

Thanks so much for your help!

Bill

HenrikOlsson
- 3rd February 2013, 16:52
That's great!
Either you just need a little longer Pause at the beginning to allow the display to power up or, more likely, the clear screen command takes a little longer to execute than you are giving it.
You can increase the timedelay for command with DEFINE LCD_COMMANDUS 2000, for example.

Once you have a couple of projects under your belt you get a feeling of what might be the problem when something doesn't work. I'd say that having analog functions switched on pins you want to use as digital is by far the most common issue people stumble across around here, followed by read-modify-write issues which sometimes is caused by analog functions not being switched off in the first place.

Keep it up and welcome to the forum!
/Henrik.