The EXT (external) modifier.


Closed Thread
Results 1 to 20 of 20

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    No, that's good info to have in this thread.

    Until now, I didn't know it either.

    Gotta ask questions.

    DT

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi DT,

    I have a question as follows.

    Code:
    MyArray1 VAR BYTE[200]  ' This one won't fit into 16F877.

    But instead of one array with 200 elements,
    I can create five separate arrays with 40 elements each; in total I get 200.

    Example:
    Code:
    MyArray1 VAR BYTE[40]
    MyArray2 VAR BYTE[40]
    MyArray3 VAR BYTE[40]
    MyArray4 VAR BYTE[40]
    MyArray5 VAR BYTE[40]

    However, it requries me to write more code to access them in a line.

    Using your ASM magic as swhon in the previous posts, can we put these five arrays into one
    array say Arg0 ?

    Thus, I can then use something like,

    Code:
    MyArray1 VAR BYTE[40]
    MyArray2 VAR BYTE[40]
    MyArray3 VAR BYTE[40]
    MyArray4 VAR BYTE[40]
    MyArray5 VAR BYTE[40]
    
    ASM
    ' DT's magical hands come in here !
    '....
    '......
    '........
    ENDASM
    
    ' Then,
    
    Arg0   VAR ' something 
    
    
    'Then, finally I can use Arg0[180], Arg0[120], etc...

    Is this doable?

    ---------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi, Sayzer

    Why not use Peekcode and Pokecode ... or simply LOOKUP ( if no change in values ) ??? ... 255 values is the limit for Pic 16F.

    With Peekcode/Pokecode, you also can load your data at once including a txt file ...


    ( No thought to the project section, of course ... !!! )

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    Sayzer, are you saying that Using EXT with Labels in post #1 doesn't work? I don't think so
    Last edited by mister_e; - 27th May 2009 at 23:19.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    Is this doable?
    Hi Sayzer,

    No, EXT won't work that way.
    The arrays would not be contiguous, and located in different banks.

    I've never tried using big arrays on a 16F before, I'd just use an 18F when I need more than 96 bytes.
    However, confronted with a challenge ... I have to try.
    Here's what I've come up with ...
    Code:
    Array1Size  CON 64
    Array2Size  CON 96               ; 96 is the largest for 16F877
    Array3Size  CON 96               ; 96 + 96 + 64 = 256 bytes
    MyArray1    VAR BYTE[Array1Size]  
    MyArray2    VAR BYTE[Array2Size] 
    MyArray3    VAR BYTE[Array3Size] 
    
    Idx         VAR BYTE
    Abyte       VAR BYTE
    ;---------------------------------------------------------------------------
    GetArray:      ; Set Idx before calling, result is in Abyte
      SELECT CASE Idx
        CASE IS < Array1Size
                  Abyte = MyArray1(Idx)
        CASE IS < (Array1Size + Array2Size)
                  Abyte = MyArray2(Idx - Array1Size)
        CASE ELSE
                  Abyte = MyArray3(Idx - (Array1Size + Array2Size))
      END SELECT
    RETURN
    
    PutArray:      ; set Idx and Abyte before calling
      SELECT CASE Idx
        CASE IS < Array1Size
                  MyArray1(Idx) = Abyte
        CASE IS < (Array1Size + Array2Size)
                  MyArray2(Idx - Array1Size) = Abyte
        CASE ELSE
                  MyArray3(Idx - (Array1Size + Array2Size)) = Abyte
      END SELECT
    RETURN
    Then to use it ...
    Code:
        Idx = 180
        Abyte = 123
        GOSUB PutArray
    
        Idx = 180
        GOSUB GetArray
        LCDOUT DEC Idx,"=",DEC Abyte
    Or something like this, which sets each element to it's own Idx value, then reads them back and displays the saved value.
    Code:
    Main:
      FOR Idx = 0 to 255
        Abyte = Idx
        GOSUB PutArray
      NEXT Idx
    
      FOR Idx = 0 to 255
        GOSUB GetArray
        HSEROUT ["G-",IDEC3 Idx,"  ",IDEC Abyte,13,10]
      NEXT Idx
    
    STOP
    Not as easy as MyArray(180), but it's an option.

    Then if you want, you can add a couple macros to make it look more like what you wanted ...
    Code:
    ASM
    #GetArray  macro Idx, Bout
        MOVE?BB  Idx, _Idx
        L?CALL   _GetArray
        MOVE?BB  _Abyte, Bout
      endm
      #define GetArray(Idx, Bout)  #GetArray  Idx, Bout
        
    #PutArray  macro Idx, Bin
        MOVE?BB  Idx, _Idx
        MOVE?BB  Bin, _Abyte
        L?CALL   _PutArray
      endm  
      #define PutArray(Idx, Bin)  #PutArray  Idx, Bin
    ENDASM
    Which then lets you do this...
    Code:
    MyByte   VAR BYTE
    
    @ PutArray(_Idx, _MyByte)   ; similar to MyArray(Idx) = MyByte
    
    @ GetArray(_Idx, _MyByte)   ; similar to MyByte = MyArray(Idx)
    HTH,
    DT

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Sayzer

    Why not use Peekcode and Pokecode ... or simply LOOKUP ( if no change in values ) ??? ... 255 values is the limit for Pic 16F.

    With Peekcode/Pokecode, you also can load your data at once including a txt file ...


    ( No thought to the project section, of course ... !!! )

    Alain
    Hi Alain,
    Yes, as you mentioned, the values change. I get data from PC into a Mem array.


    Quote Originally Posted by mister_e View Post
    Sayzer, are you saying that Using EXT with Labels in post #1 doesn't work? I don't think so

    Hi Steve, I need an array not a table. In post#1, the table is for constants, isn't it?

    BTW, Apart from this subject, I have spent so much time working on that table but could not read the correct values back from that table. It was not stable.


    Quote Originally Posted by Darrel Taylor View Post
    Hi Sayzer,

    No, EXT won't work that way.
    The arrays would not be contiguous, and located in different banks.

    I've never tried using big arrays on a 16F before, I'd just use an 18F when I need more than 96 bytes.
    However, confronted with a challenge ... I have to try.
    Here's what I've come up with ...
    Code:
    Array1Size  CON 64
    Array2Size  CON 96               ; 96 is the largest for 16F877
    Array3Size  CON 96               ; 96 + 96 + 64 = 256 bytes
    MyArray1    VAR BYTE[Array1Size]  
    MyArray2    VAR BYTE[Array2Size] 
    MyArray3    VAR BYTE[Array3Size] 
    
    Idx         VAR BYTE
    Abyte       VAR BYTE
    ;---------------------------------------------------------------------------
    GetArray:      ; Set Idx before calling, result is in Abyte
      SELECT CASE Idx
        CASE IS < Array1Size
                  Abyte = MyArray1(Idx)
        CASE IS < (Array1Size + Array2Size)
                  Abyte = MyArray2(Idx - Array1Size)
        CASE ELSE
                  Abyte = MyArray3(Idx - (Array1Size + Array2Size))
      END SELECT
    RETURN
    
    PutArray:      ; set Idx and Abyte before calling
      SELECT CASE Idx
        CASE IS < Array1Size
                  MyArray1(Idx) = Abyte
        CASE IS < (Array1Size + Array2Size)
                  MyArray2(Idx - Array1Size) = Abyte
        CASE ELSE
                  MyArray3(Idx - (Array1Size + Array2Size)) = Abyte
      END SELECT
    RETURN
    Then to use it ...
    Code:
        Idx = 180
        Abyte = 123
        GOSUB PutArray
    
        Idx = 180
        GOSUB GetArray
        LCDOUT DEC Idx,"=",DEC Abyte
    Or something like this, which sets each element to it's own Idx value, then reads them back and displays the saved value.
    Code:
    Main:
      FOR Idx = 0 to 255
        Abyte = Idx
        GOSUB PutArray
      NEXT Idx
    
      FOR Idx = 0 to 255
        GOSUB GetArray
        HSEROUT ["G-",IDEC3 Idx,"  ",IDEC Abyte,13,10]
      NEXT Idx
    
    STOP
    Not as easy as MyArray(180), but it's an option.

    Then if you want, you can add a couple macros to make it look more like what you wanted ...
    Code:
    ASM
    #GetArray  macro Idx, Bout
        MOVE?BB  Idx, _Idx
        L?CALL   _GetArray
        MOVE?BB  _Abyte, Bout
      endm
      #define GetArray(Idx, Bout)  #GetArray  Idx, Bout
        
    #PutArray  macro Idx, Bin
        MOVE?BB  Idx, _Idx
        MOVE?BB  Bin, _Abyte
        L?CALL   _PutArray
      endm  
      #define PutArray(Idx, Bin)  #PutArray  Idx, Bin
    ENDASM
    Which then lets you do this...
    Code:
    MyByte   VAR BYTE
    
    @ PutArray(_Idx, _MyByte)   ; similar to MyArray(Idx) = MyByte
    
    @ GetArray(_Idx, _MyByte)   ; similar to MyByte = MyArray(Idx)
    HTH,

    Hi DT,

    I had made something similar to your first example, but as you mentioned, it is not as easy as using something like Arg0[180].

    I must learn this ASM thingie in much upper level to comeup with my own routines.

    Thanks very much to all.
    ----------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  7. #7
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default RX BYTE to WORD and Sort

    Hi all,

    Darrell mentioned in his first post that EXT will not work with arrays,
    Can anyone suggest an elegant way to receive serial BYTE data in and convert it to WORD data and then sort it? Obviously, this won't work and to do it straight-line would be a mess.
    Code:
    ByteData    var byte[32] BANK0                                                                                                      
    
    ASM
    Arg0 = _ByteData        ; word
    Arg1 = _ByteData + 2    ; word
    Arg2 = _ByteData + 4    ; word
    Arg3 = _ByteData + 6    ; word
    Arg4 = _ByteData + 8    ; word
    Arg5 = _ByteData + 10    ; word
    Arg6 = _ByteData + 12    ; word
    Arg7 = _ByteData + 14    ; word
    Arg8 = _ByteData + 16    ; word
    Arg9 = _ByteData + 18    ; word
    Arg10 = _ByteData + 20    ; word
    Arg11 = _ByteData + 22    ; word
    Arg12 = _ByteData + 24    ; word
    Arg13 = _ByteData + 26    ; word
    Arg14 = _ByteData + 28    ; word
    Arg15 = _ByteData + 30    ; word
    ENDASM
    
    Arg0   VAR  WORD  EXT
    Arg1   VAR  word  EXT
    Arg2   VAR  WORD  EXT
    Arg3   VAR  WORD  EXT
    Arg4   VAR  word  EXT
    Arg5   VAR  WORD  EXT
    Arg6   VAR  word  EXT
    Arg7   VAR  WORD  EXT
    Arg8   VAR  WORD  EXT
    Arg9   VAR  word  EXT
    Arg10   VAR  WORD  EXT
    Arg11   VAR  word  EXT
    Arg12   VAR  WORD  EXT
    Arg13   VAR  WORD  EXT
    Arg14   VAR  word  EXT
    Arg15   VAR  word  EXT
    ...........
    '***Sort Array SUB ** collects 16 readings, sorts, and averages middle 8 ******
    SortArray:
        CounterA=0
    SortLoop:                          ' sorts 16 readings of RawData in order
        If Arg(CounterA+1) < Arg(CounterA) then
            DataA=Arg(CounterA)
            Arg(CounterA)=Arg(CounterA+1)
            Arg(CounterA+1+0)=DataA
            If CounterA > 0 then CounterA=CounterA-2
            endif
        CounterA=CounterA+1
        If CounterA < 15 then goto SortLoop
    Thanks
    Bo

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


    Did you find this post helpful? Yes | No

    Default

    Hi Bo,

    You just need to map a WORD variable to the beginning of the BYTE array.
    Code:
    ByteData    VAR BYTE[32]
    Arg         VAR WORD  EXT
     
    @Arg = _ByteData
    The Arg word array now overlaps the ByteData array.

    PBP does not do any bounds checking on arrays, so even though Arg is defined as a single WORD, you can use it as a 16 word Array.
    DT

  9. #9
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default

    Thank you again, Darrel for going deeper than most could ever go alone!

    I'm afraid that the neutrons just didn't thermalize....(when the energy doesn't slow down enough for it to transfer)

    I understand the Arg word array now overlapping the ByteData array.
    What I'm at a loss with is how to address the Arg words.

    I tried: Arg0, Arg1,... Arg0 = Arg + 1, ... Arg0 = _Arg + 1, ... cant get anything to fly.

    Compiled this:
    Code:
    ByteData    var byte[32] BANK0                                             
    Arg         VAR WORD  EXT 
    @Arg = _ByteData
    
    CounterB    var byte
    for CounterB = 0 to 31
    ByteData[CounterB]= CounterB
    next CounterB
    
    ASM
    Arg0  = Arg + 2    ; word
    Arg1  = Arg + 4    ; word
    ENDASM
    and could see in the .lst file that:
    Code:
    Arg                               00000080
    Arg0                              00000082
    Arg1                              00000084
    So it looks like it assigned addresses. As soon as I added this to the end:
    Code:
          hserout[dec Arg0,10,13]
          hserout[dec Arg1,10,13]
    I got a "Bad Expression" error. I would have expected to fill ByteData with sequential numbers 0-31 and be able to send them out to verify that the WORDs were filled with BYTE{0], BYTE[1] and BYTE{2], BYTE[3].

    Your humble servant requests more enlightenment....
    Bo

Similar Threads

  1. Replies: 1
    Last Post: - 28th January 2010, 22:15
  2. TMR1 external LP xtal setup check
    By comwarrior in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th October 2009, 18:11
  3. How to use an external oscillator
    By Mugelpower in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th February 2008, 14:19
  4. External clock
    By Firegod in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th March 2007, 00:53
  5. switching external vref+ and vdd vref
    By alejandro_halon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th February 2005, 20:13

Members who have read this thread : 3

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