Index a bit through a portion of a port


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Index a bit through a portion of a port

    Ran out of time before I could get ALL of the code submitted......

    OK, why won't this work????

    Code:
    start1:            
            if packetRcvd=1 then                                  'Packet has arrived!                
                   pkt_cntr = pkt_cntr+1                         'Increase the counter so we can turn on new LED                
                   lookup pkt_cntr, [0,6, 5, 4, 3],j             'Lookup (better) for the offsets from A.0                
                   toggle PORTA.0[j]                                'Should toggle the required port ON as all started OFF
            endif        
            if pkt_cntr=4 then pkt_cntr=0                     'We have run through all 4 LEDs so reset counter        
            PacketRcvd=0                                            'Done processing packet data so reset flag        
            goto start1
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

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


    Did you find this post helpful? Yes | No

    Default Re: Index a bit through a portion of a port

    Your toggle command is not doing what you think it is.

    Code:
    toggle PORTA.0[j]
    That will read the PIN specified by the [j] offset from PORTA.0.
    Then toggle the resulting PIN, either 0 or 1. (0 = PORTB.0, 1 = PORTB.1)

    You could use this instead ...
    Code:
    PORTA.0(j) = !PORTA.0(j)
    But you'll need to set the TRIS/PORT bits to OUTPUT/LOW first.
    DT

  3. #3
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Index a bit through a portion of a port

    Wow, so simple. This is MUCH better than what I started with. However, the LEDs do come on one at a time until they are all on. Then they go off one at a time untill all are off.I understand what you said and are doing by using the logical NOT.Is there a way to turn on only onle LED at a time? eg, 1st packet = LED1 on and all others are off, 2nd packet in=LED2 on and all others off, 3rd packet=LED3 on all others off, 4th packet =LED4 on and all others off, 5th packet=LED1 on all others off, etc??BTW, solved my CRC16 issue - it now works!Thanks again Darrel.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

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


    Did you find this post helpful? Yes | No

    Default Re: Index a bit through a portion of a port

    Code:
    LED1 = !!(packetRcvd=1)
    LED2 = !!(packetRcvd=2)
    LED3 = !!(packetRcvd=3)
    LED4 = !!(packetRcvd=4)
    DT

  5. #5
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Index a bit through a portion of a port

    It added it but ALL the LEDs came on. What I added was (can't seem to master the code posting.....) I added LED1=!!(pkt_cntr=1) and so on.
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

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


    Did you find this post helpful? Yes | No

    Default Re: Index a bit through a portion of a port

    Quote Originally Posted by ecoli-557 View Post
    It added it but ALL the LEDs came on.
    Do your LED's go to ground or VDD?

    If they go to VDD, only use 1 "!"
    Code:
    LED1 = !(pkt_cntr=1)
    LED2 = !(pkt_cntr=2)
    LED3 = !(pkt_cntr=3)
    LED4 = !(pkt_cntr=4)
    DT

  7. #7
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: Index a bit through a portion of a port

    Thanks, They are pulled up to +5v via 1K. I just tried the single '!' and none light.The base address and offset I understood, the suggestion LED1 = !(pkt_cntr=1) and so on I do not understand. Care to enlighten?
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

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