SerOut2 Dynamic Port Selection


Closed Thread
Results 1 to 11 of 11
  1. #1
    nba30's Avatar
    nba30 Guest

    Question SerOut2 Dynamic Port Selection

    I am connecting 15 serial devices to a 40 pin PIC (18F452) and I was wondering if there was a way to have a variable number: 1-15 select which port the serial data is sent to?

    For example:
    -------------------
    SELECT CASE address

    CASE 1
    port var portd.0
    CASE 2
    port var portd.1
    CASE 3
    port var portd.2
    CASE ELSE
    goto error
    END SELECT

    SerOut2 port,baud,["output string",10,13]

    -------------------
    Where "address" is a variable byte that stores a decimal number.

    This example will not compile since you are not allowed to declare an alias more than once.

    I also tried a LOOKUP statement but I cannot store the port addresses (or alias) into variable bytes or words. I also thought about using the address variable and the Pin numbers but since I am dealing with a larger PIC, I cannot access all of this pins with this command.

    Any ideas on how to do this without making a routine for each port that I need to read/write to?

    THANKS!
    Last edited by nba30; - 23rd March 2005 at 02:32.

  2. #2
    anj's Avatar
    anj Guest


    Did you find this post helpful? Yes | No

    Default

    Look at the thread "Can you make name variables" a few days ago
    https://www.picbasic.co.uk/forum/showthread.php?t=1419
    ie
    Code:
    port var porta.0
    ....
    case  X = 1  
            X = 2
            ...
    
    SerOut2 port[X],baud,["output string",10,13]
    I know this port referencing method doesnt always work with all commands, but its worth a try

    Andrew

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


    Did you find this post helpful? Yes | No

    Default

    i agree with the previous can work in some case BUT can you modify or use the PBPs defaults pin number.... see section 4.11 of your PBP manual.
    Steve

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

  4. #4
    nba30's Avatar
    nba30 Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks for the ideas guys. I will give them a shot tomorrow.

    I re-read the section in the manual about pin numbers and according to the table, I can only address PortB (0-7) and PortC (8-15). While that does give me 16 pins to work with, I really need to use the interupt pins RB.0-2.

    We'll see how it goes...

    Thanks again

  5. #5
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    You can address each pin on the pic by offsetting from Porta.0, the syntax is PortA.0(index). Index 0-7 accesses PortA0-7, index 8-15 accesses PortB0-7, index 16-23 accesses PortC0-7 and so on.
    Code:
    '      address   0  1  2  3  4  5  6 .....  
    '               a0 a1 a5 b0 b1 b5 b7 .....
    Lookup address,[00,01,05,08,09,13,15 .....],SerPin
    SerOut2 PortA.0(SerPin),baud,["output string",10,13]

  6. #6
    nba30's Avatar
    nba30 Guest


    Did you find this post helpful? Yes | No

    Default

    It seems like the Lookup function along with PORTA.0(serpin) should work, but the only thing it does is output on pins RB0 and RB1.

    Even if I write a simple program to turn on/off the pins, it still keeps addressing pins RB0 and RB1 only.

    Am I missing something?

    Thanks.

    <div class="smallfont" style="margin-bottom:2px">Code:</div>
    <pre class="alt2" style="margin:0px; padding:6px; border:1px inset; width:640px; height:98px; overflow:auto"><div dir="ltr" style="text-align:left;">
    B0 VAR BYTE
    serpin VAR BYTE

    loop:
    For b0 = 0 TO 7
    LookUp b0,[0,1,2,3,4,8,16,24],serpin
    High PORTA.0(serpin)
    Pause 500
    Next b0
    GoTo loop
    <div>

  7. #7
    passstill's Avatar
    passstill Guest


    Did you find this post helpful? Yes | No

    Default

    Hi,

    I tried to use the code above but it dosen't work, I'm using PBP 2.45,
    does anyone could give me any tips about it?


    Ciao
    Alan

    Joka kuritta kasvaa se kunniatta kuole


    Quote Originally Posted by Ingvar
    You can address each pin on the pic by offsetting from Porta.0, the syntax is PortA.0(index). Index 0-7 accesses PortA0-7, index 8-15 accesses PortB0-7, index 16-23 accesses PortC0-7 and so on.
    Code:
    '      address   0  1  2  3  4  5  6 .....  
    '               a0 a1 a5 b0 b1 b5 b7 .....
    Lookup address,[00,01,05,08,09,13,15 .....],SerPin
    SerOut2 PortA.0(SerPin),baud,["output string",10,13]

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


    Did you find this post helpful? Yes | No

    Default

    Careful Ingvar...

    It only works on a very few PICs in a very few cases...

    It does NOT work across all PICs and neither does it work against variants of the same PIC or versions of PICBasic.

    I actually withdrew a posting I made about a year ago detailing the very same thing when I discovered that in all probability the chances of it NOT working are greater than the chances of success.

    The only guaranteed things to work are the sixteen pins (0-15) as detailed in the manual, and then they are PIC type dependant (as per the table in the manual).

  9. #9
    anj's Avatar
    anj Guest


    Did you find this post helpful? Yes | No

    Default

    Gday Mel
    I have been watching this post with interest.
    I know the array id method listed works for 16F876s 16F84s and 16F88s,
    but looking at the datasheets Ports A,B and C are all contiguous in memory
    ie x05, x06 etc.
    on 12/3 this year PeterDeco posted re a similar problem, and whilst misinterpreting the post, tried portA.0 + X rather than portA.0(X), and said this also worked.
    Based on the fact "PortA" just gets referenced to its memory locn via the include files, say x05 in a 16f88, is it possible ( knowing the memory map for the specific pic/variant ), to use a calculated reference point, rather than assume the bits are contiguous and ref by array practices.
    Basically, what i am saying is do the functions that "expect a port" reference need it to come in as a standard symbol, or would the correct memory offset ( as a variable ) suffice.
    I cant test, as i dont know how to make it fail currently ( under the old method ) with the chips i normally play with.
    Andrew

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


    Did you find this post helpful? Yes | No

    Default

    I spent quite a while (at least for me) on this last year.

    I concluded that if it can't work across all PICs and all versions of PICBasic consistantly everytime, it shouldn't be used.

    The only ways I address PIC pins is by aliasing the pin or by using the direct numeric (0-15).

    The offset addressing method works for RAM and I've detailed this in the FAQ section, but I cannot reliably apply the same to Port Addressing. I have not redone my tests on V2.45 which had not been released at that time.

  11. #11
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Bummer, i 've only used it once on ports and it worked just as expected. Good to know that it might not the next time .......

Similar Threads

  1. Serout and 18F87J50
    By Glenn_Webber in forum Serial
    Replies: 8
    Last Post: - 20th November 2009, 14:26
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. SLOW Serin2 and Serout2
    By dragons_fire in forum General
    Replies: 3
    Last Post: - 26th June 2009, 02:38
  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. STATUS re-curtain W
    By zugvogel1 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th February 2005, 15:21

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