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

mTouchCVD_macroLibrary_PIC18F.h

Go to the documentation of this file.
00001 /*************************************************************************
00002  *  © 2012 Microchip Technology Inc.                                       
00003  *  
00004  *  Project Name:    mTouch Framework v2.1
00005  *  FileName:        mTouchCVD_macroLibrary_PIC18F.h
00006  *  Dependencies:    mTouch.h
00007  *                   mTouch_macroLibrary_common.h
00008  *  Processor:       See documentation for supported PIC® microcontrollers 
00009  *  Compiler:        HI-TECH Ver. 9.81 or later
00010  *  IDE:             MPLAB® IDE v8.50 (or later) or MPLAB® X                        
00011  *  Hardware:         
00012  *  Company:         
00013  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00014  *  Description:     mTouch Framework PIC18F Macro Library Header
00015  *                   - Editting this file will make customer support for
00016  *                     your application extremely difficult. Be careful,
00017  *                     as it can also have a negative impact on your
00018  *                     system's noise susceptibility.
00019  *************************************************************************/
00020  /***********************************************************************
00021  * MICROCHIP SOFTWARE NOTICE AND DISCLAIMER: You may use this software, and 
00022  * any derivatives created by any person or entity by or on your behalf, 
00023  * exclusively with Microchip's products in accordance with applicable
00024  * software license terms and conditions, a copy of which is provided for
00025  * your referencein accompanying documentation. Microchip and its licensors 
00026  * retain all ownership and intellectual property rights in the 
00027  * accompanying software and in all derivatives hereto. 
00028  * 
00029  * This software and any accompanying information is for suggestion only. 
00030  * It does not modify Microchip's standard warranty for its products. You 
00031  * agree that you are solely responsible for testing the software and 
00032  * determining its suitability. Microchip has no obligation to modify, 
00033  * test, certify, or support the software. 
00034  * 
00035  * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
00036  * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED 
00037  * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A 
00038  * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION WITH 
00039  * MICROCHIP'S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY 
00040  * APPLICATION. 
00041  * 
00042  * IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, 
00043  * TORT (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT 
00044  * LIABILITY, INDEMNITY, CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, 
00045  * SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, 
00046  * FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, 
00047  * HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY 
00048  * OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWABLE BY LAW, 
00049  * MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS 
00050  * SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID 
00051  * DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. 
00052  * 
00053  * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF 
00054  * THESE TERMS. 
00055  *************************************************************************/
00064 #ifndef __MTOUCHCVD_MACROLIBRARY_H
00065 #define __MTOUCHCVD_MACROLIBRARY_H
00066 
00067 #define ljmp    goto
00068 
00069 #include "mTouch_macroLibrary_common.h"
00070 
00071 #undef  SAVE_STATE
00072 #if defined(HI_TECH_C)
00073     #define SAVE_STATE()                        \
00074         do {                                    \
00075             asm("movwf  _int_w");               \
00076             asm("movff  STATUS, _int_status");  \
00077             asm("movff  BSR, _int_bsr");        \
00078         } while (0)
00079 #else
00080     #define SAVE_STATE()                        \
00081         do {                                    \
00082             _asm    movwf  int_w                \
00083                     movff  STATUS, int_status   \
00084                     movff  BSR, int_bsr         \
00085             _endasm                             \
00086         } while (0)
00087 #endif
00088 
00089 #undef  RESTORE_STATE
00090 #if defined(HI_TECH_C)
00091     #define RESTORE_STATE()                     \
00092         do {                                    \
00093             asm("movff  _int_bsr, BSR");        \
00094             asm("movf   _int_w, W");            \
00095             asm("movff  _int_status, STATUS");  \
00096         } while (0)
00097 #else
00098     #define RESTORE_STATE()                     \
00099         do {                                    \
00100             _asm    movff  int_bsr, BSR         \
00101                     movf   int_w, WREG          \
00102                     movff  int_status, STATUS   \
00103             _endasm                             \
00104         } while (0)
00105 #endif
00106 #undef  MTOUCH_SLEEP_STABILIZE_OSC
00107 #define MTOUCH_SLEEP_STABILIZE_OSC()
00108 
00109 #undef  JITTER_START_TIME
00110 #undef  JITTER_MAIN_LOOP
00111 #if defined(MTOUCH_JITTER_ENABLE) 
00112     #define JITTER_START_TIME()                                         \
00113         do {                                                            \
00114             if (mTouch_jitter & 0x01) {                                 \
00115                 mTouch_jitter = (uint8_t)(mTouch_jitter >> 1) ^ 0xB4;   \
00116             } else {                                                    \
00117                 mTouch_jitter = (uint8_t)(mTouch_jitter >> 1);          \
00118             }                                                           \
00119             MTOUCH_ISR_TMR_C = mTouch_jitter & MTOUCH_JITTER_MASK;      \
00120         } while(0)
00121         
00122     #define JITTER_MAIN_LOOP()                                                  \
00123         do {                                                                    \
00124             if (mTouch_jitter & 0x01) {                                         \
00125                 mTouch_jitter = (uint8_t)(mTouch_jitter >> 1) ^ 0xB4;           \
00126             } else {                                                            \
00127                 mTouch_jitter = (uint8_t)(mTouch_jitter >> 1);                  \
00128             }                                                                   \
00129             for (uint8_t i = (mTouch_jitter & MTOUCH_JITTER_MASK); i > 0; i--); \
00130         } while(0)
00131 
00132 #else           
00133     #define JITTER_START_TIME()     MTOUCH_ISR_TMR_C = 0
00134     #define JITTER_MAIN_LOOP()      
00135 #endif
00136 
00137 #undef  CHECK_AND_CLEAR_TMRxIF
00138 #define CHECK_AND_CLEAR_TMRxIF()        \
00139 do {                                    \
00140     if (MTOUCH_ISR_TMRxIF == 0)         \
00141     {                                   \
00142         asm("ljmp END_MTOUCH_SCAN");    \
00143     } else {                            \
00144         MTOUCH_ISR_TMRxIF = 0;          \
00145     }                                   \
00146 } while (0)
00147 
00148 
00149 
00150 #define CVD_RS_INIT_A(indexRef)                 MTOUCH_LAT_C_SENSOR(indexRef) |=   (uint8_t)(1 << MTOUCH_PIN_SENSOR(indexRef))
00151 #define CVD_RS_INIT_B(indexRef)                 MTOUCH_LAT_C_SENSOR(indexRef) &= ~ (uint8_t)(1 << MTOUCH_PIN_SENSOR(indexRef))
00152 
00153 #define CVD_RS_MUXSELECT(index, indexRef)       ADCON0 = MTOUCH_SELECT_SENSOR(indexRef);       \
00154                                                 ADCON0bits.DONE = 1;                  
00155 
00156 #define CVD_RS_PREPARE(index)                   
00157 
00158 // NOTE: Previously a NOP delay(11) after ADON
00159 #define CVD_RS_CONNECT_A(index)                 ADCON0bits.ADON = 0;                                                            /*  Stop sampling to avoid completion   */  \
00160                                                 ADCON0bits.ADON = 1;                                                            /*  Start again to finish charging      */  \
00161                                                 MTOUCH_TRIS_C_SENSOR(index)   |=  ((uint8_t)(1 << MTOUCH_PIN_SENSOR(index)));   /*  Set sensor to input                 */  \
00162                                                 ADCON0 = MTOUCH_SELECT_SENSOR(index);                                           /*  ADC Mux --> Sensor                  */
00163                                                 
00164 #define CVD_RS_CONNECT_B(index)                 CVD_RS_CONNECT_A(index)
00165 
00166 #define CVD_RS_SET_GODONE()                     ADCON0bits.DONE = 1;                                                            /*  Start conversion.                   */
00167 
00168 #define CVD_RS_EXIT_A(index)                    MTOUCH_LAT_C_SENSOR(index)    |=  ((uint8_t)(1 << MTOUCH_PIN_SENSOR(index)));   /*  Set sensor LAT high                 */  \
00169                                                 MTOUCH_TRIS_C_SENSOR(index)   &= ~((uint8_t)(1 << MTOUCH_PIN_SENSOR(index)));   /*  Set sensor TRIS as output           */ 
00170 
00171 #define CVD_RS_EXIT_B(index)                    MTOUCH_LAT_C_SENSOR(index)    &= ~((uint8_t)(1 << MTOUCH_PIN_SENSOR(index)));   /*  Set sensor LAT low                  */  \
00172                                                 MTOUCH_TRIS_C_SENSOR(index)   &= ~((uint8_t)(1 << MTOUCH_PIN_SENSOR(index)));   /*  Set sensor TRIS as output           */
00173 
00174            
00175 
00176 // MUTUAL SENSOR
00177 #if defined(CVD_MUTUAL_ENABLED)
00178     #define CVD_RS_MUTUAL_A(index)                                  CVD_MUTUAL_LAT = 0
00179     #define CVD_RS_MUTUAL_B(index)                                  CVD_MUTUAL_LAT = 1
00180 #elif defined(CVD_MUTUAL_EXCLUSIVE_ENABLED)
00181     #define CVD_RS_MUTUAL_A(index)                                  CVD_MUTUAL_LAT = 1
00182     #define CVD_RS_MUTUAL_B(index)                                  CVD_MUTUAL_LAT = 0
00183 #else
00184     #define CVD_RS_MUTUAL_A(index)                               
00185     #define CVD_RS_MUTUAL_B(index)                         
00186 #endif
00187 
00188 
00189 // ACTIVE SCANNING - ENTER, and REFERENCE
00190 // #if defined(CVD_MUTUAL_EXCLUSIVE_ENABLED)
00191     // #define CVD_RS_INIT_A(ref_port, ref_pin)                        
00192     // #define CVD_RS_INIT_B(ref_port, ref_pin)                        
00193     // #define CVD_RS_MUXSELECT(current_channel, ref_channel)          
00194 // #else
00195     // #if defined(CVD_FORCE_REF_DAC) || (MTOUCH_NUMBER_SENSORS == 1)
00196         // #define CVD_RS_INIT_A(ref_port, ref_pin)                    
00197         // #define CVD_RS_INIT_B(ref_port, ref_pin)                    
00198         // #define CVD_RS_MUXSELECT(current_channel, ref_channel)      
00199     // #else
00200         // #define CVD_RS_INIT_A(ref_port, ref_pin)                     
00201         // #define CVD_RS_INIT_B(ref_port, ref_pin)                    
00202         // #define CVD_RS_MUXSELECT(current_channel, ref_channel)      
00203     // #endif
00204 // #endif
00205 
00206 // ACTIVE SCANNING - CONNECTION, CONVERSION, and EXIT
00207 // #if defined(CVD_MUTUAL_EXCLUSIVE_ENABLED)
00208     // #define CVD_RS_PREPARE(port)                                    
00209     // #define CVD_RS_CONNECT_A(current_channel, pin)                  
00210     // #define CVD_RS_CONNECT_B(current_channel, pin)                  
00211     // #define CVD_RS_EXIT_A(port, pin, ref_port, ref_pin)             
00212     // #define CVD_RS_EXIT_B(port, pin, ref_port, ref_pin)             
00213 // #elif defined(CVD_GUARD_DACOUT_ENABLED)
00214     // #define CVD_RS_PREPARE(port)                                    
00215     // #define CVD_RS_CONNECT_A(current_channel, pin)                  
00216     // #define CVD_RS_CONNECT_B(current_channel, pin)                  
00217     // #define CVD_RS_EXIT_A(port, pin, ref_port, ref_pin)             
00218     // #define CVD_RS_EXIT_B(port, pin, ref_port, ref_pin)             
00219 // #elif defined(CVD_GUARD_IO_ENABLED)   
00220     // #define CVD_RS_PREPARE(port)                                    
00221     // #define CVD_RS_CONNECT_A(current_channel, pin)                  
00222     // #define CVD_RS_CONNECT_B(current_channel, pin)                  
00223     // #define CVD_RS_EXIT_A(port, pin, ref_port, ref_pin)             
00224     // #define CVD_RS_EXIT_B(port, pin, ref_port, ref_pin)             
00225 // #else
00226     // #define CVD_RS_PREPARE(port)                                    
00227     // #define CVD_RS_CONNECT_A(current_channel, pin)                  
00228     // #define CVD_RS_CONNECT_B(current_channel, pin)                  
00229     // #define CVD_RS_EXIT_A(port, pin, ref_port, ref_pin)             
00230     // #define CVD_RS_EXIT_B(port, pin, ref_port, ref_pin)             
00231 // #endif
00232 
00233 
00234 #undef  MTOUCH_READ_SENSOR
00235 #define MTOUCH_READ_SENSOR(indexSensor, indexRef)           CVD_READ_SENSOR(indexSensor,indexRef)
00236 
00237 
00238 // #define CVD_READ_SENSOR(index, indexRef)                                                                                            \
00239     // do {                                                                                                                            \
00240         // CVD_RS_MUTUAL_A();                                                              /*  Set up mutual sensor, if enabled    */  \
00241         // CVD_RS_START_CRITICAL();                                                        /*  Start critical code segment         */  \
00242         // MTOUCH_LAT_C_SENSOR(indexRef) |=   (uint8_t)(1 << MTOUCH_PIN_SENSOR(indexRef));                                             \
00243         // ADCON0 = MTOUCH_SELECT_SENSOR(indexRef);                                        /*  ADC Mux --> Reference               */  \
00244         // ADCON0bits.DONE = 1;                                                            /*  Start sampling to connect CHOLD     */  \
00245         // _NOP_DELAY(18);                                                                 /*  Fixed delay while CHOLD charges     */  \
00246         // ADCON0bits.ADON = 0;                                                            /*  Stop sampling to avoid completion   */  \
00247         // ADCON0bits.ADON = 1;                                                            /*  Start again to finish charging      */  \
00248         // _NOP_DELAY(11);                                                                 /*  Fixed delay while CHOLD charges     */  \
00249         // MTOUCH_TRIS_C_SENSOR(index)   |=  ((uint8_t)(1 << MTOUCH_PIN_SENSOR(index)));   /*  Set sensor to input                 */  \
00250         // ADCON0 = MTOUCH_SELECT_SENSOR(index);                                           /*  ADC Mux --> Sensor                  */  \
00251         // ADCON0bits.DONE = 1;                                                            /*  Start conversion.                   */  \
00252         // CVD_RS_POSTA_MATH();                                                            /*  Perform math while Scan A completes */  \
00253         // while(ADCON0bits.DONE);                                                         /*  Make sure conversion is finished    */  \
00254         // MTOUCH_LAT_C_SENSOR(index)    |=  ((uint8_t)(1 << MTOUCH_PIN_SENSOR(index)));   /*  Set sensor LAT high                 */  \
00255         // MTOUCH_TRIS_C_SENSOR(index)   &= ~((uint8_t)(1 << MTOUCH_PIN_SENSOR(index)));   /*  Set sensor TRIS as output           */  \
00256         // MTOUCH_STORE_SCAN_A();                                                          /*  Store the result of the ADC scan    */  \
00257         // CVD_RS_MUTUAL_B();                                                              /*  Set up mutual sensor, if enabled    */  \
00258         // ADCON0 = MTOUCH_SELECT_SENSOR(indexRef);                                        /*  ADC Mux --> Reference               */  \
00259         // MTOUCH_LAT_C_SENSOR(indexRef) &= ~ (uint8_t)(1 << MTOUCH_PIN_SENSOR(indexRef)); /*  Output low on reference             */  \
00260         // ADCON0bits.DONE = 1;                                                            /*  Start sampling to connect CHOLD     */  \
00261         // _NOP_DELAY(18);                                                                 /*  Fixed delay while CHOLD charges     */  \
00262         // ADCON0bits.ADON = 0;                                                            /*  Stop sampling to avoid completion   */  \
00263         // ADCON0bits.ADON = 1;                                                            /*  Start again to finish charging      */  \
00264         // _NOP_DELAY(11);                                                                 /*  Fixed delay while CHOLD charges     */  \
00265         // MTOUCH_TRIS_C_SENSOR(index)   |=  ((uint8_t)(1 << MTOUCH_PIN_SENSOR(index)));   /*  Set sensor to input                 */  \
00266         // ADCON0 = MTOUCH_SELECT_SENSOR(index);                                           /*  ADC Mux --> Sensor                  */  \
00267         // ADCON0bits.DONE = 1;                                                            /*  Start conversion.                   */  \
00268         // while(ADCON0bits.DONE);                                                         /*  Make sure conversion is finished    */  \
00269         // MTOUCH_LAT_C_SENSOR(index)    &= ~((uint8_t)(1 << MTOUCH_PIN_SENSOR(index)));   /*  Set sensor LAT low                  */  \
00270         // MTOUCH_TRIS_C_SENSOR(index)   &= ~((uint8_t)(1 << MTOUCH_PIN_SENSOR(index)));   /*  Set sensor TRIS as output           */  \
00271         // CVD_RS_END_CRITICAL(index);                                                     /*  End critical code segment           */  \
00272     // } while(0)
00273     
00274 #endif
00275 
00276 
00277 
00278 

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