void ADC12Init(uchar Times,uchar Tube,uchar n,unsigned char v)
{
if(Tube ==0) //单通道转换
{
if(v == 0)
{
ADC12CTL0 = ADC12ON + SHT0_8 + MSC + REFON + REF2_5V; //使用内部电压,打开ADC12内核,8分频,内部参考电压2.5V
ADC12MCTL0 = SREF_0; //使用内部电压,参考位为AVCC和AVSS
}
if(v == 1)
{
ADC12CTL0 = ADC12ON + SHT0_8; //使用外部电压,打开ADC12内核,8分频
ADC12MCTL0 = SREF_2; //使用外部电压,参考为为VeREF+和AVSS
}
if(Times == 0)ADC12CTL1 = SHP + CONSEQ_0; //单通道单次转换,采样信号来自采样定时器
if(Times == 1)ADC12CTL1 = SHP + CONSEQ_2; //单通道多次转换,采样信号来自采样定时器
switch (n) //选择通道
{
case 0:ADC12MCTL0 |= INCH_0;break;
case 1:ADC12MCTL0 |= INCH_1;break;
case 2:ADC12MCTL0 |= INCH_2;break;
case 3:ADC12MCTL0 |= INCH_3;break;
case 4:ADC12MCTL0 |= INCH_4;break;
case 5:ADC12MCTL0 |= INCH_5;break;
case 6:ADC12MCTL0 |= INCH_6;break;
case 7:ADC12MCTL0 |= INCH_7;break;
}
ADC12IE = n; //使能待转换通道的中断
ADC12CTL0 |= ENC; //开启软件使能
}
if(Tube ==1) //多通道转换
{
if(v == 0)
{
ADC12CTL0 = ADC12ON + SHT0_8 + MSC + REFON + REF2_5V; //使用内部电压,打开ADC12内核,8分频,内部参考电压2.5V
ADC12MCTL0 = SREF_0; //使用内部电压,参考位为AVCC和AVSS
}
if(v == 1)
{
ADC12CTL0 = ADC12ON + SHT0_8; //使用外部电压,打开ADC12内核,8分频
ADC12MCTL0 = SREF_2; //使用外部电压,参考为为VeREF+和AVSS
}
if(Times == 0)ADC12CTL1 = SHP + CONSEQ_1; //多通道单次转换,采样信号来自采样定时器
if(Times == 1)ADC12CTL1 = SHP + CONSEQ_3; //多通道多次转换,采样信号来自采样定时器
ADC12IE = 0xff; //使能待转换通道的中断
ADC12CTL0 |= ENC; //开启软件使能
}
} |