pins in arrays?


Closed Thread
Results 1 to 17 of 17

Thread: pins in arrays?

Hybrid View

  1. #1
    scorpion's Avatar
    scorpion Guest

    Default pins in arrays?

    can i do something like this?
    ok a better question:
    how can i do something like this

    outpin[0] var porta.0
    outpin[1] var porta.1
    outpin[2] var porta.2

    for i = 0 to 2
    high outpin[i]
    pause 500
    next i

    for i = 0 to 2
    low outpin[i]
    pause 500
    next i

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


    Did you find this post helpful? Yes | No

    Default

    For the ONLY reliable answer, see your PBP manual section 4.11 Pins.

    There are other solutions, but their behaviour is not consistant across different PIC types - so best not go there for now.

    Here's a reprint of a posting from April 2003 (on the email forum) giving a code example of pin addressing...

    Melanie's Bouncing Ball
    ===================

    Example of what we've been talking about... No - I've not had a
    sex-change! Everyone does Cylons or Knight Rider as an example
    (boring - that's for kid's)... we'll be different (adult, grown-up,
    X-rated version)... there I was all dressed up in my tight leather
    catwoman outfit with chromed spikes, playing with someone's ball (*see
    note at end) the other day and watching it bounce...

    ' MelsBall.bas
    ' Melanie's Bouncing Ball
    ' ----------------
    ' No wise cracks!

    ' 8 LED's on PORTB, connected Anode to PIC
    ' all Cathodes commoned and via a single
    ' 270R Resistor to Vss. since no two LED's
    ' will be on at a time, we can be economical
    ' with the Resistors... they're expensive...

    '
    ' PIC Defines
    ' -----------
    @ DEVICE pic16F628, INTRC_OSC_NOCLKOUT
    ' System Clock Options
    @ DEVICE pic16F628, WDT_ON
    ' Watchdog Timer
    @ DEVICE pic16F628, PWRT_ON
    ' Power-On Timer
    @ DEVICE pic16F628, MCLR_OFF
    ' Master Clear Options (Internal)
    @ DEVICE pic16F628, BOD_ON
    ' Brown-Out Detect
    @ DEVICE pic16F628, LVP_OFF
    ' Low-Voltage Programming
    @ DEVICE pic16F628, CPD_OFF
    ' Data Memory Code Protect
    @ DEVICE pic16F628, PROTECT_OFF
    ' Program Code Protection

    '
    ' Software Defines
    ' ----------------
    PortBPin var byte
    DecayBounce var byte
    GravityDelay var word

    '
    ' Initialise Hardware
    ' -------------------
    CMCON=%00000111
    TRISA=%00000000
    TRISB=$00000000
    PORTB=0 ' All LED's OFF
    ' Ground Level = PORTB.0
    ' Highest Bounce point = PORTB.7

    '
    ' Main Program Loop
    ' -----------------
    DoAgain:
    '
    ' Drop Ball
    ' ---------
    DecayBounce=7
    DecayLoop:
    GravityDelay=256
    For PortBPin=DecayBounce to 0 step -1
    High PortBPin
    Gosub Accelerate
    Low PortBPin
    Next PortBPin
    '
    ' Rebound
    ' -------
    DecayBounce=DecayBounce-1
    For PortBPin=0 to DecayBounce
    High PortBPin
    Gosub Decelerate
    Low PortBPin
    Next PortBPin
    '
    ' New Apex
    ' --------
    If DecayBounce=0 then
    High 0
    Pause 1500
    Low 0
    Pause 1500
    Goto DoAgain
    endif
    Goto DecayLoop

    '
    ' Subroutine Accelerates Ball
    ' ---------------------------
    Accelerate:
    GravityDelay=GravityDelay/2
    Pause GravityDelay
    Return

    '
    ' Subroutine Decelerates Ball
    ' ---------------------------
    Decelerate:
    GravityDelay=GravityDelay*2
    Pause GravityDelay
    Return

    end

    Die-hard's will tell me it's not the formula for gravitational
    acceleration - I don't care... it looks good and what do you expect
    for a five-minute bit of code and eight LED's. If you got time to
    burn, tweak your own formula's...

    * Note - Tennis Ball *smiles*

    Melanie

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


    Did you find this post helpful? Yes | No

    Default

    the best way to learn is to try... what can happen in the worst case, compilation error. NOT MUCH. Then once you try everything, you have read the whole PBP manual and all the thread related to your problem/question on this forum AND you bang your head more than hundreds times and your face is full of blood, you'd cry for few hours and get divorced, now you can ask some question


    No it's a bit too much but this question is asked maybe once a month or so. You'll definetely win to look into your PBP manual as Melanie suggested.

    **update** great previous post edit Melanie
    Last edited by mister_e; - 29th March 2005 at 18:48.
    Steve

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

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Melanie,

    I was bored tonight, so i thought i'd play with your Ball.

    Press Play.

    <embed SRC="http://www.darreltaylor.com/files/MelaniesBall.wmv" AUTOSTART="false">
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Hey, I notice you had two! Must be a typical male thing... (not that I know - I'm just an innocent kinda gal)... you get bored and what's the first thing you play with?

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie
    (not that I know - I'm just an innocent kinda gal)...
    Yeah! right. With the "...tight leather catwoman outfit with chromed spikes...".

    Quite innocent I say...!

    Ioannis

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  3. PIC - 8 Pins - 6 Output Pins ?
    By DanPBP in forum Off Topic
    Replies: 0
    Last Post: - 22nd October 2007, 00:23
  4. I2C Effects on other PortA pins
    By kenmac in forum General
    Replies: 2
    Last Post: - 11th July 2005, 05:36
  5. PIC PORT 'special' pins
    By barkerben in forum General
    Replies: 1
    Last Post: - 18th January 2005, 21:40

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