This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2540 ADC编程,大家可以参考



#include "ioCC2540.h"

unsigned int adc_result;
void main()
{ CLKCONCMD = 0x80;

// Wait until system clock source has changed to HS XOSC (CLKCONSTA.OSC = 0).
while(CLKCONSTA & 0x40);//外部晶振32MHz
APCFG=0x01;///P0.0脚模拟输入
ADCCON1 = 0x33;///软件方式采样
ADCCON3 =0xb0;///参考电压AVDD5,12bit,有效11位,P0.0脚


while(1)
{ adc_result=0;
ADCCON1 |= 0x40;
while( !(ADCCON1 &0x80));

/* Store the ADC result from the ADCH/L register to the adc_result variable.
* The conversion result resides in the MSB section of the combined ADCH and
* ADCL registers.
*/
adc_result = (ADCL >> 4);
adc_result |= (ADCH << 4);
}

}