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

    Hey Again-
    With this thread : http://www.picbasic.co.uk/forum/showthread.php?t=14038 I have tried the following, but it does NOT compile. The errors are too many but the 1st couple are:
    Syntax error, redefinition of label pLED, syntax error. So I think it may be a dumb thing on my part....

    Pertinant code below:
    '-----------------------------------------------------------------------------------------
    'Additional I/O Definitions
    error var PORTG.3 'ERROR output, ACTIVE LOW (LED)
    heart var PORTG.0 'Heartbeat to know we are online - ACTIVE LOW
    CTS Var PORTG.4 'Goes high to xmit on RS485
    pLED[1] VAR PORTA.3 'Network activity LED1
    pLED[2] VAR PORTA.4 'Network activity LED2
    pLED[3] VAR PORTA.5 'Network activity LED3
    pLED[4] VAR PORTA.6 'Network activity LED4
    AC var PORTA.2 '110 VAC present or not - low if present
    '------------------------------------------------------------------------------------------
    'Variable List
    i var byte 'Loop counter var
    j var byte 'Loop counter var
    rxbyte var byte 'serial receive byte
    sync var byte 'data byte 1 - $54
    chksum var word '16 bit checksum
    bad_data var bit 'Bad data indicator
    adval5 var word 'A2D conversion result 5v
    adval24 var word 'A2D conversion result 24v
    pkt_cntr var byte 'Variable to rotate the 4 LES indicating received packets
    CRC16 var word 'CRC16 holder

    Actual code:
    start1:
    ' DEBUG "5 volt= ",DEC adval5 DIG 3,".",DEC3 adval5, 10, 13
    if packetRcvd=1 then 'Packet has arrived!
    pkt_cntr = pkt_cntr+1 'Increase the counter so we can turn on new LED
    toggle pLED[pkt_cntr] 'Turns on new packet LED
    ' debug HDB2, HDB1, source_h, source_l, dest_h, dest_l, datab1, crc_high, crc_low, 10, 13
    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

    Again, this is to test the theory but it does not work.
    Any help??

    Regards
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

  2. #2
    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

    Sorry about the last post - it had errors.....

    WHY won't this work? The array IS contigous, isn't it?

    pLED var bit[4]

    SYMBOL pLED[1]=PORTA.3 'Network activity LED1
    SYMBOL pLED[2]=PORTA.4 'Network activity LED2
    SYMBOL pLED[3]=PORTA.5 'Network activity LED3
    SYMBOL pLED[4]=PORTA.6 'Network activity LED4

    Then:
    start1:
    if packetRcvd=1 then 'Packet has arrived!
    pkt_cntr = pkt_cntr+1 'Increase the counter so we can turn on new LED
    toggle pLED[pkt_cntr] 'Turns on new packet LED
    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

  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

    This has been fun, I found a who;e new set of threads!
    According to this http://www.picbasic.co.uk/forum/show...t=4074&p=22065 what I have below should work, but no LEDs come on...... Any help??

    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, [6, 5, 4, 3],j 'Lookup (better) for the offsets from A.0
    toggle PORTA.0[j] 'Should toggle the required port
    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

  4. #4
    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

    I found out how to post code in a more readable manner so I have posted again.But, why won't this work? Can't you toggle a port pin addressed this way??
    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

  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

    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

  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

    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

  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

    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

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