Whers is the typo'


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2007
    Location
    Lake Villa Il.
    Posts
    40

    Red face Whers is the typo'

    Hello all,
    I hate to do this, I have to ask for help. I can't get PORT D to work properly.
    Gear used:
    PBP V2.50b
    MCS Plus
    PIC 16f877a
    MELABS USB PROGRAMMER
    PICPROTO 64

    Program causing me toloose my sanity (what little I had):

    '************************************************* ***************
    '* Name : BCD True and Complimentary Switch Decoder *
    '* with 7segement LED display *
    '* *
    '* Author : Terry L.Garrett K9HA *
    '* Notice : Copyright (c) 2008 Terry L. Garrett *
    '* : All Rights Reserved *
    '* Date : 10/4/2008 *
    '* Version : 3.0 *
    '* Notes : 7 Segment LED display TEST *
    '* : Correct display for 0 to F HEX *
    '************************************************* ***************
    '************************************************* ***************
    ' PURPOSE:
    ' Read and display BCD 4 bit bcd switches, both TRUE AND COMPLIMENTARY
    '
    ' * * * System Defines * * *
    '
    '
    @ DEVICE pic16f877a, CPD_OFF
    @ DEVICE pic16f877a, PROTECT_OFF
    @ DEVICE pic16f877a, WRT_OFF
    '
    DEFINE OSC 4
    ADCON1=7 ' SETS PORTS AS ALL DIGITAL( I HOPE)
    '
    '????????????????????????????????????????????????? ????????????
    '
    INTCON=0 'I Think this turns off ALL INTERUPTS FOR PORTB????
    '
    '????????????????????????????????????????????????? ?????????????
    '
    '************************************************* ***************
    '
    ' Variable Descritptions:
    '
    ' NAME # bits location I/O Description
    ' Type 1 PortD0 IN LOW for TRUE
    ' HIGH for COMPLEMENTARY
    ' PortD.0 1 Program BIT VAR BIT
    '
    '************************************************* ***************
    '
    ' * * * VARIABLE DECLARATIONS * * *
    '
    ' NOTICE: bin2binary subroutine(s) are from melabs website
    ' Thank you, melabs
    '************************************************* *****************
    '
    B0 var byte 'Used in subroutine to generate LED Segment data
    'B1 var byte 'Used in subroutine to generate LED Segment data
    Type var BIT 'PortD.0
    '
    '************************************************* ***************
    ' DEVICE SET-UP
    '
    CLEAR ' Is this the proper place to put this?
    '
    TRISB=%11111111 ' ALL 8 BITS SET AS INPUT: HOEVER ONLY LOWER 4 REALLY USED.
    ' ' *** GROUND BITS 4-7 ***
    '
    PortB=%11111111 ' ALL BIT PRELOADED TO 1. Known condition.
    '
    TRISC=%00000000 'ALL BITS SET AS OUTPUT ( BITS 0-6: LED SEGMENTS 1-7
    '
    PortC=%11111111 'ALL BITS preloaded as HIGH (LED DISPLAY IS OFF)
    '
    TRISE.4=%0 ' Makes Port D DIGITAL I/O?
    '
    TRISD=%11111111 ' Ground bits 1-7
    '
    PortD.0=%0 ' PORTD.0 preloaded to ZERO (LOW). Known condition
    tYPE = PortD.0 ' Se
    '
    Main:
    while Type <1
    B0=PortB
    gosub lowloop
    wend
    '
    'while type = 1
    'gosub Highloop
    'wend
    goto main ' This should cause constant reading/input from PORTB
    '
    '************************************************* *************************
    '
    LowLoop:

    ' B0 = B1 ' Pass the PORTB data
    Gosub bin2seg ' Convert to segment value
    Poke PortC, B0 ' Put segment values out to LED
    Pauseus 1 ' Display it for 1 microsecond
    Poke PortC,$1E ' Turns off display
    pauseus 1 ' Display is OFF for 1 microsecond
    return ' RETURNS to MAIN; gets next PORTB data

    ' ************************************************** *****
    ' ************* 2nd level soubroutines follow ******************
    ' Convert binary number in B0 to segments for LED
    bin2seg: Lookup B0,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18,$88,$83,$C 6,$A1,$86,$8E],B0
    Return
    END
    ' CLEAN COMPILE 145 WORDS USED 10/04/2008 06:00:00 PM CDT
    '
    ' * note to self: this worked until you added the PORTD code, the wend while
    ' argument.
    '
    ' *!*! This don't work correctly




    Where did I go wrong?
    I know that a few will say RTFM, Ha Ihave and my wife says if I stay up late one more night
    that I can sleep with the dogs. I DO NOT HAVE A DOG.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Sneaky-geek View Post
    Hello all,
    I hate to do this, I have to ask for help. I can't get PORT D to work properly.
    Gear used:
    PBP V2.50b
    MCS Plus
    PIC 16f877a
    MELABS USB PROGRAMMER
    PICPROTO 64

    Program causing me toloose my sanity (what little I had):

    '************************************************* ***************
    '* Name : BCD True and Complimentary Switch Decoder *
    '* with 7segement LED display *
    '* *
    '* Author : Terry L.Garrett K9HA *
    '* Notice : Copyright (c) 2008 Terry L. Garrett *
    '* : All Rights Reserved *
    '* Date : 10/4/2008 *
    '* Version : 3.0 *
    '* Notes : 7 Segment LED display TEST *
    '* : Correct display for 0 to F HEX *
    '************************************************* ***************
    '************************************************* ***************
    ' PURPOSE:
    ' Read and display BCD 4 bit bcd switches, both TRUE AND COMPLIMENTARY
    '
    ' * * * System Defines * * *
    '
    '
    @ DEVICE pic16f877a, CPD_OFF
    @ DEVICE pic16f877a, PROTECT_OFF
    @ DEVICE pic16f877a, WRT_OFF
    '
    DEFINE OSC 4
    ADCON1=7 ' SETS PORTS AS ALL DIGITAL( I HOPE)
    '
    '????????????????????????????????????????????????? ????????????
    '
    INTCON=0 'I Think this turns off ALL INTERUPTS FOR PORTB????
    '
    '????????????????????????????????????????????????? ?????????????
    '
    '************************************************* ***************
    '
    ' Variable Descritptions:
    '
    ' NAME # bits location I/O Description
    ' Type 1 PortD0 IN LOW for TRUE
    ' HIGH for COMPLEMENTARY
    ' PortD.0 1 Program BIT VAR BIT
    '
    '************************************************* ***************
    '
    ' * * * VARIABLE DECLARATIONS * * *
    '
    ' NOTICE: bin2binary subroutine(s) are from melabs website
    ' Thank you, melabs
    '************************************************* *****************
    '
    B0 var byte 'Used in subroutine to generate LED Segment data
    'B1 var byte 'Used in subroutine to generate LED Segment data
    Type var BIT 'PortD.0
    '
    '************************************************* ***************
    ' DEVICE SET-UP
    '
    CLEAR ' Is this the proper place to put this?
    '
    TRISB=%11111111 ' ALL 8 BITS SET AS INPUT: HOEVER ONLY LOWER 4 REALLY USED.
    ' ' *** GROUND BITS 4-7 ***
    '
    PortB=%11111111 ' ALL BIT PRELOADED TO 1. Known condition.
    '
    TRISC=%00000000 'ALL BITS SET AS OUTPUT ( BITS 0-6: LED SEGMENTS 1-7
    '
    PortC=%11111111 'ALL BITS preloaded as HIGH (LED DISPLAY IS OFF)
    '
    TRISE.4=%0 ' Makes Port D DIGITAL I/O?
    '
    TRISD=%11111111 ' Ground bits 1-7
    '
    PortD.0=%0 ' PORTD.0 preloaded to ZERO (LOW). Known condition
    tYPE = PortD.0 ' Se
    '
    Main:
    while Type <1
    B0=PortB
    gosub lowloop
    wend
    '
    'while type = 1
    'gosub Highloop
    'wend
    goto main ' This should cause constant reading/input from PORTB
    '
    '************************************************* *************************
    '
    LowLoop:

    ' B0 = B1 ' Pass the PORTB data
    Gosub bin2seg ' Convert to segment value
    Poke PortC, B0 ' Put segment values out to LED
    Pauseus 1 ' Display it for 1 microsecond
    Poke PortC,$1E ' Turns off display
    pauseus 1 ' Display is OFF for 1 microsecond
    return ' RETURNS to MAIN; gets next PORTB data

    ' ************************************************** *****
    ' ************* 2nd level soubroutines follow ******************
    ' Convert binary number in B0 to segments for LED
    bin2seg: Lookup B0,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18,$88,$83,$C 6,$A1,$86,$8E],B0
    Return
    END
    ' CLEAN COMPILE 145 WORDS USED 10/04/2008 06:00:00 PM CDT
    '
    ' * note to self: this worked until you added the PORTD code, the wend while
    ' argument.
    '
    ' *!*! This don't work correctly




    Where did I go wrong?
    I know that a few will say RTFM, Ha Ihave and my wife says if I stay up late one more night
    that I can sleep with the dogs. I DO NOT HAVE A DOG.
    OK first a question, define not working properly?
    now what I see:
    Set port latches before the tris registers ' thanks Bruce.
    adcon1 = 6 " or %000000110 ' seven will work but 6 is proper here data sheet says 0000011x
    Clear works but so does calling your wife "hey You" better way is myVar = 0 MyVar2 = 0 . .
    Check your lookup table, looks like you are reading a variable and then trying to store the lookup result in the same var, better lookup B0[ data . . .] B1 b0 = b1
    Oh BTW re:RTFM
    read it to the children at bedtime, they will go to sleep fast!
    Last edited by Archangel; - 5th October 2008 at 01:45.
    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
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Then break it back down to PortD only...and build 'er back up...
    Just do a 'blinky' on all pins on PortD...
    Code:
    DEFINE OSC 4
    @ DEVICE pic16f877a, CPD_OFF
    @ DEVICE pic16f877a, PROTECT_OFF
    @ DEVICE pic16f877a, WRT_OFF
    CLEAR : ADCON1=7 : INTCON=0 : B0 var byte : trisd = 0
    main: b0 = b0 + 1 : portd = b0 : goto main
    You should see each Port D pin flashing at exactly half the frequency of the pin before it. If it's flashing too fast, throw a bit of a pause in the main loop. At least that'll take any questions about PortD out the window...

  4. #4
    Join Date
    Nov 2007
    Location
    Lake Villa Il.
    Posts
    40


    Did you find this post helpful? Yes | No

    Default

    Hello Joe,
    I did try your suggestion and it still will not work.
    Please see the following code IT DOES WORK
    My 'kids are off raising thier own. My Wife's (I call her 'Da BOSS, BOSS) eyes glossed over in about 2 minutes, she says huh?
    I do thank you for your thoughts and suggestions.

    Terry, K9HA

    '************************************************* ***************
    '
    ' * * * System Defines * * *
    '
    '
    @ DEVICE pic16f877a, CPD_OFF

    @ DEVICE pic16f877a, PROTECT_OFF
    @ DEVICE pic16f877a, WRT_OFF
    DEFINE OSC 4
    'DEVICE pic16f877a,
    'ADCON1=7 ' sETS pORTS AS ALL DIGITAL( I HOPE)
    '????????????????????????????????????????????????? ????????????
    '
    INTCON=0 'I Think this turns off ALL INTERUPTS FOR PORTB????
    '
    '????????????????????????????????????????????????? ?????????????

    '
    '************************************************* ***************
    '
    ' Variable Descritptions:
    '
    ' NAME # bits location I/O Description
    ' Type 1 PortD0 IN LOW for TRUE
    ' HIGH for COMPLEMENTARY
    ' PortC.7 1 Program BIT VAR BIT
    '
    '************************************************* ***************
    '
    ' * * * VARIABLE DECLARATIONS * * *
    '
    B0 var byte 'Used in subroutine to generate LED Segment data
    B1 var byte 'Used in subroutine to generate LED Segment data
    'Type var BIT 'PortD.0
    'tYPE = PortD.0

    '
    '************************************************* ***************
    ' DEVICE SET-UP
    '




    CLEAR ' Is this the proper place to put this?

    '
    PortB=%11111111 ' ALL BIT PRELOADED TO 1. Known condition.
    '
    TRISB=%11111111 ' ALL 8 BITS SET AS INPUT: HOEVER ONLY LOWER 4 REALLY USED.
    ' ' *** GROUND BITS 4-7 ***
    PortC=%11111111 'ALL BITS preloaded as HIGH (LED DISPLAY IS OFF), BIT 7 as HIGH
    '
    TRISC=%00000000 'ALL BITS SET AS OUTPUT ( BITS 0-6: LED SEGMENTS 1-7
    TRISE.4=0 'tURNS OFF PARALLEL/SLAVE PORT FUNCTION FOR PORT D

    loop:
    B0=PORTB

    'For B1 = 0 To 15 ' Count from 0 to 15 "F"
    'B0 = B1 ' Pass the count to the conversion subroutine
    Gosub bin2seg ' Convert to segment value
    Poke PortC, B0 ' Put segment values out to LED
    PauseUS 1 ' Display it for 1 second
    Poke PortC, $FF ' Turn off PortC
    PAUSEUS 1
    'Next B1 ' Do next
    Goto loop ' Do it forever

    ' Convert binary number in B0 to segments for LED
    bin2seg: Lookup B0,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18,$88,$83,$C 6,$A1,$86,$8E],B0
    Return
    END
    ' CLEAN COMPILE 121 WORDS USED 10/04/2008 09:15:00 PM
    '
    ' Yippie, IT WORKS!!




    THIS does read a BCD switch

  5. #5
    Join Date
    Nov 2007
    Location
    Lake Villa Il.
    Posts
    40


    Did you find this post helpful? Yes | No

    Default

    Skimask,
    The desired end result is to use 4 bits on Port B as input, Port C as output to drive the display, and 1 bit on Port D as input to tell the difference between True and Complimentary encoded switches, rotary encoders.

    TNX,
    Terry

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Ok, I smell what your cooking now...
    One, ok, two suggestions.
    Don't need to use Poke. Just use PortC = $FF or whatever instead to assign a value to a port.
    Also, when running at 4Mhz, the minimum pauseus possible is 24us as stated in the PBP manual, so anything less than 24 will get you 24 anyways. If you actually want a 1us pause, you might try a @ NOP instead.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Terry,
    If you are only using 4 port b pins as inputs I would make the rest outputs and set low and use pulldowns just to avoid that port being made available to stray signals.IMHO I did an BCD with lookup a while back using a 12f675.
    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.

  8. #8
    Join Date
    Nov 2007
    Location
    Chicago
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Maybe nothing

    Sneaky,
    Maybe it's nothing, but I see a space between the $c and 6 in the code below. Seems like this would cause a compile error but I haven't tried it.

    ' Convert binary number in B0 to segments for LED
    bin2seg: Lookup B0,[$40,$79,$24,$30,$19,$12,$02,$78,$00,$18,$88,$83,$C 6,$A1,$86,$8E],B0
    Return
    END

Similar Threads

  1. PIC16F877A - Timer0 won't interrupt
    By WishMaster^ in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 25th April 2007, 08:25
  2. Crystalfontz LCD
    By jman12 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 9th February 2007, 15:04
  3. Bit variables... typo?
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th November 2004, 18:11

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