2 bytes to word array variable - fastest way


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Jun 2010
    Location
    Venezuela
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: 2 bytes to word array variable - fastest way

    hello, i use this and work:

    read I,b1.HIGHBYTE ' read byte type var from EEprom
    read I+1,b1.LOWBYTE 'read byte type var from EEprom
    TEmpDs18(L) = B1 'word array

  2. #2
    Join Date
    Feb 2011
    Location
    Michigan, USA
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: 2 bytes to word array variable - fastest way

    Well it turns out the more intuitive way is also a little faster. That is if I
    have done this correctly.

    I used [view] [program memory] in MPLab and counted the number of
    instructions between the start and end labels.

    This code was 18 lines:
    Code:
     
    StartTest:
      adcData.lowbyte[Index] = ADRESL
      adcData.lowbyte[Index+1] = ADRESH
    EndTest:
    This code was 16 lines:
    Code:
     
    StartTest:
      tempWord.highbyte = ADRESH
      tempWord.lowbyte = ADRESL
      adcdata[index] = tempword
    EndTest:
    So as long as I can afford the extra word variable, I will be using the
    temp variable way...... unless someone else reveals a clever trick.

    thanks all for your replies,
    Mike -

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


    Did you find this post helpful? Yes | No

    Default Re: 2 bytes to word array variable - fastest way

    If ADRESH & ADRESL are consecutive SFR... then you could use

    Code:
        @ADRESULT = ADRESL
        ADRESULT VAR WORD EXT
    
        MyArray VAR WORD [8]
    
    Start:
        MyArray[0] = ADRESULT
    But I doubt ADRESL/ADRESH are consecutive in many PIC.
    Steve

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

  4. #4
    Join Date
    Feb 2011
    Location
    Michigan, USA
    Posts
    33


    Did you find this post helpful? Yes | No

    Default Re: 2 bytes to word array variable - fastest way

    mister_e,
    Thats a good trick. One to remember. And it only produces 9 lines of
    instruction. But your right, the PIC I'm using (16F684), ADRESH/L are not
    next to each other.

    Actually, ACCON0 is after ADRESH. That would give you an interesting result.

    thanks,
    Mike -

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