New user frustration (16F688 + LCD)


Closed Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2013
    Posts
    7

    Unhappy New user frustration (16F688 + LCD)

    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

  2. #2
    Join Date
    Feb 2010
    Location
    USA, New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default Re: New user frustration (16F688 + LCD)

    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.

    Best Regards,
    Paul
    The way to avoid mistakes is to gain experience. The way to gain experience is to make mistakes.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: New user frustration (16F688 + LCD)

    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:
    Code:
    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.

  4. #4
    Join Date
    Feb 2013
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: New user frustration (16F688 + LCD)

    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/arch...hp/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

  5. #5
    Join Date
    Feb 2013
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: New user frustration (16F688 + LCD)

    Here is my schematic....

    Name:  LCD schematic.JPG
Views: 3297
Size:  69.2 KB

    Thanks again,

    Bill

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: New user frustration (16F688 + LCD)

    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.

  7. #7
    Join Date
    Feb 2013
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: New user frustration (16F688 + LCD)

    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

  8. #8
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: New user frustration (16F688 + LCD)

    If you get LCD working.

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

    LCDOUT $FE,$C0,"Hello."

    and

    LCDOUT $FE,$C0,"World."

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: New user frustration (16F688 + LCD)

    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.

  10. #10
    Join Date
    Feb 2013
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: New user frustration (16F688 + LCD)

    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

  11. #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: New user frustration (16F688 + LCD)

    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.

Similar Threads

  1. Interfacing with Arduino I2C LCD
    By norohs in forum Documentation
    Replies: 47
    Last Post: - 30th May 2017, 18:53
  2. PICbasic and 40X4 lines LCD
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th January 2013, 22:42
  3. LCD using 4 data lines, Lab X1
    By queenidog in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th January 2013, 23:10
  4. LCD Low Power
    By kduck63 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th December 2012, 00:05
  5. forum posting frustration
    By Heckler in forum Forum Requests
    Replies: 8
    Last Post: - 16th March 2012, 11:31

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts