LCD R/S works on Port A but not Port B


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2008
    Location
    Carrollton, TX
    Posts
    6

    Default LCD R/S works on Port A but not Port B

    Have been trying on both a 16F627A and now a 16F84A'
    The first code below works, but when I switch the R/S pin from PortA.2 to Port B.2, I get a blank LCD screen. I can't see what I'm doing wrong. Can anyone help?

    LCD Display
    ' ================
    '
    '
    ' The connection between the LCD display and the microcontroller is as follows:
    '
    ' Display Microcontroller pin
    ' DB4 RB4
    ' DB5 RB5
    ' DB6 RB6
    ' DB7 RB7
    ' E RB3
    ' RS RA2
    '
    ' Compiler: PicBasic Pro
    '
    ' Modifications
    ' ==========
    '
    '************************************************* *******************************************

    ' DEFINITIONS
    define LCD_DREG PORTB
    define LCD_DBIT 4
    define RSREG PORTA
    define LCD_RSBIT 2
    define LCD_EREG PORTB
    define LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50

    TRISA = 0 ' Register A pins are outputs
    TRISB = 0 ' Register B pins are outputs


    PAUSE 500 ' Wait 0.5sec for LCD to initialize

    OPTION_REG = $80

    LCDOUT $FE, 1 ' Clear LCD
    LCDOUT $FE, $C0
    LCDOUt "ClockWorks"
    '

    END




    The following does not work:
    ' LCD Display
    ' ================
    '
    '
    ' The connection between the LCD display and the microcontroller is as follows:
    '
    ' Display Microcontroller pin
    ' DB4 RB4
    ' DB5 RB5
    ' DB6 RB6
    ' DB7 RB7
    ' E RB3
    ' RS RB2
    '
    ' Compiler: PicBasic Pro
    '
    ' Modifications
    ' ==========
    '
    '************************************************* *******************************************

    ' DEFINITIONS
    define LCD_DREG PORTB
    define LCD_DBIT 4
    define RSREG PORTB
    define LCD_RSBIT 2
    define LCD_EREG PORTB
    define LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50

    TRISA = 0 ' Register A pins are outputs
    TRISB = 0 ' Register B pins are outputs


    PAUSE 500 ' Wait 0.5sec for LCD to initialize

    OPTION_REG = $80

    LCDOUT $FE, 1 ' Clear LCD
    LCDOUT $FE, $C0
    LCDOUt "ClockNot"


    END
    TDon

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


    Did you find this post helpful? Yes | No

    Default

    Try adding this to your code. FLAGS=0 and for the 627A add cmcon=7 to disable the comparators on portA. It is just me but I would initialize the Ports before the Tris with PortB = 0 and PortA = 0 and lose this: OPTION_REG = $80. OPTION_REG = $80 sets WPU when portB is set as input, since you are using it as outputs, it is not needed.
    Last edited by Archangel; - 10th February 2009 at 05:46.
    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.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    You've screwed up your defines...

    Instead of...

    Define LCD_RSREG PORTB

    you've written...

    define RSREG PORTB

    PICBasic doesn't error on define typo's, and you must have chosen the default setting in the option that works.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    You've screwed up your defines...

    Instead of...

    Define LCD_RSREG PORTB

    you've written...

    define RSREG PORTB

    PICBasic doesn't error on define typo's, and you must have chosen the default setting in the option that works.
    SHARP EYES ! Good catch.
    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.

  5. #5
    Join Date
    Jan 2008
    Location
    Carrollton, TX
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Thanks Melanie and Joe,

    And I had even read Melanies post about not screwing up the DEFINE statements!
    What happened was that I had copied some defines from the pbppic14.lib file and then modified them for PBP, but I missed changing them to upper case.

    This is a good example of why you should post your code when you ask a question. No telling how long it would have taken me to find that.

    thanks again
    TDon

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 works at 4MHz, but not 12 or 16MHz
    By Max Power in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th June 2008, 01:23
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Running an LCD on different port
    By malc-c in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 18th December 2006, 06:41

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