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 00038 #define VREF 3.3 //assume Vref = 3.3 volts 00039 00040 int main (void) { 00041 uint16 u16_adcVal; 00042 float f_adcVal; 00043 00044 configBasic(HELLO_MSG); 00045 CONFIG_AN5_AS_ANALOG(); 00046 00047 // Configure A/D to sample AN5 for 31 Tad periods in 10-bit mode 00048 // then perform a single conversion. 00049 configADC1_ManualCH0(ADC_CH0_POS_SAMPLEA_AN5, 31, 0); 00050 while (1) { 00051 u16_adcVal = convertADC1(); //get ADC value 00052 f_adcVal = u16_adcVal; 00053 f_adcVal = f_adcVal/1024.0 * VREF; //convert to float 0.0 to VREF 00054 printf("ADC input: %4.2f V (0x%04x)\n", (double) f_adcVal, u16_adcVal); 00055 DELAY_MS(300); //delay so that we do not flood the UART. 00056 doHeartbeat(); 00057 } //end while(1) 00058 00059 }