00001 /* 00002 * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")" 00003 * All rights reserved. 00004 * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University) 00005 * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University) 00006 * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University) 00007 * 00008 * Permission to use, copy, modify, and distribute this software and its 00009 * documentation for any purpose, without fee, and without written agreement is 00010 * hereby granted, provided that the above copyright notice, the following 00011 * two paragraphs and the authors appear in all copies of this software. 00012 * 00013 * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR 00014 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 00015 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS" 00016 * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00017 * 00018 * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES, 00019 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 00020 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 00021 * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO 00022 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." 00023 * 00024 * Please maintain this header in its entirety when copying/modifying 00025 * these files. 00026 * 00027 * 00028 */ 00029 #include "pic24_all.h" 00030 #include <stdio.h> 00031 00036 void configComparator(void) { 00037 CMCON = CMP_IDLE_STOP | CMP1_ENABLE | CMP2_DISABLE | 00038 CMP1_OUTPUT_DISABLE | CMP1_NORMAL_OUTPUT | 00039 CMP1_NEG_IP_VIN_POS | CMP1_POS_IP_CV_REF; 00040 CVRCON = CMP_VREF_ENABLE | 00041 CMP_VREF_OUTPUT_DISABLE | 00042 CMP_VRSRC_AVDD_AVSS | 00043 CMP_0P50_CVRR_1 ; 00044 DELAY_US(10) //wait for comparator to settle 00045 _C1EVT = 0; //clear C1 event flag 00046 _CMIF = 0; //clear interrupt flag 00047 } 00048 00049 int main (void) { 00050 uint8 u8_i; 00051 configBasic(HELLO_MSG); 00052 configComparator(); 00053 u8_i = _C1OUT; //intial read to set trigger 00054 while (1) { 00055 do { 00056 doHeartbeat(); //wait for trigger 00057 } while (!_CMIF); 00058 _CMIF = 0; 00059 u8_i = _C1OUT; //current value 00060 outString("\n Comparator fired: "); 00061 outUint8(u8_i); 00062 DELAY_MS(100); 00063 } //end while 00064 }//end main