Is this code not initialising the LCD properly?


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2010
    Location
    In the Shed
    Posts
    6

    Default Is this code not initialising the LCD properly?

    Hi,

    I have been trying to get a standard 44780 LCD to work but all I get is Lines 1 & 3 lit up with solid blocks, and nothing on Lines 2 & 4. See Photo.



    The PIC is a16F886 and the set-up is all correctly wired and has been proven to work using a HEX file given to me by a friend who programs in ASM. Unfortunately he knows nothing about PicBasic...

    The Code I've tried is;
    Code:
    '*******************************************************************************
    '*                 20 x 4 LCD for Display                                      *
    '*                                                                             *
    '*            LCD connected as follows:                                        *
    '*              LCD         PIC         PWR                                    *
    '*             01 Vss                  Ground                                  *
    '*             02 Vdd                  5 volts                                 *
    '*             03 Vo                   Ground (contrast)                       *
    '*             04 RS      24 PortB.3                                           *
    '*             05 RW                   Ground                                  *
    '*             06 E       23 PortB.2                                           *
    '*             07 DB0                  No connect                              *
    '*             08 DB1                  No connect                              *
    '*             09 DB2                  No connect                              *
    '*             10 DB3                  No connect                              *
    '*             11 DB4     25 PortB.4                                           *
    '*             12 DB5     26 PortB.5                                           *
    '*             13 DB6     27 PortB.6                                           *
    '*             14 DB7     28 PortB.7                                           *
    '*             15 A                    5 volts (backlight)                     *
    '*             16 K                    Ground  (backlight)                     *
    '*                                                                             *
    '*******************************************************************************
    
    ' Defines
    '*******************************************************************************
    
    DEFINE OSC 4                'using a 4 MHz oscillator
    DEFINE LCD_DREG PORTB       'LCD data port 
    DEFINE LCD_DBIT 4           'LCD data starting bit 0 or 4 
    DEFINE LCD_RSREG PORTB      'LCD register select port 
    DEFINE LCD_RSBIT 3          'LCD register select bit 
    DEFINE LCD_EREG PORTB       'LCD enable port 
    DEFINE LCD_EBIT 2           'LCD enable bit 
    DEFINE LCD_RWREG PORTB      'LCD read/write port (Not Used This Time)
    DEFINE LCD_RWBIT 1          'LCD read/write bit (Not Used This Time) 
    DEFINE LCD_BITS 4           'LCD bus size 4 or 8 
    DEFINE LCD_LINES 4          'Number lines on LCD 
    DEFINE LCD_COMMANDUS 1500   'Command delay time in us 
    DEFINE LCD_DATAUS 44        'Data delay time in us 
    
    
    ' Main Program                                                 
    '*******************************************************************************
        PAUSE 500      ' Wait .5 second for PIC and LCD to boot
        
        ADCON1 = 7    ' disable A/D converters
        ANSEL = 0     ' disable analog converters
        
        high portc.4   'Turn on LED to show PIC works
        pause 500
        flags = 0      'Put in in case LCD not initialised on power-up
        pause 500
        lcdout $FE,1 ' Clear LCD 
        LCDout "Some words for test" 
        END
    The PIC is working OK (LED lights-up)
    Can you see what I'm doing wrong?
    Attached Images Attached Images  

  2. #2
    Join Date
    Sep 2008
    Location
    Maine, USA
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Check wiring

    Nice LCD!

    Do you have your data pins connected to the HIGH 4 bits of the display?? I made the mistake of using the LOW 4 bits once.

    And check your R/W hookup too.
    "Do or do not, there is no try" Yoda

  3. #3
    Join Date
    Jan 2010
    Location
    In the Shed
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Yes the High bits are connected (orange wires, LCD Pin1 is on the left)
    I have pulled the R/W pin to ground for permanent write mode.

    It's so frustrating!

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Add ANSELH = 0 to disable PORTB analog.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Jan 2010
    Location
    PHILADELPHIA, PA - USA
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    Also,

    Here is something else to look at, that frustrated me for a while.

    Note on the specs that the Vo LCD voltage may be specified relative to the supply voltage (Vdd) and not ground.

    Use a 20K pot wired as a voltage divider to feed the Vo and check that the output voltage is close to the spec. a 5k or 10k pot will work too.

    On mine at least, there was a fairly narrow range, where the LCD was readable.

    It turned out that mine was working all along, I just didn't know it.

    Bob
    Wozzy-2010

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    RW bit ? are you going to read from the LCD memory to the PIC ? IF not
    just tie it to ground, I do the same for the contrast bit, pin 3. I NEVER use a contrast pot and have yet to need one.
    You might try adding FLAGS = 1 into your code, at least until you are sure everything is working. Check the Data Sheet and see if that PIC has comparators on portB and turn them off if so. And Finally TRISB=0
    so your PIC knows the LCD requires outputs.

    "PIC working ok LED lights up"
    That's because the HIGH command will manipulate the TRIS register, I think probably the TRISB = 0 or TRISB = %00000000 will make it work.
    Oh BTW I see you are new here, WELCOME !
    Last edited by Archangel; - 29th January 2010 at 06:15.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    Join Date
    Jan 2010
    Location
    In the Shed
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Thanks all for the suggestions, I'll give them a go when I get home from work.

    Cheers

  8. #8
    Join Date
    Jan 2010
    Location
    In the Shed
    Posts
    6


    Did you find this post helpful? Yes | No

    Talking Sorted

    Thanks all,

    The solution was ANSELH
    I had thought ANSEL covered this chip but I guess there is a high register that needs setting.

    Back to the datasheet...........

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Platypus View Post
    Thanks all,

    The solution was ANSELH
    I had thought ANSEL covered this chip but I guess there is a high register that needs setting.

    Back to the datasheet...........
    And Thank You for the feedback, It adds to my arsenal of experience.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. RF Modules
    By tonyfelloni in forum mel PIC BASIC Pro
    Replies: 44
    Last Post: - 26th June 2010, 18:42
  2. lcd stops after about 5 minutes and gets stuck
    By robertpeach in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th September 2009, 13:03
  3. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 22:31
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 09:26
  5. LCD Problem
    By karenhornby in forum General
    Replies: 3
    Last Post: - 19th June 2008, 12:43

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