Indexing port pins for serout2/serin2


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flyingasics View Post

    Relay[1] = 14 'RB6
    Relay[2] = 20 'RC4
    Relay[3] = 26 'RD2
    main:
    ' cycle through relays
    for i = 1 to 3
    x = relay[i]
    serout2 porta.0[x], 8276, ["hello"]

    Thanks!
    Something I can't understand ...

    Porta.0[14,20 or 26] ???

    Also note relay[] can be a bit array...

    May be some " select case " will do a better job here ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Something I can't understand ...

    Porta.0[14,20 or 26] ???

    Also note relay[] can be a bit array...

    May be some " select case " will do a better job here ...

    Alain
    Porta.0[14,20 or 26] is supposed to be an undeclared array and since the PORTS are located sequentially in memory PicBasic Pro takes the value in brackets and treats it as an offset from porta.0 so

    porta.0[1] is porta.1
    porta.0[8] is portb.0

    The problem with using loops and select case is that my code will start to get really long and nasty looking.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Can someone explain why this will not work with the serout/serin functions? I had given up doing it this way and writing the program using cases for each pair of ports that I want to talk to, but it is looking like i am going to run out of flash memory on the PIC doing it this way.


    Relay var Byte[4]
    x var byte
    i var byte

    Relay[1] = 14 'RB6
    Relay[2] = 20 'RC4
    Relay[3] = 26 'RD2
    main:
    ' cycle through relays
    for i = 1 to 3
    x = relay[i]
    serout2 porta.0[x], 8276, ["hello"]
    PAUSE 300
    next i

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flyingasics View Post
    Can someone explain why this will not work with the serout/serin functions?
    serout2 porta.0[x], 8276, ["hello"]
    porta.0[x] is an Array function.
    When used with HIGH LOW SEROUT or any command other than a math formula, it reads the indicated array element (a pin) and returns the value to be used in the command.

    Since it's a BIT Array, it will only return a 0 or 1 depending on the state of the indexed PIN.
    Therefore, the serout2 command will only output on PORTB.0 or PORTB.1

    To reiterate my previous recommendation ...
    If you moved your serial outputs so they are all on two PORTs, instead of scattered across 3 or four ports ... you can do exactly what you want by using pin "Numbers", and a very small bit of code.
    DT

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Ok, so am I just out of luck using some kind of loop to reduce code and make it easier to modify the in the future if I want to use ports ABCDE? Not because I have them spread out but I just have that many serial devices I want to talk to. What is the reason why there are only 2 ports at a time that you can reference with a pin "number".

    Can I change PORTL and PORTH during runtime to other ports?

    Thanks.

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