unsigned int result[4];
void init_ADC10()
{
P1SEL|=BIT0+BIT3+BIT4+BIT5;
ADC10AE0|=BIT0+BIT3+BIT4+BIT5; // 使P1.0允许AD模拟输入信号
ADC10CTL0=ADC10ON+MSC+SREF_0;//+REFON 开AD内核,选择电源为参考电压
ADC10CTL1=ADC10SSEL_0+CONSEQ_0; //+INCH_1+INCH_2 选择ADC12SC为触发源,选择系统时钟为AD内核时钟,采用单通道多次采用
}
void start_ADC10()
{
ADC10CTL1|=INCH_0;
ADC10CTL0|=ADC10SC+ENC; // 开始转换 开转换允许
while(ADC10CTL1&ADC10BUSY!=0);//判断是否转换完毕
result[0]= ADC10MEM;
//printf("%d\n",result[0]);
ADC10CTL0&=~(ADC10SC+ENC); //关转换允许才能选择通道
ADC10CTL1&=~INCH_0; //通道清0
ADC10CTL1|=INCH_3;
ADC10CTL0|=ADC10SC+ENC;
while(ADC10CTL1&ADC10BUSY!=0);
result[1]= ADC10MEM;
//printf("%d\n",result[1]);
ADC10CTL0&=~(ADC10SC+ENC);
ADC10CTL1&=~INCH_3;
ADC10CTL1|=INCH_4;
ADC10CTL0|=ADC10SC+ENC;
while(ADC10CTL1&ADC10BUSY!=0);
result[2]= ADC10MEM;
ADC10CTL0&=~(ADC10SC+ENC);
ADC10CTL1&=~INCH_4;
ADC10CTL1|=INCH_5;
ADC10CTL0|=ADC10SC+ENC;
while(ADC10CTL1&ADC10BUSY!=0);
result[3]= ADC10MEM;
ADC10CTL0&=~(ADC10SC+ENC);
ADC10CTL1&=~INCH_5;
//printf("%d\n",result[2]);
} |