I thought PORTA.0[33] was the same as PORTE.1 ?!?


Closed Thread
Results 1 to 10 of 10
  1. #1
    blainecf's Avatar
    blainecf Guest

    Question I thought PORTA.0[33] was the same as PORTE.1 ?!?

    Any Ideas???


    SERIN2 PORTE.1, 49236, [Commbyte]

    SERIN2 PORTA.0[33], 49236, [Commbyte]

    The first line works perfectly, the second line doesn't work at all.

    I have multiple lines that I'm getting comm signals from, and I need to select them with an index variable. Everywhere else in the program I'm able to use these two concepts interchangeably, except with SERIN2 (and, SEROUT2, I think). I've tried brackets and parenthesis - no help.

    My alternative is to write 8 separate sets of code, one for each I/O line

    Any brilliance would be appropriately lavished.

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

    Default

    Hi blaine,

    Confusing, isn't it?

    With the PORTA.0[33], it's actually doing an array operation.

    It will Read PORTE.1 which is either a 0 or 1, then it will SERIN from either PORTB.0 or PORTB.1, depending on the PORTE.1 value.

    There is a way to do what you're after, but it depends on 1 thing.

    Have you used any "Numbered Ports" anywhere else in your program?

    Numbered Ports would be anything like...

    LOW 1
    HIGH 7
    SERIN2, 15, ...

    P = 6
    LOW P

    etc. etc.
    DT

  3. #3
    blainecf's Avatar
    blainecf Guest

    Unhappy Good or bad, I'm NOT using numbered ports

    I'm really hoping you have a solution. Please enlighten...

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

    Default

    It depends on what pins the serial data is coming in on too, hopefully they are all on only 2 PORTS.

    Here's the idea.

    In your PBP folder, open the .BAS file associated with the chip you are using. You'll see these variables.

    PORTL VAR PORTB
    PORTH VAR PORTC
    TRISL VAR TRISB
    TRISH VAR TRISC


    They are the Starting locations for the Numbered Ports.

    For 0-7 it uses PORTL and TRISL
    for 8-15 it uses PORTH and TRISH

    These can actually be assigned 2 different ports. You could have PORTL on PORTA, and PORTH on PORTE. Then 0-7 would be PORTA, and 8-15 would be PORTE.

    DO NOT just edit the file. Comment out the lines, and declare the PORTs in your main program. This way when you write another program for that chip, the compiler will remind you that the file has been changed.

    After that there are many ways to handle the numbers. But it's something like this.

    PORTH VAR PORTE
    TRISH VAR TRISE

    P = 9 ; PORTE.1
    SERIN2 P, 49236, [Commbyte]

    Last edited by Darrel Taylor; - 19th July 2006 at 22:53. Reason: .
    DT

  5. #5
    blainecf's Avatar
    blainecf Guest

    Default No such luck

    D:

    Thanks for the info, but I'll need another solution for my application. I'm using pins scattered across B, C, D, and E ports. For now I've hard-coded individual SELECT CASE statements for each comm group for both SERIN2 and SEROUT2 commands... yuk!

    Too bad you can't alias individual array elements to user-defined pins. That would be sweet.

    Any other suggestions out there??????????

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

    Default

    Ok, then one more question.

    16F or 18F?

    DT

  7. #7
    blainecf's Avatar
    blainecf Guest

    Default Processor type:

    18F458 - 44pin plcc

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

    Default

    blaine,

    I think this might work for you.

    It uses the same numbers that you were expecting before.
    PORTA.0 = 0
    PORTB.0 = 8
    PORTE.1 = 33

    Code:
    P = 33 : gosub SetSerinPin
    GOSUB SerinP2
    SerinP2 will return 1 byte from the selected PIN. Received data will be in Commbyte.

    Code:
    ;-----------------------------------------------------------------------
    @P_A = PORTA                      ; Find address for PORTA
    P_A       CON EXT
    PinPort   VAR WORD                ; Address of selected Port
    PinBit    VAR Byte                ; Bit Mask of selected port
    
    SetSerinPin:
        PinPort = P_A + (P >> 3)      ; PORTA + P/8 Find selected PORT
        PinBit  = DCD (P & %111)      ; create BIT mask
    return
    
    SerinP2:                          ; Get a BYTE from the specified PORT
       RM1 = PinBit
       RR1 = PinPort.LowByte
       RS1 = PinPort.HighByte
    @  SERIN2MODE?C   49236
    @  SERIN2?B       _Commbyte
    RETURN
    
    @  ifdef doesnotcompile    ; Force PBP to include SERIN2 library
          SERIN2 1, 1, [Commbyte]
    @  endif
    ;-----------------------------------------------------------------------
    DT

  9. #9
    blainecf's Avatar
    blainecf Guest

    Thumbs up Nice!

    I'll have to study this, and will probably try it tonight or tomorrow; but, initially it looks exactly like what I'm looking for.

    Elegant, clean, versatile, sweet!

    Thanks D.

    bcf

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

    Default

    I don't know about elegant, but versatile, yup. Hope you can use it.

    Let me know if you need the Serout side of it too.

    DT

Similar Threads

  1. More space than I thought !!!
    By keithdoxey in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th August 2006, 21:04
  2. 16F88 is not the dream device I thought it was.
    By keithdoxey in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 25th October 2005, 22:19
  3. What is the Pin Number for PortE.1? on 18F458
    By khufumen in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 2nd June 2005, 17:13

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