• Main Page
  • Modules
  • Files
  • File List
  • Globals

mTouchCVD_macroLibrary_PIC16F1.h

Go to the documentation of this file.
00001 /*************************************************************************
00002  *  © 2011 Microchip Technology Inc.                                       
00003  *  
00004  *  Project Name:    mTouch CVD Framework v1.1
00005  *  FileName:        mTouchCVD_macroLibrary_PIC16F1.h
00006  *  Dependencies:    mTouchCVD.h
00007  *  Processor:       See documentation for supported PIC® microcontrollers 
00008  *  Compiler:        HI-TECH Ver. 9.81 or later
00009  *  IDE:             MPLAB® IDE v8.50 (or later) or MPLAB® X                        
00010  *  Hardware:         
00011  *  Company:         
00012  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00013  *  Description:     mTouch CVD Framework Hardware Profile Header File
00014  *                   - Editting this file will make customer support for
00015  *                     your application extremely difficult. Be careful,
00016  *                     as it can also have a negative impact on your
00017  *                     system's noise susceptibility.
00018  *************************************************************************/
00019  /***********************************************************************
00020  * MICROCHIP SOFTWARE NOTICE AND DISCLAIMER: You may use this software, and 
00021  * any derivatives created by any person or entity by or on your behalf, 
00022  * exclusively with Microchip's products in accordance with applicable
00023  * software license terms and conditions, a copy of which is provided for
00024  * your referencein accompanying documentation. Microchip and its licensors 
00025  * retain all ownership and intellectual property rights in the 
00026  * accompanying software and in all derivatives hereto. 
00027  * 
00028  * This software and any accompanying information is for suggestion only. 
00029  * It does not modify Microchip's standard warranty for its products. You 
00030  * agree that you are solely responsible for testing the software and 
00031  * determining its suitability. Microchip has no obligation to modify, 
00032  * test, certify, or support the software. 
00033  * 
00034  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
00035  * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED 
00036  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A 
00037  * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION WITH 
00038  * MICROCHIP'S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY 
00039  * APPLICATION. 
00040  * 
00041  * IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, 
00042  * TORT (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT 
00043  * LIABILITY, INDEMNITY, CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, 
00044  * SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, 
00045  * FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, 
00046  * HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY 
00047  * OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWABLE BY LAW, 
00048  * MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS 
00049  * SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID 
00050  * DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. 
00051  * 
00052  * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF 
00053  * THESE TERMS. 
00054  *************************************************************************/
00063 #ifndef __MTOUCHCVD_MACROLIBRARY_H
00064 #define __MTOUCHCVD_MACROLIBRARY_H
00065 
00073 #define MASKBANK(var,bank)        ((var)^((bank)*80h))
00074 #define   NOBANK(var)             (var & 0x7F)
00075 
00088 #define SAVE_STATE()                            \
00089 do {                                            \
00090 } while (0)
00091 // The Enhanced Midrange Core does not require saving/restoring state on entering
00092 // the ISR, so these macros have been left empty. They are implemented in the non-
00093 // enhanced core version of the macroLibrary.
00094 
00102 #define RESTORE_STATE()                         \
00103 do {                                            \
00104 } while (0)
00105 // The Enhanced Midrange Core does not require saving/restoring state on entering
00106 // the ISR, so these macros have been left empty. They are implemented in the non-
00107 // enhanced core version of the macroLibrary.
00108 
00116 #define CHECK_AND_CLEAR_TMR0IF()                                                            \
00117 do {                                                                                        \
00118     if (TMR0IF == 0)                                                                        \
00119     {                              /* T0IF is not set so,                               */  \
00120         asm("ljmp END_ISR");       /* exit the mTouch ISR                               */  \
00121     } else {                       /* T0IF is set, so                                   */  \
00122         TMR0IF = 0;                /* clear it and continue with mTouch ISR service     */  \
00123     }                                                                                       \
00124 } while (0)
00125 
00143 #if defined(CVD_JITTER_ENABLE)                              // If jittering is enabled
00144     #if (CVD_JITTER_TYPE == 0)                              // Type 0: Using ADRESL as the random seed value
00145         #define JITTER_START_TIME()                                                                                         \
00146             do {                                                                                                            \
00147                 asm("BANKSEL    _ADRESL"                        );  /* Make sure we're starting in the correct bank     */  \
00148                 asm("movf   "   ___mkstr(NOBANK(_ADRESL))   ",W");  /* Load ADRESL into the working register            */  \
00149                 asm("andlw      0x3F"                           );  /* Mask its value to look at only the 5 LSb's       */  \
00150                 asm("movlb      0"                              );  /* Move to Bank 0 to access TMR0 SFR                */  \
00151                 asm("addwf      _TMR0"                          );  /* Add the masked ADRESL value as an offset to TMR0 */  \
00152             } while (0)
00153     #elif (CVD_JITTER_TYPE == 1)                            // Type 1: Using a linear feedback shift register to generate a random value
00154         #define JITTER_START_TIME()                                                                                         \
00155             do {                                                                                                            \
00156                 asm("BANKSEL    _mTouchCVD_jitter"              );  /* Make sure we're starting in the correct bank     */  \
00157                 asm("bcf    "   ___mkstr(_STATUS)           ",0");  /* Clear the carry bit                              */  \
00158                 asm("rrf    "   ___mkstr(_mTouchCVD_jitter) ",W");  /* Right shift the current jitter seed value        */  \
00159                 asm("btfsc  "   ___mkstr(_STATUS)           ",0");  /* Check the carry bit - if set, perform XOR        */  \
00160                 asm("xorlw      0xB4"                           );  /* (cond) XOR the jitter seed with 0xB4             */  \
00161                 asm("movwf  "   ___mkstr(_mTouchCVD_jitter)     );  /* Store the result as the new jitter seed value    */  \
00162                 asm("andlw      0x3F"                           );  /* Grab the 5 LSb's from the seed value             */  \
00163                 asm("movlb      0"                              );  /* Move to Bank 0 to access TMR0 SFR                */  \
00164                 asm("addwf      _TMR0"                          );  /* Add the masked LFSR value as an offset to TMR0   */  \
00165             } while (0)
00166     #endif
00167 #else                                                       // Do not implement the jittering function
00168     #define JITTER_START_TIME()                                                     \
00169         do {                                                                        \
00170             asm("movlb      0"      );  /* Move to Bank 0 to access TMR0 SFR    */  \
00171             asm("clrf       _TMR0"  );  /* Clear TMR0                           */  \
00172         } while (0)
00173 #endif
00174 
00181 #define WAIT_FOR_GODONE_BIT()                       while (GO_nDONE);  
00182 
00195 #define STORE_LAST_RESULT()                                                     \
00196 do {                                                                            \
00197     last_result = (unsigned int)((ADRESH | 0x04) << 8) + ADRESL - last_result;  \
00198 } while (0)
00199 
00200 
00222 #define READ_SENSOR(indexSensor, indexRef)  READ_SENSOR_EXPANDED(__paste(CVD_SELECT_SENSOR,indexSensor),__paste(CVD_SELECT_SENSOR,indexRef),__paste(CVD_PORT_SENSOR,indexSensor),__paste(CVD_PIN_SENSOR,indexSensor),__paste(CVD_PORT_SENSOR,indexRef),__paste(CVD_PIN_SENSOR,indexRef))
00223 
00224 // Example Dedicated-Reference-Sensor Implementation:
00225 // #define READ_SENSOR(indexSensor, indexRef)  READ_SENSOR_EXPANDED(__paste(CVD_SELECT_SENSOR,indexSensor),CVD_SELECT_REFERENCE,__paste(CVD_PORT_SENSOR,indexSensor),__paste(CVD_PIN_SENSOR,indexSensor),CVD_PORT_REFERENCE,CVD_PIN_REFERENCE)
00226 
00299 #if CVD_NUMBER_SENSORS == 1
00300 #define READ_SENSOR_EXPANDED(current_channel, ref_channel, port, pin, ref_port, ref_pin)                                                            \
00301 do {                                                                        /*                   SINGLE SENSOR SCAN METHOD                      */  \
00302     asm("BANKSEL    "   ___mkstr(_DACCON0)                              );  /*                                                                  */  \
00303     asm("movlw      "   ___mkstr(CVD_DACCON0_VDD)                       );  /*                                                                  */  \
00304     asm("movwf      "   ___mkstr(NOBANK(_DACCON0))                      );  /* DACCON0 = CVD_DACCON0_VDD                                        */  \
00305     asm("movlw      "   ___mkstr(CVD_DACCON1_VDD)                       );  /*                                                                  */  \
00306     asm("movwf      "   ___mkstr(NOBANK(_DACCON1))                      );  /* DACCON1 = CVD_DACCON1_VDD                                        */  \
00307     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                                                  */  \
00308     asm("movlw      "   ___mkstr(CVD_SELECT_DAC_NOGO)                   );  /*                                                                  */  \
00309     asm("movwf      "   ___mkstr(NOBANK(_ADCON0))                       );  /* ADC Mux --> DAC                                                  */  \
00310     asm("movlw LOW  "   ___mkstr(port)                                  );  /*                                                                  */  \
00311     asm("movwf      "   ___mkstr(_FSR1L)                                );  /*                                                                  */  \
00312     asm("movlw HIGH "   ___mkstr(port)                                  );  /*                                                                  */  \
00313     asm("movwf      "   ___mkstr(_FSR0H)                                );  /*                                                                  */  \
00314     asm("addlw          0x01"                                           );  /*                                                                  */  \
00315     asm("movwf      "   ___mkstr(_FSR1H)                                );  /*                                                                  */  \
00316     asm("movlw LOW  "   ___mkstr(port)                                  );  /*                                                                  */  \
00317     asm("addlw          0x80"                                           );  /*                                                                  */  \
00318     asm("movwf      "   ___mkstr(_FSR0L)                                );  /*                                                                  */  \
00319     asm("btfsc      "   ___mkstr(_STATUS)                   ",0"        );  /* FSR0 = Sensor TRIS register                                      */  \
00320     asm("incf       "   ___mkstr(_FSR0H)                                );  /* FSR1 = Sensor LAT register                                       */  \
00321     CVD_DELAY_CHOLD();                                                      /*                                                                  */  \
00322     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                                                  */  \
00323     asm("movlw      "  ___mkstr(current_channel)                        );  /*                                                                  */  \
00324     asm("bsf        "  ___mkstr(_INDF0)     ","     ___mkstr(pin)       );  /* Set the sensor to an input                                       */  \
00325     asm("movwf      "  ___mkstr(NOBANK(_ADCON0))                        );  /* ADC Mux --> Sensor                                               */  \
00326     CVD_DELAY_SETTLE();                                                     /*                                                                  */  \
00327     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                                                  */  \
00328     asm("bsf        "  ___mkstr(NOBANK(_ADCON0))            ", 1"       );  /* Begin the conversion by setting the GO/DONE bit                  */  \
00329     CVD_GO_DONE_DELAY();                                                    /*                                                                  */  \
00330     asm("bcf        "  ___mkstr(_INDF0)     ","     ___mkstr(pin)       );  /* Set the sensor to an output                                      */  \
00331     asm("bsf        "  ___mkstr(_INDF1)     ","     ___mkstr(pin)       );  /* Set sensor LAT high                                              */  \
00332     asm("global         decimate            "                           );  /*                                                                  */  \
00333     asm("call           decimate            "                           );  /* decimate();                                                      */  \
00334     asm("BANKSEL    "   ___mkstr(_DACCON0)                              );  /*                                                                  */  \
00335     asm("movlw      "   ___mkstr(CVD_DACCON0_VSS)                       );  /*                                                                  */  \
00336     asm("movwf      "   ___mkstr(NOBANK(_DACCON0))                      );  /* DACCON0 = CVD_DACCON0_VSS                                        */  \
00337     asm("movlw      "   ___mkstr(CVD_DACCON1_VSS)                       );  /*                                                                  */  \
00338     asm("movwf      "   ___mkstr(NOBANK(_DACCON1))                      );  /* DACCON1 = CVD_DACCON1_VSS                                        */  \
00339     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                                                  */  \
00340     asm("movlw      "   ___mkstr(CVD_SELECT_DAC_NOGO)                   );  /*                                                                  */  \
00341     asm("movwf      "   ___mkstr(NOBANK(_ADCON0))                       );  /* ADC Mux --> DAC                                                  */  \
00342     asm("movlw LOW  "   ___mkstr(port)                                  );  /*                                                                  */  \
00343     asm("movwf      "   ___mkstr(_FSR1L)                                );  /*                                                                  */  \
00344     asm("movlw HIGH "   ___mkstr(port)                                  );  /*                                                                  */  \
00345     asm("movwf      "   ___mkstr(_FSR0H)                                );  /*                                                                  */  \
00346     asm("addlw          0x01"                                           );  /*                                                                  */  \
00347     asm("movwf      "   ___mkstr(_FSR1H)                                );  /*                                                                  */  \
00348     asm("movlw LOW  "   ___mkstr(port)                                  );  /*                                                                  */  \
00349     asm("addlw          0x80"                                           );  /*                                                                  */  \
00350     asm("movwf      "   ___mkstr(_FSR0L)                                );  /*                                                                  */  \
00351     asm("btfsc      "   ___mkstr(_STATUS)                   ",0"        );  /* FSR0 = Sensor TRIS register                                      */  \
00352     asm("incf       "   ___mkstr(_FSR0H)                                );  /* FSR1 = Sensor LAT register                                       */  \
00353     CVD_DELAY_CHOLD();                                                      /*                                                                  */  \
00354     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                                                  */  \
00355     asm("movlw      "  ___mkstr(current_channel)                        );  /*                                                                  */  \
00356     asm("bsf        "  ___mkstr(_INDF0)     ","     ___mkstr(pin)       );  /* Set the sensor to an input                                       */  \
00357     asm("movwf      "  ___mkstr(NOBANK(_ADCON0))                        );  /* ADC Mux --> Sensor                                               */  \
00358     CVD_DELAY_SETTLE();                                                     /*                                                                  */  \
00359     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                                                  */  \
00360     asm("bsf        "  ___mkstr(NOBANK(_ADCON0))            ", 1"       );  /* Begin the conversion by setting the GO/DONE bit                  */  \
00361     CVD_GO_DONE_DELAY();                                                    /*                                                                  */  \
00362     asm("bcf        "  ___mkstr(_INDF0)     ","     ___mkstr(pin)       );  /* Set the sensor to an output                                      */  \
00363     asm("bcf        "  ___mkstr(_INDF1)     ","     ___mkstr(pin)       );  /* Set sensor LAT low                                               */  \
00364 } while(0)
00365 #else
00366 #define READ_SENSOR_EXPANDED(current_channel, ref_channel, port, pin, ref_port, ref_pin)                            \
00367 do {                                                                        /* REFERENCE SENSOR SCAN METHOD     */  \
00368     asm("movlw LOW  "   ___mkstr(ref_port)                              );  /*                                  */  \
00369     asm("movwf      "   ___mkstr(_FSR1L)                                );  /*                                  */  \
00370     asm("movlw          0x01"                                           );  /*                                  */  \
00371     asm("addlw HIGH "   ___mkstr(ref_port)                              );  /*                                  */  \
00372     asm("movwf      "   ___mkstr(_FSR1H)                                );  /* FSR1 = Reference LAT register    */  \
00373     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                  */  \
00374     asm("movlw      "   ___mkstr(ref_channel)                           );  /*                                  */  \
00375     asm("movwf      "   ___mkstr(NOBANK(_ADCON0))                       );  /* ADC Mux --> Reference Sensor     */  \
00376     asm("bsf        "   ___mkstr(_INDF1)    ","    ___mkstr(ref_pin)    );  /* Set the reference LAT bit        */  \
00377     asm("movlw HIGH "   ___mkstr(port)                                  );  /*                                  */  \
00378     asm("movwf      "   ___mkstr(_FSR0H)                                );  /*                                  */  \
00379     asm("movlw LOW  "   ___mkstr(port)                                  );  /*                                  */  \
00380     asm("addlw          0x80"                                           );  /*                                  */  \
00381     asm("movwf      "   ___mkstr(_FSR0L)                                );  /*                                  */  \
00382     asm("btfsc      "   ___mkstr(_STATUS)                   ",0"        );  /*                                  */  \
00383     asm("incf       "   ___mkstr(_FSR0H)                                );  /* FSR0 = Sensor's TRIS register    */  \
00384     CVD_DELAY_CHOLD();                                                      /*                                  */  \
00385     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                  */  \
00386     asm("movlw      "   ___mkstr(current_channel)                       );  /*                                  */  \
00387     asm("bsf        "   ___mkstr(_INDF0)    ","    ___mkstr(pin)        );  /* Set the sensor to an input       */  \
00388     asm("movwf      "   ___mkstr(NOBANK(_ADCON0))                       );  /* ADC Mux --> Sensor               */  \
00389     CVD_DELAY_SETTLE();                                                     /*                                  */  \
00390     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                  */  \
00391     asm("bsf        "   ___mkstr(NOBANK(_ADCON0))           ",1"        );  /* Set the GO/DONE bit              */  \
00392     CVD_GO_DONE_DELAY();                                                    /*                                  */  \
00393     asm("bcf        "   ___mkstr(_INDF0)    ","    ___mkstr(pin)        );  /* Set the sensor to an output      */  \
00394     asm("BANKSEL    "   ___mkstr(port)                                  );  /*                                  */  \
00395     asm("bsf        "   ___mkstr(NOBANK(port)) "," ___mkstr(pin)        );  /* Set sensor LAT high              */  \
00396     asm("global         decimate"                                       );  /*                                  */  \
00397     asm("call           decimate"                                       );  /*                                  */  \
00398     asm("movlw LOW  "   ___mkstr(ref_port)                              );  /*                                  */  \
00399     asm("movwf      "   ___mkstr(_FSR1L)                                );  /*                                  */  \
00400     asm("movlw          0x01"                                           );  /*                                  */  \
00401     asm("addlw HIGH "   ___mkstr(ref_port)                              );  /*                                  */  \
00402     asm("movwf      "   ___mkstr(_FSR1H)                                );  /* FSR1 = Reference LAT register    */  \
00403     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                  */  \
00404     asm("movlw      "   ___mkstr(ref_channel)                           );  /*                                  */  \
00405     asm("movwf      "   ___mkstr(NOBANK(_ADCON0))                       );  /* ADC Mux --> Reference Sensor     */  \
00406     asm("bcf        "   ___mkstr(_INDF1)    ","    ___mkstr(ref_pin)    );  /* Set the reference LAT bit        */  \
00407     asm("movlw HIGH "   ___mkstr(port)                                  );  /*                                  */  \
00408     asm("movwf      "   ___mkstr(_FSR0H)                                );  /*                                  */  \
00409     asm("movlw LOW  "   ___mkstr(port)                                  );  /*                                  */  \
00410     asm("addlw          0x80"                                           );  /*                                  */  \
00411     asm("movwf      "   ___mkstr(_FSR0L)                                );  /*                                  */  \
00412     asm("btfsc      "   ___mkstr(_STATUS)                   ",0"        );  /*                                  */  \
00413     asm("incf       "   ___mkstr(_FSR0H)                                );  /* FSR0 = Sensor's TRIS register    */  \
00414     CVD_DELAY_CHOLD();                                                      /*                                  */  \
00415     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                  */  \
00416     asm("movlw      "   ___mkstr(current_channel)                       );  /*                                  */  \
00417     asm("bsf        "   ___mkstr(_INDF0)    ","    ___mkstr(pin)        );  /* Set the sensor to an input       */  \
00418     asm("movwf      "   ___mkstr(NOBANK(_ADCON0))                       );  /* ADC Mux --> Sensor               */  \
00419     CVD_DELAY_SETTLE();                                                     /*                                  */  \
00420     asm("BANKSEL    "   ___mkstr(_ADCON0)                               );  /*                                  */  \
00421     asm("bsf        "   ___mkstr(NOBANK(_ADCON0))           ",1"        );  /* Set the GO/DONE bit              */  \
00422     CVD_GO_DONE_DELAY();                                                    /*                                  */  \
00423     asm("bcf        "   ___mkstr(_INDF0)    ","    ___mkstr(pin)        );  /* Set the sensor to an output      */  \
00424     asm("bcf        "   ___mkstr(_INDF1)    ","    ___mkstr(ref_pin)    );  /* Set reference LAT low            */  \
00425     asm("BANKSEL    "   ___mkstr(port)                                  );  /*                                  */  \
00426     asm("bcf        "   ___mkstr(NOBANK(port)) "," ___mkstr(pin)        );  /* Set sensor LAT low               */  \
00427 } while(0)
00428 #endif
00429 
00430 
00452 #if (CVD_NUMBER_SENSORS > 1)
00453 #define CVD_DECIMATE()                                                                                                                  \
00454 do {                                                                /*                                                              */  \
00455     asm("BANKSEL    _current_sensor");                              /* Use the current_sensor variable as an index                  */  \
00456     asm("lslf   "   ___mkstr(MASKBANK(_current_sensor,0))   ",W");  /* Multiplying by two because int's take up 2 bytes each        */  \
00457     asm("addlw LOW  _sensor_data");                                 /* Adding the index to the sensor_data variable address         */  \
00458     asm("movwf      _FSR0L");                                       /* Pointing the FSR to the correct array location               */  \
00459     asm("movlw HIGH _sensor_data");                                 /*                                                              */  \
00460     asm("movwf      _FSR0H");                                       /* Same as above, this time for the high byte of the address    */  \
00461     asm("movf       _INDF0,W");                                     /* Getting the value from the memory location                   */  \
00462     asm("subwf      _last_result,F");                               /* Subtract the stored value from the latest reading result     */  \
00463     asm("incf       _FSR0L,F");                                     /*                                                              */  \
00464     asm("movf       _INDF0,W");                                     /*                                                              */  \
00465     asm("subwfb     _last_result+1,W");                             /* Same as above, now just handling the high byte               */  \
00466     asm("decf       _FSR0L,F");                                     /*                                                              */  \
00467     asm("btfss      _STATUS,0");                                    /* Check the result of the subtraction                          */  \
00468     asm("ljmp       sensor_smaller");                               /* If the latest reading was smaller, jump.                     */  \
00469     asm("iorwf      _last_result,W");                               /*                                                              */  \
00470     asm("btfss      _STATUS,2");                                    /* If the two are equal, load nothing.                          */  \
00471     asm("movlw      1");                                            /* Otherwise (latest reading is larger), load 1 into W          */  \
00472     asm("addwf      _INDF0,F");                                     /* Add 1 (or nothing) to the stored value                       */  \
00473     asm("movf       _INDF0,W");                                     /* Now take the stored value and load it into last_result       */  \
00474     asm("movwf      _last_result,F");                               /*   for easy access                                            */  \
00475     asm("incf       _FSR0L,F");                                     /* Point to the high byte of the stored value                   */  \
00476     asm("btfsc      _STATUS,0");                                    /* If we had an overflow from the addition,                     */  \
00477     asm("incf       _INDF0,F");                                     /*   increment the higher byte                                  */  \
00478     asm("movf       _INDF0,W");                                     /* Now take the high byte of the stored value and load it into  */  \
00479     asm("movwf      _last_result+1");                               /*   last_result for easy access.                               */  \
00480     asm("ljmp       decimate_end");                                 /* Jump (avoid 'smaller' case code)                             */  \
00481 } while (0)                                                 
00482 
00483 #define CVD_SENSOR_SMALLER()                                                                                                            \
00484 do {                                                                /*                                                              */  \
00485     asm("movlw      1");                                            /* Perform the exact same commands as above, but this time      */  \
00486     asm("subwf      _INDF0,F");                                     /*   subtract instead of add. The stored value is then loaded   */  \
00487     asm("movf       _INDF0,W");                                     /*   into last_result for easy access.                          */  \
00488     asm("movwf      _last_result");                                 /*                                                              */  \
00489     asm("incf       _FSR0L,F");                                     /*                                                              */  \
00490     asm("btfss      _STATUS,0");                                    /*                                                              */  \
00491     asm("decf       _INDF0,F");                                     /*                                                              */  \
00492     asm("movf       _INDF0,W");                                     /*                                                              */  \
00493     asm("movwf      _last_result+1");                               /*                                                              */  \
00494 } while (0)                                                 
00495 
00496 #define CVD_DECIMATE_END()                                                                                                              \
00497 do {                                                                /*                                                              */  \
00498     asm("lslf       _current_sensor,W");                            /* Use the current_sensor variable as an index. Since the       */  \
00499     asm("addwf      _current_sensor,W");                            /*   CVD_Acq_Filtered_Data array is of 24-bit values, we        */  \
00500     asm("addlw LOW  _CVD_Acq_Filtered_Data");                       /*   are multiplying the index by 3, then adding it to the      */  \
00501     asm("movwf      _FSR0L");                                       /*   address of the accumulator array.                          */  \
00502     asm("movlw HIGH _CVD_Acq_Filtered_Data");                       /*                                                              */  \
00503     asm("movwf      _FSR0H");                                       /*                                                              */  \
00504     asm("movf       _last_result,W");                               /* Take the value in last_result (aka sensor_data, now) and     */  \
00505     asm("addwf      _INDF0,F");                                     /*   add it to the accumulator array.                           */  \
00506     asm("incf       _FSR0L,F");                                     /*                                                              */  \
00507     asm("movf       _last_result+1,W");                             /*                                                              */  \
00508     asm("addwfc     _INDF0,F");                                     /* Add with carry handles possible overflow condition.          */  \
00509     asm("incf       _FSR0L,F");                                     /*                                                              */  \
00510     asm("btfsc      _STATUS,0");                                    /* Handle possible overflow condition one more time since this  */  \
00511     asm("incf       _INDF0,F");                                     /*   is a 24-bit array.                                         */  \
00512     asm("BANKSEL    _ADCON0");                                      /*                                                              */  \
00513     asm("btfsc    " ___mkstr(MASKBANK(_ADCON0,1)) ",1");            /* Has the ADC scan completed?                                  */  \
00514     asm("goto       $-1");                                          /* If not, we're going to wait until it is.                     */  \
00515     asm("movf     " ___mkstr(MASKBANK(_ADRESH,1)) ",W");            /*                                                              */  \
00516     asm("BANKSEL    _last_result");                                 /*                                                              */  \
00517     asm("movwf    " ___mkstr(MASKBANK(_last_result+1,0)));          /*                                                              */  \
00518     asm("BANKSEL    _ADRESL");                                      /* Finally, store the low byte as well.                         */  \
00519     asm("movf     " ___mkstr(MASKBANK(_ADRESL,1)) ",W");            /*                                                              */  \
00520     asm("BANKSEL    _last_result");                                 /*                                                              */  \
00521     asm("movwf    " ___mkstr(MASKBANK(_last_result,0)));            /*                                                              */  \
00522     asm("return");                                                  /* Finished! Now go start the next ADC scan in READ_SENSOR().   */  \
00523 } while(0)
00524         
00525 #else                                           // Only one sensor, so no index variable manipulation is required
00526                                                 // Otherwise, code below mirrors code above.
00527 #define CVD_DECIMATE()                                              \
00528 do {                                                                \
00529     asm("BANKSEL    _last_result");                                 \
00530     asm("movlw LOW  _sensor_data");                                 \
00531     asm("movwf      _FSR0L");                                       \
00532     asm("movlw HIGH _sensor_data");                                 \
00533     asm("movwf      _FSR0H");                                       \
00534     asm("movf       _INDF0,W");                                     \
00535     asm("subwf      _last_result,F");                               \
00536     asm("incf       _FSR0L,F");                                     \
00537     asm("movf       _INDF0,W");                                     \
00538     asm("subwfb     _last_result+1,W");                             \
00539     asm("decf       _FSR0L,F");                                     \
00540     asm("btfss      _STATUS,0");                                    \
00541     asm("ljmp       sensor_smaller");                               \
00542     asm("iorwf      _last_result,W");                               \
00543     asm("btfss      _STATUS,2");                                    \
00544     asm("movlw      1");                                            \
00545     asm("addwf      _INDF0,F");                                     \
00546     asm("movf       _INDF0,W");                                     \
00547     asm("movwf      _last_result,F");                               \
00548     asm("incf       _FSR0L,F");                                     \
00549     asm("btfsc      _STATUS,0");                                    \
00550     asm("incf       _INDF0,F");                                     \
00551     asm("movf       _INDF0,W");                                     \
00552     asm("movwf      _last_result+1");                               \
00553     asm("ljmp       decimate_end");                                 \
00554 } while (0)                                                 
00555 
00556 #define CVD_SENSOR_SMALLER()                                        \
00557 do {                                                                \
00558     asm("movlw      1");                                            \
00559     asm("subwf      _INDF0,F");                                     \
00560     asm("movf       _INDF0,W");                                     \
00561     asm("movwf      _last_result");                                 \
00562     asm("incf       _FSR0L,F");                                     \
00563     asm("btfss      _STATUS,0");                                    \
00564     asm("decf       _INDF0,F");                                     \
00565     asm("movf       _INDF0,W");                                     \
00566     asm("movwf      _last_result+1");                               \
00567 } while (0)                                                 
00568 
00569 #define CVD_DECIMATE_END()                                          \
00570 do {                                                                \
00571     asm("movlw LOW  _CVD_Acq_Filtered_Data");                       \
00572     asm("movwf      _FSR0L");                                       \
00573     asm("movlw HIGH _CVD_Acq_Filtered_Data");                       \
00574     asm("movwf      _FSR0H");                                       \
00575     asm("movf       _last_result,W");                               \
00576     asm("addwf      _INDF0,F");                                     \
00577     asm("incf       _FSR0L,F");                                     \
00578     asm("movf       _last_result+1,W");                             \
00579     asm("addwfc     _INDF0,F");                                     \
00580     asm("incf       _FSR0L,F");                                     \
00581     asm("btfsc      _STATUS,0");                                    \
00582     asm("incf       _INDF0,F");                                     \
00583     asm("BANKSEL    _ADCON0");                                      \
00584     asm("btfsc    " ___mkstr(MASKBANK(_ADCON0,1)) ",1");            \
00585     asm("goto       $-1");                                          \
00586     asm("movf     " ___mkstr(MASKBANK(_ADRESH,1)) ",W");            \
00587     asm("BANKSEL    _last_result");                                 \
00588     asm("movwf    " ___mkstr(MASKBANK(_last_result+1,0)));          \
00589     asm("BANKSEL    _ADRESL");                                      \
00590     asm("movf     " ___mkstr(MASKBANK(_ADRESL,1)) ",W");            \
00591     asm("BANKSEL    _last_result");                                 \
00592     asm("movwf    " ___mkstr(MASKBANK(_last_result,0)));            \
00593     asm("return");                                                  \
00594 } while(0)
00595 #endif
00596 
00597 
00603 
00611 #define STORE_SENSOR_SCALE(index, shift)                                                \
00612     do {                                                                                \
00613         CVDSensorData[index-1] = (unsigned int)(CVD_Acq_Filtered_Data[index] >> shift); \
00614         CVD_Acq_Filtered_Data[index] = 0;                                               \
00615     } while(0)
00616 
00623 #define STORE_LAST_SENSOR_SCALE(index, shift)                                                           \
00624     do {                                                                                                \
00625         CVDSensorData[CVD_NUMBER_SENSORS-1] = (unsigned int)(CVD_Acq_Filtered_Data[index] >> shift);    \
00626         CVD_Acq_Filtered_Data[index] = 0;                                                               \
00627     } while(0)
00628 
00635 #define STORE_SINGLE_SENSOR_SCALE(index, shift)                                 \
00636     do {                                                                        \
00637         CVDSensorData[0] = (unsigned int)(CVD_Acq_Filtered_Data[0] >> shift);   \
00638         CVD_Acq_Filtered_Data[0] = 0;                                           \
00639     } while(0)
00640 
00650 #if (CVD_NUMBER_SENSORS > 1)
00651     #if (CVD_SCALING == 1)
00652         #define STORE_SENSOR(index)         STORE_SENSOR_SCALE(index, 0) 
00653         #define STORE_LAST_SENSOR(index)    STORE_LAST_SENSOR_SCALE(index, 0) 
00654     #elif (CVD_SCALING == 16)
00655         #define STORE_SENSOR(index)         STORE_SENSOR_SCALE(index, 4) 
00656         #define STORE_LAST_SENSOR(index)    STORE_LAST_SENSOR_SCALE(index, 4) 
00657     #elif (CVD_SCALING == 256)
00658         #define STORE_SENSOR(index)         STORE_SENSOR_SCALE(index, 8) 
00659         #define STORE_LAST_SENSOR(index)    STORE_LAST_SENSOR_SCALE(index, 8) 
00660     #else
00661         #warning CVD_SCALING set to an invalid value. Defaulting to 16:1 scaling.
00662         #define STORE_SENSOR(index)         STORE_SENSOR_SCALE(index, 4) 
00663         #define STORE_LAST_SENSOR(index)    STORE_LAST_SENSOR_SCALE(index, 4)
00664     #endif
00665 #else
00666     #if (CVD_SCALING == 1)
00667         #define STORE_SENSOR(index)         STORE_SINGLE_SENSOR_SCALE(index, 0) 
00668     #elif (CVD_SCALING == 16)
00669         #define STORE_SENSOR(index)         STORE_SINGLE_SENSOR_SCALE(index, 4) 
00670     #elif (CVD_SCALING == 256)
00671         #define STORE_SENSOR(index)         STORE_SINGLE_SENSOR_SCALE(index, 8) 
00672     #else
00673         #warning CVD_SCALING set to an invalid value. Defaulting to 16:1 scaling.
00674         #define STORE_SENSOR(index)         STORE_SENSOR_SCALE(index, 4) 
00675     #endif
00676 #endif
00677 
00684 #define EXIT_SENSOR(index)                                                                          \
00685 do {                                                                                                \
00686     index++;                                                                                        \
00687     asm("ljmp END_ISR");                            /* Exit the ISR                             */  \
00688 } while(0)
00689 
00713 #if (CVD_NUMBER_SENSORS > 1)
00714     #define EXIT_LAST_SENSOR(index)     EXIT_LAST_SENSOR_DECINDEX(index); EXIT_LAST_SENSOR_MAIN()       // First resets the index, then updates the sample counter
00715 #else
00716     #define EXIT_LAST_SENSOR(index)     EXIT_LAST_SENSOR_MAIN()                                         // Only one sensor, so only updates the sample counter
00717 #endif
00718 
00719 #define EXIT_LAST_SENSOR_MAIN()                                                                                                 \
00720 do {                                                                                                                            \
00721     if (--sample_counter != 0) {                          /* Decrement the sample counter and check if it's equal to 0      */  \
00722         asm("ljmp END_ISR");                              /* If not equal to 0, exit the ISR                                */  \
00723     }                                                                                                                           \
00724     sample_counter = CVD_SAMPLES_PER_SCAN;                /* If equal to 0, reset the sample counter continue with storage  */  \
00725 } while(0)
00726     
00727 #define EXIT_LAST_SENSOR_DECINDEX(index)    index = 0;
00728 
00736 #define SET_DATA_READY_FLAG()       \
00737     do {                            \
00738         mTouchCVD_dataReady = 1;    \
00739     } while(0)
00740 
00741 
00742 
00757 #if (CVD_NUMBER_SENSORS == 1)
00758 
00759     #define GENERATE_JUMP_TABLE()       \
00760         do {                            \
00761             asm("global   sensor_0");   \
00762             asm("ljmp     sensor_0");   \
00763         } while (0)
00764      
00765     #define GENERATE_STORAGE_FUNCTION()         STORE_SENSOR(0);   
00766     
00767 #else
00768 
00769     #define CVD_ASM_JUMP_LABEL_1()      case 1:     asm("ljmp sensor_1");
00770     #define CVD_ASM_JUMP_LABEL_2()      case 2:     asm("ljmp sensor_2");
00771     #define CVD_ASM_JUMP_LABEL_3()      case 3:     asm("ljmp sensor_3");
00772     #define CVD_ASM_JUMP_LABEL_4()      case 4:     asm("ljmp sensor_4");
00773     #define CVD_ASM_JUMP_LABEL_5()      case 5:     asm("ljmp sensor_5");
00774     #define CVD_ASM_JUMP_LABEL_6()      case 6:     asm("ljmp sensor_6");
00775     #define CVD_ASM_JUMP_LABEL_7()      case 7:     asm("ljmp sensor_7");
00776     #define CVD_ASM_JUMP_LABEL_8()      case 8:     asm("ljmp sensor_8");
00777     #define CVD_ASM_JUMP_LABEL_9()      case 9:     asm("ljmp sensor_9");
00778     #define CVD_ASM_JUMP_LABEL_10()     case 10:    asm("ljmp sensor_10");
00779     #define CVD_ASM_JUMP_LABEL_11()     case 11:    asm("ljmp sensor_11");
00780     #define CVD_ASM_JUMP_LABEL_12()     case 12:    asm("ljmp sensor_12");
00781     #define CVD_ASM_JUMP_LABEL_13()     case 13:    asm("ljmp sensor_13");
00782     #define CVD_ASM_JUMP_LABEL_14()     case 14:    asm("ljmp sensor_14");
00783     #define CVD_ASM_JUMP_LABEL_15()     case 15:    asm("ljmp sensor_15");
00784     #define CVD_ASM_JUMP_LABEL_16()     case 16:    asm("ljmp sensor_16");
00785     #define CVD_ASM_JUMP_LABEL_17()     case 17:    asm("ljmp sensor_17");
00786     #define CVD_ASM_JUMP_LABEL_18()     case 18:    asm("ljmp sensor_18");
00787     #define CVD_ASM_JUMP_LABEL_19()     case 19:    asm("ljmp sensor_19");
00788     #define CVD_ASM_JUMP_LABEL_20()     case 20:    asm("ljmp sensor_20");
00789     #define CVD_ASM_JUMP_LABEL_21()     case 21:    asm("ljmp sensor_21");
00790     #define CVD_ASM_JUMP_LABEL_22()     case 22:    asm("ljmp sensor_22");
00791     #define CVD_ASM_JUMP_LABEL_23()     case 23:    asm("ljmp sensor_23");
00792     #define CVD_ASM_JUMP_LABEL_24()     case 24:    asm("ljmp sensor_24");
00793     #define CVD_ASM_JUMP_LABEL_25()     case 25:    asm("ljmp sensor_25");
00794     #define CVD_ASM_JUMP_LABEL_26()     case 26:    asm("ljmp sensor_26");
00795     #define CVD_ASM_JUMP_LABEL_27()     case 27:    asm("ljmp sensor_27");
00796     #define CVD_ASM_JUMP_LABEL_28()     case 28:    asm("ljmp sensor_28");
00797     #define CVD_ASM_JUMP_LABEL_29()     case 29:    asm("ljmp sensor_29");
00798 
00799     #define CVD_STORE_LABEL_0()         STORE_LAST_SENSOR(0);
00800     #define CVD_STORE_LABEL_1()         STORE_SENSOR(1);
00801     #define CVD_STORE_LABEL_2()         STORE_SENSOR(2);
00802     #define CVD_STORE_LABEL_3()         STORE_SENSOR(3);
00803     #define CVD_STORE_LABEL_4()         STORE_SENSOR(4);
00804     #define CVD_STORE_LABEL_5()         STORE_SENSOR(5);
00805     #define CVD_STORE_LABEL_6()         STORE_SENSOR(6);
00806     #define CVD_STORE_LABEL_7()         STORE_SENSOR(7);
00807     #define CVD_STORE_LABEL_8()         STORE_SENSOR(8);
00808     #define CVD_STORE_LABEL_9()         STORE_SENSOR(9);
00809     #define CVD_STORE_LABEL_10()        STORE_SENSOR(10);
00810     #define CVD_STORE_LABEL_11()        STORE_SENSOR(11);
00811     #define CVD_STORE_LABEL_12()        STORE_SENSOR(12);
00812     #define CVD_STORE_LABEL_13()        STORE_SENSOR(13);
00813     #define CVD_STORE_LABEL_14()        STORE_SENSOR(14);
00814     #define CVD_STORE_LABEL_15()        STORE_SENSOR(15);
00815     #define CVD_STORE_LABEL_16()        STORE_SENSOR(16);
00816     #define CVD_STORE_LABEL_17()        STORE_SENSOR(17);
00817     #define CVD_STORE_LABEL_18()        STORE_SENSOR(18);
00818     #define CVD_STORE_LABEL_19()        STORE_SENSOR(19);
00819     #define CVD_STORE_LABEL_20()        STORE_SENSOR(20);
00820     #define CVD_STORE_LABEL_21()        STORE_SENSOR(21);
00821     #define CVD_STORE_LABEL_22()        STORE_SENSOR(22);
00822     #define CVD_STORE_LABEL_23()        STORE_SENSOR(23);
00823     #define CVD_STORE_LABEL_24()        STORE_SENSOR(24);
00824     #define CVD_STORE_LABEL_25()        STORE_SENSOR(25);
00825     #define CVD_STORE_LABEL_26()        STORE_SENSOR(26);
00826     #define CVD_STORE_LABEL_27()        STORE_SENSOR(27);
00827     #define CVD_STORE_LABEL_28()        STORE_SENSOR(28);
00828     #define CVD_STORE_LABEL_29()        STORE_SENSOR(29);
00829 
00830     #if (CVD_NUMBER_SENSORS > 30)
00831         #error This version of the framework macro library unable to support more than 30 sensors at this time.
00832     #endif
00833     
00834     #if CVD_NUMBER_SENSORS < 30
00835         #undef  CVD_ASM_JUMP_LABEL_29()
00836         #define CVD_ASM_JUMP_LABEL_29()
00837         #undef  CVD_STORE_LABEL_29()
00838         #define CVD_STORE_LABEL_29()
00839     #endif
00840     #if CVD_NUMBER_SENSORS < 29
00841         #undef  CVD_ASM_JUMP_LABEL_28()
00842         #define CVD_ASM_JUMP_LABEL_28()
00843         #undef  CVD_STORE_LABEL_28()
00844         #define CVD_STORE_LABEL_28()
00845     #endif
00846     #if CVD_NUMBER_SENSORS < 28
00847         #undef  CVD_ASM_JUMP_LABEL_27()
00848         #define CVD_ASM_JUMP_LABEL_27()
00849         #undef  CVD_STORE_LABEL_27()
00850         #define CVD_STORE_LABEL_27()
00851     #endif
00852     #if CVD_NUMBER_SENSORS < 27
00853         #undef  CVD_ASM_JUMP_LABEL_26()
00854         #define CVD_ASM_JUMP_LABEL_26()
00855         #undef  CVD_STORE_LABEL_26()
00856         #define CVD_STORE_LABEL_26()
00857     #endif
00858     #if CVD_NUMBER_SENSORS < 26
00859         #undef  CVD_ASM_JUMP_LABEL_25()
00860         #define CVD_ASM_JUMP_LABEL_25()
00861         #undef  CVD_STORE_LABEL_25()
00862         #define CVD_STORE_LABEL_25()
00863     #endif
00864     #if CVD_NUMBER_SENSORS < 25 
00865         #undef  CVD_ASM_JUMP_LABEL_24()
00866         #define CVD_ASM_JUMP_LABEL_24()
00867         #undef  CVD_STORE_LABEL_24()
00868         #define CVD_STORE_LABEL_24()
00869     #endif
00870     #if CVD_NUMBER_SENSORS < 24
00871         #undef  CVD_ASM_JUMP_LABEL_23()
00872         #define CVD_ASM_JUMP_LABEL_23()
00873         #undef  CVD_STORE_LABEL_23()
00874         #define CVD_STORE_LABEL_23()
00875     #endif
00876     #if CVD_NUMBER_SENSORS < 23
00877         #undef  CVD_ASM_JUMP_LABEL_22()
00878         #define CVD_ASM_JUMP_LABEL_22()
00879         #undef  CVD_STORE_LABEL_22()
00880         #define CVD_STORE_LABEL_22()
00881     #endif
00882     #if CVD_NUMBER_SENSORS < 22
00883         #undef  CVD_ASM_JUMP_LABEL_21()
00884         #define CVD_ASM_JUMP_LABEL_21()
00885         #undef  CVD_STORE_LABEL_21()
00886         #define CVD_STORE_LABEL_21()
00887     #endif
00888     #if CVD_NUMBER_SENSORS < 21
00889         #undef  CVD_ASM_JUMP_LABEL_20()
00890         #define CVD_ASM_JUMP_LABEL_20()
00891         #undef  CVD_STORE_LABEL_20()
00892         #define CVD_STORE_LABEL_20()
00893     #endif
00894     #if CVD_NUMBER_SENSORS < 20
00895         #undef  CVD_ASM_JUMP_LABEL_19()
00896         #define CVD_ASM_JUMP_LABEL_19()
00897         #undef  CVD_STORE_LABEL_19()
00898         #define CVD_STORE_LABEL_19()
00899     #endif
00900     #if CVD_NUMBER_SENSORS < 19
00901         #undef  CVD_ASM_JUMP_LABEL_18()
00902         #define CVD_ASM_JUMP_LABEL_18()
00903         #undef  CVD_STORE_LABEL_18()
00904         #define CVD_STORE_LABEL_18()
00905     #endif
00906     #if CVD_NUMBER_SENSORS < 18
00907         #undef  CVD_ASM_JUMP_LABEL_17()
00908         #define CVD_ASM_JUMP_LABEL_17()
00909         #undef  CVD_STORE_LABEL_17()
00910         #define CVD_STORE_LABEL_17()
00911     #endif
00912     #if CVD_NUMBER_SENSORS < 17
00913         #undef  CVD_ASM_JUMP_LABEL_16()
00914         #define CVD_ASM_JUMP_LABEL_16()
00915         #undef  CVD_STORE_LABEL_16()
00916         #define CVD_STORE_LABEL_16()
00917     #endif
00918     #if CVD_NUMBER_SENSORS < 16
00919         #undef  CVD_ASM_JUMP_LABEL_15()
00920         #define CVD_ASM_JUMP_LABEL_15()
00921         #undef  CVD_STORE_LABEL_15()
00922         #define CVD_STORE_LABEL_15()
00923     #endif
00924     #if CVD_NUMBER_SENSORS < 15
00925         #undef  CVD_ASM_JUMP_LABEL_14()
00926         #define CVD_ASM_JUMP_LABEL_14()
00927         #undef  CVD_STORE_LABEL_14()
00928         #define CVD_STORE_LABEL_14()
00929     #endif
00930     #if CVD_NUMBER_SENSORS < 14
00931         #undef  CVD_ASM_JUMP_LABEL_13()
00932         #define CVD_ASM_JUMP_LABEL_13()
00933         #undef  CVD_STORE_LABEL_13()
00934         #define CVD_STORE_LABEL_13()
00935     #endif
00936     #if CVD_NUMBER_SENSORS < 13
00937         #undef  CVD_ASM_JUMP_LABEL_12()
00938         #define CVD_ASM_JUMP_LABEL_12()
00939         #undef  CVD_STORE_LABEL_12()
00940         #define CVD_STORE_LABEL_12()
00941     #endif
00942     #if CVD_NUMBER_SENSORS < 12
00943         #undef  CVD_ASM_JUMP_LABEL_11()
00944         #define CVD_ASM_JUMP_LABEL_11()
00945         #undef  CVD_STORE_LABEL_11()
00946         #define CVD_STORE_LABEL_11()
00947     #endif
00948     #if CVD_NUMBER_SENSORS < 11
00949         #undef  CVD_ASM_JUMP_LABEL_10()
00950         #define CVD_ASM_JUMP_LABEL_10()
00951         #undef  CVD_STORE_LABEL_10()
00952         #define CVD_STORE_LABEL_10()
00953     #endif
00954     #if CVD_NUMBER_SENSORS < 10
00955         #undef  CVD_ASM_JUMP_LABEL_9()
00956         #define CVD_ASM_JUMP_LABEL_9()
00957         #undef  CVD_STORE_LABEL_9()
00958         #define CVD_STORE_LABEL_9()
00959     #endif
00960     #if CVD_NUMBER_SENSORS < 9
00961         #undef  CVD_ASM_JUMP_LABEL_8()
00962         #define CVD_ASM_JUMP_LABEL_8()
00963         #undef  CVD_STORE_LABEL_8()
00964         #define CVD_STORE_LABEL_8()
00965     #endif
00966     #if CVD_NUMBER_SENSORS < 8
00967         #undef  CVD_ASM_JUMP_LABEL_7()
00968         #define CVD_ASM_JUMP_LABEL_7()
00969         #undef  CVD_STORE_LABEL_7()
00970         #define CVD_STORE_LABEL_7()
00971     #endif
00972     #if CVD_NUMBER_SENSORS < 7
00973         #undef  CVD_ASM_JUMP_LABEL_6()
00974         #define CVD_ASM_JUMP_LABEL_6()
00975         #undef  CVD_STORE_LABEL_6()
00976         #define CVD_STORE_LABEL_6()
00977     #endif
00978     #if CVD_NUMBER_SENSORS < 6
00979         #undef  CVD_ASM_JUMP_LABEL_5()
00980         #define CVD_ASM_JUMP_LABEL_5()
00981         #undef  CVD_STORE_LABEL_5()
00982         #define CVD_STORE_LABEL_5()
00983     #endif
00984     #if CVD_NUMBER_SENSORS < 5
00985         #undef  CVD_ASM_JUMP_LABEL_4()
00986         #define CVD_ASM_JUMP_LABEL_4()
00987         #undef  CVD_STORE_LABEL_4()
00988         #define CVD_STORE_LABEL_4()
00989     #endif
00990     #if CVD_NUMBER_SENSORS < 4
00991         #undef  CVD_ASM_JUMP_LABEL_3()
00992         #define CVD_ASM_JUMP_LABEL_3()
00993         #undef  CVD_STORE_LABEL_3()
00994         #define CVD_STORE_LABEL_3()
00995     #endif
00996     #if CVD_NUMBER_SENSORS < 3
00997         #undef  CVD_ASM_JUMP_LABEL_2()
00998         #define CVD_ASM_JUMP_LABEL_2()
00999         #undef  CVD_STORE_LABEL_2()
01000         #define CVD_STORE_LABEL_2()
01001     #endif
01002     #if CVD_NUMBER_SENSORS < 2
01003         #undef  CVD_ASM_JUMP_LABEL_1()
01004         #define CVD_ASM_JUMP_LABEL_1()
01005         #undef  CVD_STORE_LABEL_1()
01006         #define CVD_STORE_LABEL_1()
01007     #endif
01008 
01009     #define GENERATE_JUMP_TABLE()               \
01010         do {                                    \
01011             asm("global      sensor_0,"         \
01012                             "sensor_1,"         \
01013                             "sensor_2,"         \
01014                             "sensor_3,"         \
01015                             "sensor_4,"         \
01016                             "sensor_5,"         \
01017                             "sensor_6,"         \
01018                             "sensor_7,"         \
01019                             "sensor_8,"         \
01020                             "sensor_9,"         \
01021                             "sensor_10,"        \
01022                             "sensor_11,"        \
01023                             "sensor_12,"        \
01024                             "sensor_13,"        \
01025                             "sensor_14,"        \
01026                             "sensor_15,"        \
01027                             "sensor_16,"        \
01028                             "sensor_17,"        \
01029                             "sensor_18,"        \
01030                             "sensor_19,"        \
01031                             "sensor_20,"        \
01032                             "sensor_21,"        \
01033                             "sensor_22,"        \
01034                             "sensor_23,"        \
01035                             "sensor_24,"        \
01036                             "sensor_25,"        \
01037                             "sensor_26,"        \
01038                             "sensor_27,"        \
01039                             "sensor_28,"        \
01040                             "sensor_29 ");      \
01041             switch (current_sensor)             \
01042             {                                   \
01043                 case 0: asm("ljmp sensor_0");   \
01044                 CVD_ASM_JUMP_LABEL_1();         \
01045                 CVD_ASM_JUMP_LABEL_2();         \
01046                 CVD_ASM_JUMP_LABEL_3();         \
01047                 CVD_ASM_JUMP_LABEL_4();         \
01048                 CVD_ASM_JUMP_LABEL_5();         \
01049                 CVD_ASM_JUMP_LABEL_6();         \
01050                 CVD_ASM_JUMP_LABEL_7();         \
01051                 CVD_ASM_JUMP_LABEL_8();         \
01052                 CVD_ASM_JUMP_LABEL_9();         \
01053                 CVD_ASM_JUMP_LABEL_10();        \
01054                 CVD_ASM_JUMP_LABEL_11();        \
01055                 CVD_ASM_JUMP_LABEL_12();        \
01056                 CVD_ASM_JUMP_LABEL_13();        \
01057                 CVD_ASM_JUMP_LABEL_14();        \
01058                 CVD_ASM_JUMP_LABEL_15();        \
01059                 CVD_ASM_JUMP_LABEL_16();        \
01060                 CVD_ASM_JUMP_LABEL_17();        \
01061                 CVD_ASM_JUMP_LABEL_18();        \
01062                 CVD_ASM_JUMP_LABEL_19();        \
01063                 CVD_ASM_JUMP_LABEL_20();        \
01064                 CVD_ASM_JUMP_LABEL_21();        \
01065                 CVD_ASM_JUMP_LABEL_22();        \
01066                 CVD_ASM_JUMP_LABEL_23();        \
01067                 CVD_ASM_JUMP_LABEL_24();        \
01068                 CVD_ASM_JUMP_LABEL_25();        \
01069                 CVD_ASM_JUMP_LABEL_26();        \
01070                 CVD_ASM_JUMP_LABEL_27();        \
01071                 CVD_ASM_JUMP_LABEL_28();        \
01072                 CVD_ASM_JUMP_LABEL_29();        \
01073                 default: break;                 \
01074             }                                   \
01075         } while (0)
01076 
01077 
01078     #define GENERATE_STORAGE_FUNCTION()         \
01079         do {                                    \
01080             CVD_STORE_LABEL_0();                \
01081             CVD_STORE_LABEL_1();                \
01082             CVD_STORE_LABEL_2();                \
01083             CVD_STORE_LABEL_3();                \
01084             CVD_STORE_LABEL_4();                \
01085             CVD_STORE_LABEL_5();                \
01086             CVD_STORE_LABEL_6();                \
01087             CVD_STORE_LABEL_7();                \
01088             CVD_STORE_LABEL_8();                \
01089             CVD_STORE_LABEL_9();                \
01090             CVD_STORE_LABEL_10();               \
01091             CVD_STORE_LABEL_11();               \
01092             CVD_STORE_LABEL_12();               \
01093             CVD_STORE_LABEL_13();               \
01094             CVD_STORE_LABEL_14();               \
01095             CVD_STORE_LABEL_15();               \
01096             CVD_STORE_LABEL_16();               \
01097             CVD_STORE_LABEL_17();               \
01098             CVD_STORE_LABEL_18();               \
01099             CVD_STORE_LABEL_19();               \
01100             CVD_STORE_LABEL_20();               \
01101             CVD_STORE_LABEL_21();               \
01102             CVD_STORE_LABEL_22();               \
01103             CVD_STORE_LABEL_23();               \
01104             CVD_STORE_LABEL_24();               \
01105             CVD_STORE_LABEL_25();               \
01106             CVD_STORE_LABEL_26();               \
01107             CVD_STORE_LABEL_27();               \
01108             CVD_STORE_LABEL_28();               \
01109             CVD_STORE_LABEL_29();               \
01110         } while (0)
01111 #endif
01112 
01113 #endif
01114 
01115 
01116 
01117 

mTouch CVD Framework v1.1 documentation by  Click here to visit our website at www.microchip.com