void Init_ADC(void)
{
//初始化IO口
AD1CR_bit.SEL = 6; //enable AD1.6
AD1CR_bit.CLKDIV = 60000000/4500000;
AD1CR_bit.BURST = 0; // put A/D into continuous convert mode
AD1CR_bit.CLKS = 0; //11 clocks/10 bit accuracy
AD1CR_bit.PDN = 1; //power up the unit
PINSEL1_bit.P0_21 = 2; // This is probably the potentiometer output
//开始转换
AD1CR_bit.START = 0x0001; //start 1st cnvrsn immediately
}
//-------------------------------------------
//读取ADC的值
unsigned int Read_ADC(void)
{
unsigned int ADCresult;
while(AD1DR6_bit.DONE == 0); //wait until conversion done
ADCresult = AD1DR6_bit.VVDDA ; // save the converted data
//开始下一次转换
AD1CR_bit.START = 0x0001; // start the next conversion
return ADCresult;
}
请那位告诉帮我看看。什么地方有问题呀。例程改的。谢谢 |