00001 /************************************************************************* 00002 * © 2011 Microchip Technology Inc. 00003 * 00004 * Project Name: mTouch CVD Framework v1.1 00005 * FileName: main_example.c 00006 * Dependencies: mTouchCVD.h 00007 * Processor: 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: Main routine 00014 * - Example implementation of the framework's API calls 00015 * - All application code should be implemented in this 00016 * or some other user-created file. This will allow 00017 * for better customer support and easier upgrades to 00018 * later firmware versions. 00019 * - See the documentation located in the docs/ folder 00020 * for a detailed guide on getting started with your 00021 * application and the mTouch framework. 00022 *************************************************************************/ 00023 /************************************************************************* 00024 * MICROCHIP SOFTWARE NOTICE AND DISCLAIMER: You may use this software, and 00025 * any derivatives created by any person or entity by or on your behalf, 00026 * exclusively with Microchip's products in accordance with applicable 00027 * software license terms and conditions, a copy of which is provided for 00028 * your referencein accompanying documentation. Microchip and its licensors 00029 * retain all ownership and intellectual property rights in the 00030 * accompanying software and in all derivatives hereto. 00031 * 00032 * This software and any accompanying information is for suggestion only. 00033 * It does not modify Microchip's standard warranty for its products. You 00034 * agree that you are solely responsible for testing the software and 00035 * determining its suitability. Microchip has no obligation to modify, 00036 * test, certify, or support the software. 00037 * 00038 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 00039 * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED 00040 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A 00041 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE, ITS INTERACTION WITH 00042 * MICROCHIP'S PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY 00043 * APPLICATION. 00044 * 00045 * IN NO EVENT, WILL MICROCHIP BE LIABLE, WHETHER IN CONTRACT, WARRANTY, 00046 * TORT (INCLUDING NEGLIGENCE OR BREACH OF STATUTORY DUTY), STRICT 00047 * LIABILITY, INDEMNITY, CONTRIBUTION, OR OTHERWISE, FOR ANY INDIRECT, 00048 * SPECIAL, PUNITIVE, EXEMPLARY, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, 00049 * FOR COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, 00050 * HOWSOEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY 00051 * OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWABLE BY LAW, 00052 * MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS 00053 * SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID 00054 * DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. 00055 * 00056 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF 00057 * THESE TERMS. 00058 *************************************************************************/ 00059 00063 00064 00065 #include "includes/mTouchCVD.h" // Required Include 00066 00067 // CONFIGURATION SETTINGS 00068 // Note - These are example configurations only. 00069 #if defined(_16F193x) 00070 #ifdef __DEBUG 00071 __CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF); 00072 __CONFIG(WRT_OFF & PLLEN_ON & STVREN_OFF & BORV_25 & LVP_OFF); 00073 #else 00074 __CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF); 00075 __CONFIG(WRT_OFF & PLLEN_ON & STVREN_OFF & BORV_25 & LVP_OFF); 00076 #endif 00077 #elif defined(_16F1823) 00078 __CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_OFF & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF); 00079 __CONFIG(WRT_OFF & PLLEN_ON & STVREN_OFF & BORV_25 & LVP_OFF); 00080 #elif defined(_16F182x) 00081 __CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF); 00082 __CONFIG(WRT_OFF & PLLEN_ON & STVREN_OFF & BORV_25 & LVP_OFF); 00083 #elif defined(_16F152x) 00084 __CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF); 00085 __CONFIG(WRT_OFF & VCAPEN_OFF & STVREN_OFF & BORV_25 & ULPBOR_OFF & LVP_OFF); 00086 #elif defined(_16F194x) 00087 __CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_ON & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF); 00088 __CONFIG(WRT_OFF & VCAPEN_OFF & PLLEN_ON & STVREN_OFF & BORV_25 & LVP_OFF); 00089 #elif defined(_12F617) 00090 __CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & IOSCFS_8MHZ & BOREN_OFF & WRT_OFF); 00091 #elif defined(_12F615) || defined(_12HV615) 00092 __CONFIG(FOSC_INTOSCIO & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & IOSCFS_8MHZ & BOREN_OFF); 00093 #endif 00094 00095 // PROTOTYPES 00096 void Example_System_Init(void); 00097 00098 void main(void) 00099 { 00100 00101 Example_System_Init(); // Your System Initialization Function 00102 00103 mTouchCVD_Init(); // mTouch Initialization 00104 00105 00106 //---------------------------- 00107 // Example mTouch API Usage 00108 //---------------------------- 00109 while(1) 00110 { 00111 00112 if (mTouchCVD_isDataReady()) // Is new information ready? 00113 { 00114 mTouchCVD_Service(); // Decode the newly captured data and transmit new data updates. 00115 00116 //---------------------------- 00117 // Example LED Handling Code 00118 //---------------------------- 00119 // The mTouch framework does not have an automated, board-level output system yet. 00120 // All system responses to sensor state changes must be programmed by you. 00121 00122 // #define LED0 LATE0 00123 // #define LED1 LATE1 00124 00125 // #define LED_ON 1 00126 // #define LED_OFF 0 00127 00128 // if (CVD_GetButtonState(0) < CVD_PRESSED) { LED0 = LED_OFF; } else { LED0 = LED_ON; } // Sensor0 00129 // if (CVD_GetButtonState(1) < CVD_PRESSED) { LED1 = LED_OFF; } else { LED1 = LED_ON; } // Sensor1 00130 00131 } 00132 } 00133 } 00134 00135 void Example_System_Init() 00136 { 00137 // SYSTEM INITIALIZATION 00138 // 00139 // The mTouch framework controls these modules: 00140 // * TMR0 - YOU MUST INIT THE OPTION REGISTER / TMR0 PRESCALER 00141 // Do not choose 1:1 prescaling. 00142 // 00143 // * ADC - automatic initialization 00144 // * UART - automatic initialization (if enabled and available) 00145 // 00146 // mTouch performs better as Fosc increases. 00147 00148 // (The 12F615 and 12F617 do not have an OSCCON register) 00149 #if !defined(_12F61x) 00150 OSCCON = 0b01110000; // 32 MHz Fosc w/ PLLEN_ON (config) (UPDATE CONFIG FILE IF CHANGED) 00151 #endif 00152 00153 OPTION_REG = 0b10000000; // Set TMR0 Prescaler (NOT 1:1) (UPDATE CONFIG FILE IF CHANGED) 00154 00155 // PORT INITIALIZATION 00156 // 00157 // mTouch sensor pins should be set as digital, output low. 00158 #if defined(_16F1936) 00159 ANSELA = 0b00000000; 00160 ANSELB = 0b00000000; 00161 TRISA = 0b00000000; 00162 TRISB = 0b00000000; 00163 TRISC = 0b00000000; 00164 TRISE = 0b00000000; 00165 PORTA = 0b00000000; 00166 PORTB = 0b00000000; 00167 PORTC = 0b00000000; 00168 PORTE = 0b00000000; 00169 #elif defined(_16F1937) 00170 ANSELA = 0b00000000; 00171 ANSELB = 0b00000000; 00172 ANSELD = 0b00000000; 00173 ANSELE = 0b00000000; 00174 TRISA = 0b00000000; 00175 TRISB = 0b00000000; 00176 TRISC = 0b00000000; 00177 TRISD = 0b00000000; 00178 TRISE = 0b00000000; 00179 PORTA = 0b00000000; 00180 PORTB = 0b00000000; 00181 PORTC = 0b00000000; 00182 PORTD = 0b00000000; 00183 PORTE = 0b00000000; 00184 #elif defined(_12F61x) 00185 #if defined(CVD_DEBUG_UART_ENABLED) 00186 GPIO = 0b00000100; 00187 TRISIO = 0b00000000; 00188 #else 00189 GPIO = 0b00000000; 00190 TRISIO = 0b00000000; 00191 #endif 00192 #endif 00193 00194 00195 } 00196