// ADC ISR __arm void Adc_CompleteISR_Handler (void) { rI_ISPC = BIT_ADC; // clear pending bit of adc wAdcResult[wAdcPos] = rADCDAT; wAdcPos++; if(wAdcPos < MAX_ADC_BUFFLEN){ BSP_ADC_StartChannel(wAdcCh); }else{ OSSemPost(pSemAdc); // signal sampling over } } /* Initialize the ADC, dwAdcRate is in Hz the larger the PSR is, the lower the input current will be so lower ADC rate can lead to more accurate AD result */ void BSP_ADC_Init(INT32U dwAdcRate) { rADCPSR = MCLK/(32*dwAdcRate)-1; rADCCON = 0; // activate ADC clock, no operation, CH0 pISR_ADC = (unsigned) Adc_CompleteISR_Handler; // set ISR vector rINTMSK &= ~BIT_ADC; // enable inperrupt } // switch to sepcified channel, and start conversion // uiChannel must be within 0 to 7 void BSP_ADC_SwitchChannel(INT16U wChannel) { wAdcPos = 0; wAdcCh = wChannel; rADCCON = 0x01 | (wChannel << 2); // start conversion } // start ADC on specified channel // uiChannel must be within 0 to 7 void BSP_ADC_StartChannel(INT16U wChannel) { rADCCON = 0x01 | (wChannel << 2); }