$ifndef _DwordArray_ $define _DwordArray_ $if (_core <> 16) $error DwordArray Macro only suitable For 18F devices $endif '--------------------------------------------------------------------------------------- ' Declare a Dword Array ' ' Syntax: ' DeclareDwordArray [ Array Name , Array Size ] ' $define DeclareDwordArray(pArrayName,pArraySize) ' Reminders = Off ' Dim pArrayName[pArraySize * 4] As Byte ' Reminders = On '--------------------------------------------------------------------------------------- ' Dword Array Load and Retrieve Macro ' ' The Actual array is build from a single or multiple byte arrays ' If a Dword array of size 20 is required, the byte array must be four times this ' because 32-bit (Dword) variables and constants require 4 bytes to hold their value ' So create the array: ' ' Dim MyArray[80] as Byte ' Room for 20 Dword (32-bit) elements ' ' Syntax: ' ' Retreive from a Dword Array ' Var = DwordArray Array Name , [Array Index] ' ' Load into a Dword Array ' DwordArray Array Name , [Array Index] , Var ' DwordArray Macro- pArrayName, pArrayIndex, pValueToPlace \ Dword #if ((Prm_1 != Byte_Array_Ptr) && (Prm_1 != Word_Array_Ptr)) #error "Parameter 1 must be an Array's Name" Exitm #endif #if((Prm_2 == Float) || (Prm_2 == Fnum)) #error "DwordArray macro index value cannot be a Floating Point Variable or Constant" Exitm #endif Asm- lfsr 0,pArrayName Endasm- #if((Prm_2 == Num8) || (Prm_2 == Num16) || (Prm_2 == Num32)) ; Index is a Constant value #if (pArrayIndex > 0) movlw ((pArrayIndex*4)&255) ; Multiply index by four and extract the low byte addwf FSR0L,f ; Add it to the value already held in FSR0L movlw (((pArrayIndex*4)>>8)&255) ; Multiply index by four and extract the high byte addwfc FSR0H,f ; Add it to the value already held in FSR0H #endif #endif #if(Prm_2 == Byte) ; Index is a Byte Variable? #if(pArrayIndex != WREG) Asm- movff pArrayIndex,WREG Endasm- #endif mullw 4 ; Multiply index by four (immune from bank changes) movf PRODL,w ; \ addwf FSR0L,f ; | Add it to the value already held in FSR0L\H movf PRODH,w ; | addwfc FSR0H,f ; / #endif #if((Prm_2 == Word) || (Prm_2 == Dword)) ; Index is a Word or Dword Variable? Asm- lfsr 1,pArrayIndex ; Load the index variable's address into FSR1 bcf STATUS,0 ; \ rlcf POSTINC1,w ; | movwf PRODL ; | rlcf INDF1,w ; | movwf PRODH ; | Multiply index by four (immune from bank changes) bcf STATUS,0 ; | rlcf PRODL,f ; | rlcf PRODH,f ; / movf PRODL,w ; \ addwf FSR0L,f ; | movf PRODH,w ; | Add it To the value already held in FSR0L\H addwfc FSR0H,f ; / Endasm- #endif ' ' Load or Retrieve from the array depending on whether the macro has an assignment variable preceeding it ' #if (DwordArray_Return == 0) ; No assignment variable found, so it is a loading macro #if (Prm_Count != 3) #error "Missing Loading Operand with DwordArray macro" #else #if((Prm_3 == Num8) || (Prm_3 == Num16) || (Prm_3 == Num32) || (Prm_3 == SNum8) || (Prm_3 == SNum16) || (Prm_3 == SNum32)) #if((pValueToPlace & 255) == 255) setf POSTINC0 #else #if((pValueToPlace & 255) == 0) ; Operate on low byte clrf POSTINC0 #else Num_SFR (pValueToPlace & 255),POSTINC0 #endif #endif #if(((pValueToPlace >> 8) & 255) == 255) ; Operate on mid 1 byte setf POSTINC0 #else #if(((pValueToPlace >> 8) & 255) == 0) clrf POSTINC0 #else Num_SFR ((pValueToPlace >> 8) & 255),POSTINC0 #endif #endif #if(((pValueToPlace >> 16) & 255) == 255) ; Operate on mid 2 byte setf POSTINC0 #else #if(((pValueToPlace >> 16) & 255) == 0) clrf POSTINC0 #else Num_SFR ((pValueToPlace >> 16) & 255),POSTINC0 #endif #endif #if(((pValueToPlace >> 24) & 255) == 255) ; Operate on high byte setf POSTINC0 #else #if(((pValueToPlace >> 24) & 255) == 0) clrf POSTINC0 #else Num_SFR ((pValueToPlace >> 24) & 255),POSTINC0 #endif #endif #endif #if(Prm_3 == Byte) Asm- movff pValueToPlace,POSTINC0 Endasm- clrf POSTINC0 clrf POSTINC0 clrf POSTINC0 #endif #if(Prm_3 == Word) Asm- movff pValueToPlace,POSTINC0 movff pValueToPlace + 1,POSTINC0 Endasm- clrf POSTINC0 clrf POSTINC0 #endif #if((Prm_3 == Dword) || (Prm_3 == Float)) Asm- movff pValueToPlace,POSTINC0 movff pValueToPlace + 1,POSTINC0 movff pValueToPlace + 2,POSTINC0 movff pValueToPlace + 3,POSTINC0 Endasm- #endif #endif #else ; Otherwise it is a Retrieving macro Asm- movff POSTINC0,Return_Var movff POSTINC0,Return_Var + 1 movff POSTINC0,Return_Var + 2 movff POSTINC0,Return_Var + 3 Endasm- #endif Endm $endif