Losing data when extracting bytes from words - 16F18855


Results 1 to 26 of 26

Threaded View

  1. #10
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: Losing data when extracting bytes from words - 16F18855

    Quote Originally Posted by richard View Post
    ...a packetised binary structure is way more efficient esp if its fixed length ...
    I've been working with your module for 2 days and encountered a slight complication. I love the routine, but it seems the module is still working in the background when the next code instructions execute. For example:

    I can refer to ADCcode in the RX pgm right away after strcpy cause it's the first byte in my structure:

    Code:
    asm
    ADCcode    = _MsgData
    ADCnum     = _MsgData + 1
    ADCerror1  = _MsgData + 3
    ADCerror2  = _MsgData + 4
    endasm
    
    
    ...
    
    
    Mainloop:
    
        while RXoccurred = 0                            ' Wait for message
        wend
    
        strcpy  MsgData , incoming ,5
    
        if ADCcode = 0 then
            gosub ProcessADC_A0
        else
            if  ADCcode = 1 then
                gosub ProcessADC_A1
            else
                if  ADCcode = 3 then
                    gosub ProcessSW3
                else
                    if  ADCcode = 4 then
                        gosub ProcessADC_A4
                    else
                        if  ADCcode = 5 then
                            gosub ProcessADC_C3
                        else
                            if  ADCcode = 6 then
                                gosub ProcessADC_C4
                            endif
                        endif
                    endif
                endif
            endif
        endif
    
      GOTO Mainloop
    This code works as expected.


    But if I refer to ADCerror1 or ADCerror2 in the TX pgm immediately after strcpy, they don't get seen by the program. I have to add a PAUSE 1 for the IFs to get triggered:

    Code:
        hserout [   str MsgData\5   ]                 ' transmit ADC value            
    
        while TX1STA.1 = 0                              ' Check TRMT bit
        wend
    
        while RXoccurred = 0                            ' Wait for confirmation message (RX int)
        wend
    
        strcpy  MsgData , incoming ,5
        
        PAUSE 1
                                                    
        if ADCerror1 = 1 then                           ' Check return code 1
             Errorcodes = Errorcodes | %01000000            ' Force PORTA bit 6 to 1
        else
            if ADCerror2 = 1 then                       ' Check return code 2
                Errorcodes = Errorcodes | %10000000         ' Force PORTA bit 7 to 1
            else
                Errorcodes = Errorcodes & %00111111         ' Force PORTA bits 6-7 to 0
            endif
        endif

    Is it complicated to add a Completion Code variable in element 0 (1 byte)?
    0 = processing
    1 = finished


    That way I can substitute the PAUSE by a WHILE WEND like this:

    Code:
    '    PAUSE 1
        while incoming[0] = 0                           ' Wait for string copy to complete
        wend
    I can initialize incoming[0] to 0 before calling strcpy if that helps you.

    I try to avoid using PAUSE so I can use DT Ints without surprises.

    Right now my structure is only 5 bytes long, but this will most likely grow over time.


    PS: Please don't bother with this if it takes more than 2-3 minutes.
    Last edited by Demon; - 18th March 2025 at 06:31.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. Decoding serial data bytes and nibbles.
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th January 2018, 08:22
  2. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  3. ORing / ANDing bytes or words
    By mmargolis in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 19th March 2011, 20:12
  4. Success! Are they 'words' or are they 'bytes'?
    By BitHead in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th December 2009, 16:54
  5. Codespace Saving Tip... Don't mix Words and Bytes
    By Melanie in forum Code Examples
    Replies: 0
    Last Post: - 18th June 2004, 10:23

Members who have read this thread : 14

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