📄 configadc.c
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 *
* *** + + *** HAL - ConfigADC *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* *
*****************************************************************************
* Author: ROH *
*****************************************************************************
* Revision history: *
* *
* $Log: ConfigADC.c,v $
* Revision 1.1 2002/10/14 13:04:29 tos
* Initial version in CVS.
*
* *
****************************************************************************/
#include <chipcon/hal.h>
//----------------------------------------------------------------------------
// bool halConfigADC(...)
//
// Description:
// This function configures the ADC. The _option_ argument is used to
// select operational mode, _clkFreq_ gives the device clock frequency in
// kHz, and _threshold_ is used to set the threshold value for some
// operational modes. An interrupt is generated in all modes (except
// for reset-generating mode in which a reset is generated instead) whenever
// the 8 MSB of the measured sample is greater or equal to the threshold
// value. Thus, if an interrupt for each sample is desired, the threshold
// should be set to 0 (and the ADC and GLOBAL_ADC_DES interrupts enabled.)
// After configuring the ADC it must be powered up using the ADC_POWER(bool)
// macro. It should be powered down again when not in use to conserve power.
// The correct ADC input must be selected using the ADC_SELECT_INPUT(input)
// macro and started using the ADC_RUN(bool) macro for continuous modes.
// The ADC_SAMPLE_SINGLE macro is used to initiate a sample acquisition in
// single-conversion mode, and the ADC_RUNNING macro can be used to
// determine whether the sample is complete
// The ADC_GET_SAMPLE_10BIT or ADC_GET_SAMPLE_8BIT macros return the latest
// sample value.
//
// Arguments:
// byte options
// One or more of the below defined constants define the desired
// operational mode.
// word clkFreq
// The XOSC clock frequency in kHz.
// byte threshold
// The threshold value for generating interrupts (and stopping in
// multi-conversion, stopping mode) or reset (in multi-conversion,
// reset-generating mode).
//
// Return value:
// void
//----------------------------------------------------------------------------
void halConfigADC(byte options, word clkFreq, byte threshold) {
clkFreq= (clkFreq-250*8)/(250*16);
ADCON2=(options&0x80)|((byte)clkFreq&0x3F);
if (options&ADC_INTERRUPT_ENABLE) {
EXIF&=~0x40;
ADIE=1;
}
ADCON=0x80|(options&0x38);
ADTRH=threshold;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -