The EXT (external) modifier.


Closed Thread
Results 1 to 20 of 20

Hybrid View

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

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

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

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

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


    Did you find this post helpful? Yes | No

    Default

    Arrays are accessed with an index inside brackets.

    Arg(Idx)
    Arg(0)
    etc.
    DT

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


    Did you find this post helpful? Yes | No

    Default

    OOPs!
    Thank You

    Sometimes RTFM is feels like looking at a forest and someone saying "the bunnies are right there, can't you see them?". Guess I just have to go into the woods and try again!
    Bo

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


    Did you find this post helpful? Yes | No

    Default Visualization

    I was having trouble understanding the results that I was getting. I ran this to get a better view of how things were working. ...he can be taught...
    Code:
    INCLUDE "AllDigital.pbp"
    DEFINE OSC 8          ' this was run on an 18F2525
    OSCCON = %01110000
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 34  ' 57600 Baud @ 8MHz, -0.79%
    SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    ByteData    var byte[32] BANK0                                             
    Arg         VAR WORD  EXT 
    ArgWd0      var word
    ArgHi0      var byte
    ArgLo0      var byte
    ArgWd1      var word
    ArgHi1      var byte
    ArgLo1      var byte
    @Arg = _ByteData
    hserout["ArgTest",10,13]
    start:
    CounterB    var byte
    for CounterB = 0 to 31
    ByteData[CounterB]= CounterB
    next CounterB                                                                        
    
        hserout["Byte0= ",dec bytedata[0],", Byte1= ",dec bytedata[1],10,13]
        ArgWd0 = Arg[0]
        ArgHi0 = ArgWd0.highbyte
        ArgLo0 = ArgWd0.lowbyte
        hserout["Arg0 HiBtD= ",dec ArgHi0,10,13]
        hserout["Arg0 LoBtD= ",dec ArgLo0,10,13]
        hserout["Arg0 HiBtB= ",bin ArgHi0,10,13]
        hserout["Arg0 LoBtB= ",bin ArgLo0,10,13]
        hserout["Arg0 HiBtH= ",hex ArgHi0,10,13]
        hserout["Arg0 LoBtH= ",hex ArgLo0,10,13]
        hserout["Arg0= ",dec Arg[0],10,13]
        hserout["Byte2= ",dec bytedata[2],", Byte3= ",dec bytedata[3],10,13]
        hserout["Arg1= ",dec Arg[1],10,13]
        ArgWd1 = Arg[1]
        ArgHi1 = ArgWd1.highbyte
        ArgLo1 = ArgWd1.lowbyte
        hserout["Arg1 HiBtD= ",dec ArgHi1,10,13]
        hserout["Arg1 LoBtD= ",dec ArgLo1,10,13]
        hserout["Arg1 HiBtB= ",bin ArgHi1,10,13]
        hserout["Arg1 LoBtB= ",bin ArgLo1,10,13]
        hserout["Arg1 HiBtH= ",hex ArgHi1,10,13]
        hserout["Arg1 LoBtH= ",hex ArgLo1,10,13]
        hserout["Arg1= ",dec Arg[1],10,13]
       end
    The results were:
    Code:
    ArgTest                                                                       
    Byte0= 0, Byte1= 1                                                            
    Arg0 HiBtD= 1                                                                
    Arg0 LoBtD= 0                                                                 
    Arg0 HiBtB= 1                                                                
    Arg0 LoBtB= 0
    Arg0 HiBtH= 1                                                                 
    Arg0 LoBtH= 0                                                                 
    Arg0= 256                                                                     
    Byte2= 2, Byte3= 3                                                            
    Arg1= 770                                                                     
    Arg1 HiBtD= 3                                                                
    Arg1 LoBtD= 2                                                                 
    Arg1 HiBtB= 11                                                               
    Arg1 LoBtB= 10                                                                
    Arg1 HiBtH= 3                                                                 
    Arg1 LoBtH= 2                                                                 
    Arg1= 770
    That let me see that it was being stored like this:
    00000001 00000000 = 256
    00000011 00000010 = 770
    Don't know if that will help anyone, but it helped me understand a bit more.
    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