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 00030 #include "pic24_all.h" 00031 #include "stdio.h" 00032 00033 // uncomment the next line to setup this project for a 12-bit ADC 00034 #define USE_12BIT_ADC 00035 00036 #ifdef USE_12BIT_ADC 00037 #define ADC_LEN 12 00038 #define ADC_NSTEPS 4096 00039 #define ADC_12BIT_FLAG 1 00040 #else 00041 #define ADC_LEN 10 00042 #define ADC_NSTEPS 1024 00043 #define ADC_12BIT_FLAG 0 00044 #endif 00045 00052 int main (void) { 00053 uint16 u16_pot1, u16_pot2; 00054 float f_pot1, f_pot2; 00055 00056 configBasic(HELLO_MSG); 00057 00058 // make RA0/AN0/VREF+ a digital input to kill the pullup and 00059 // set the TRISA bit, then make it ANALOG so the ADC will work 00060 CONFIG_AN0_AS_ANALOG(); 00061 CONFIG_AN1_AS_ANALOG(); 00062 00063 while (1) { 00064 configADC1_ManualCH0( ADC_CH0_POS_SAMPLEA_AN0, 31, ADC_12BIT_FLAG ); 00065 u16_pot1 = convertADC1(); 00066 configADC1_ManualCH0( ADC_CH0_POS_SAMPLEA_AN1, 31, ADC_12BIT_FLAG ); 00067 u16_pot2 = convertADC1(); 00068 00069 f_pot1 = 3.30 / ADC_NSTEPS * u16_pot1; 00070 f_pot2 = 3.30 / ADC_NSTEPS * u16_pot2; 00071 00072 printf("AN0 is 0x%0X or %1.4fV. | AN1 is 0x%0X or %1.4fV.\n", \ 00073 u16_pot1, (double) f_pot1, u16_pot2, (double) f_pot2 ); 00074 00075 DELAY_MS(1500); 00076 00077 } //endof while() 00078 } // endof main() 00079