LCD with PIC16F687


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2006
    Posts
    36

    Default LCD with PIC16F687

    I am new to using the PICBASIC but I have background experience with PIC microcontrollers. I am trying to learn how to use an LCD with a PIC16F687. I have tried to copy the example that I found on the MELABS website but it does not seem to functioning. The program will compile just fine but when the micro does not seem to be doign anything when powered up. I am using a scope and it appears that the Data bit pins are just cycling on and off about every 500 ms. I am not sure what I am supposed to be looking at. I would assume that the pins would be switching at a fast rate but I am not seeing that happen. I modified my program to use the PORTC instead of PORTA for the data bits. No other pins are changing. Any suggestions? Thanks for the help.

    Below is the code.

    DEFINE OSC 4

    DEFINE LCD_DREG PORTC 'set LCD DATA port
    DEFINE LCD_DBIT 4 'set starting DATA bit (0 or 4) if 4-bit
    DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
    DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit
    DEFINE LCD_EREG PORTB ' Set LCD Enable port
    DEFINE LCD_EBIT 6 ' Set LCD Enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
    DEFINE LCD_LINES 2 ' Set number of lines on LCD
    DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
    DEFINE LCD_DATAUS 50 ' Set data delay time in us

    'CMCON = 7
    ADCON1 = 7
    ANSEL = %00000000
    TRISA = %00000000
    TRISB = %00000000
    TRISC = %00000000
    PORTA = %00000000
    PORTB = %00000000
    PORTC = %00000000

    Pause 500 ' Wait for LCD to startup

    loop: 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 loop ' Do it forever

  2. #2
    Join Date
    Apr 2006
    Location
    Michigan
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    I had a similiar problem. Turned out I was configuring registers wrong. I notice some of the pins that you are using can also be analog. You need to make them digital for the LCD command to work. Try making ANSEL = %11111111. I can't remember if %00000000 is analog or digital, but I thought it was analog.

  3. #3
    Join Date
    Apr 2006
    Location
    Michigan
    Posts
    70


    Did you find this post helpful? Yes | No

    Default

    You also need to make anselh=%00001111. Anselh is the analog register for port C while ansel is the register for port A. Like I said though I may have the 0's and 1's backwards. I always get confused and have to experiment. The four 0s at the beginning are don't cares.

  4. #4
    Join Date
    May 2006
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Apparently that was what I needed to do. I did not have the ANSELH register set. To set each pin to the Digital function, each bit must be set to a "0", so ANSELH = %00000000. Thanks.

    My LCD works now and gives me the Hello World example that I have seen in numerous examples. Thanks.

  5. #5
    Join Date
    May 2006
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Would you have any advice for setting the configuration bits? Now I am manually changing them before I load the program into the microcontroller.

    I want to disable the watchdog timer and master reset to be internal.

    Thanks.

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    read the FAQ, there's a huge thread about that http://www.picbasic.co.uk/forum/showthread.php?t=543
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Is this code not initialising the LCD properly?
    By Platypus in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 30th January 2010, 19:14
  2. 16f688 LCD what have I done wrong
    By spitfiredriver in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th August 2009, 19:54
  3. LCD Problem
    By karenhornby in forum General
    Replies: 3
    Last Post: - 19th June 2008, 11:43
  4. Need help with LCD number display.
    By Steve Matson in forum mel PIC BASIC
    Replies: 8
    Last Post: - 26th June 2007, 23:07
  5. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30

Members who have read this thread : 0

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