pins in arrays?


Closed Thread
Results 1 to 17 of 17

Thread: pins in arrays?

  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,110


    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

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


    Did you find this post helpful? Yes | No

    Default

    LMAO... Melanie, that leather kit will stick to you 'till you'll die

    Chance are that you're still young and fit... 'till you get married, have children, become fat, then divorce, lose weight to make it fit again!!

    Probably you have some regret now to talk about that kit... many months/years ago... naaah i don't think so!

    Just kidding!
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    > Chance are that you're still young and fit

    You would dare question that? Sounds like you need a visit from Miss Whiplash!

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


    Did you find this post helpful? Yes | No

    Wink Now you talk!!!

    <img src=http://www.picbasic.co.uk/forum/attachment.php?attachmentid=445&stc=1>
    Attached Images Attached Images  
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    hmmmm... she's having a bad hairday... I could comment but this isn't an adult rated forum... *laughs*

  11. #11
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,110


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie
    hmmmm... she's having a bad hairday... I could comment but this isn't an adult rated forum... *laughs*
    Mmm, well pointed comment! I have a nice PIC driven hair tool for her (or anyone else too...!). With some 10KV of voltage and an thermal stabilized roller, that hair would look better, I think.

    Ioannis

  12. #12
    obaskirt's Avatar
    obaskirt Guest


    Did you find this post helpful? Yes | No

    Question

    For PIC16F877. I have to use "ADCON1=7" instead of "CMCON=%00000111". Is it correct?

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


    Did you find this post helpful? Yes | No

    Default

    YES, unless you have a PIC16F877A. In which case, you would need both of them.

    Not quite sure how that fits in with this topic though.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    I was about to say that - you've beaten me to it - but I assume obaskirt's referring to the original example code at the top of this thread which was for a PIC16F628...

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


    Did you find this post helpful? Yes | No

    Default

    Yup, I guess that would fit.

    I was still thinking about your balls. Got me all flustered.
    <br>
    DT

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


    Did you find this post helpful? Yes | No

    Default

    be carefull of your wording
    Steve

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

  17. #17
    obaskirt's Avatar
    obaskirt Guest


    Did you find this post helpful? Yes | No

    Wink

    I connected 4 buttons to PORTA's first four pin and also I connected 8 leds to PORTB and a buzzer PORTD 2. pin. You know that PIC16F877's PORTA comes in a analog mode so I used ADCON1=7 and I turned them to digital mode. (If you use PORTA and you do not use ADCON1=7, the code won't work. I tried and I saw that.)

    Then, I used this code and it worked, Thanks everybody...


    Code:
    MY CODE:
    
    '---> PORT DECLARATIONS
    TRISB = %00000000   ' Make Port B's all pins output
    OUTPUT PORTD.2       ' Make Port D's 2. pin output   
    TRISA = %00001111   ' Make Port A's 0-4 pins input
    PORTB = 0                ' Make Port B's all pins 0 Volt
    PORTD.2 = 0             ' Make Port D's 2. pin 0 Volt  
    
    '---> MAIN CODE
    counter VAR BYTE  ' Counter for different sounds.
    PortBPin VAR BYTE ' This is for turning on leds sequential order.
    
    'Any PICmicro MCU with analog inputs, such as the PIC16C7xx,
    'PIC16F87x and PIC12C67x series devices, will come up in analog mode.
    'You must set them to digital if that is how you intend to use them:
    ADCON1 = 7 
    
    loop:   'Our main loop
    
    ' For Button T0
    IF PORTA.0 = 0 THEN  ' If button T0 is pressed then generate different sounds. Counter increment rate is 10.
       FOR counter=10 to 130 STEP 10
          SOUND PORTD.2, [counter,10,60,10]  ' Generate Sound
       NEXT counter
    ENDIF
    
    ' For Button T1
    IF PORTA.1 = 0 THEN  ' If button T1 is pressed then turn on leds 0 to 7
       PORTD.2 = 0           ' Make Port D's 2. pin 0 Volt  
       FOR PortBPin=0 to 7 STEP 1
          HIGH PortBPin
          PAUSE 200
          LOW PortBPin
       NEXT PortBPin
    ENDIF
    
    ' For Button T2
    IF PORTA.2 = 0 THEN  ' If button T1 is pressed then turn on leds 7 to 0
       PORTD.2 = 0         ' Make Port D's 2. pin 0 Volt  
       FOR PortBPin=7 to 0 STEP -1
          HIGH PortBPin
          PAUSE 200
          LOW PortBPin
       NEXT PortBPin
    ENDIF
    
    ' For Button T3
    IF PORTA.3 = 0 THEN      ' If button T3 is pressed then turn on leds inside to outside then outside to inside.
       PORTD.2 = 0           ' Make Port D's 2. pin 0 Volt  (Buzzer'ı kapatır.)
       PORTB = %00011000     ' Port B's middle 4. and 5. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %00100100     ' Port B's middle 3. and 6. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %01000010     ' Port B's middle 2. and 7. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %10000001     ' Port B's middle 1. and 8. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %01000010     ' Port B's middle 2. and 7. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %00100100     ' Port B's middle 3. and 6. pins are turns on.
       PAUSE 300             ' Wait 300 ms
       PORTB = %00011000     ' Port B's middle 4. and 5. pins are turns on.
       PAUSE 300             ' Wait 300 ms
    ENDIF
    
    GOTO loop  ' Do it forever
    END ' End of our program.
    Last edited by Darrel Taylor; - 17th September 2005 at 21:04. Reason: added [code][/code] tags

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