代码改编自TI例程,就是测A0通道输入的电压值,电压值如果小于0.5*Vref+,就点亮led,反之led不亮
volatile unsigned int i;
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
MAIN_POWER_ON; //打开外设电源
P7DIR |= LED_PWR; // Led电源打开
P7OUT &=~LED_PWR;
P9DIR |= 0x01; // P1.0 output
P6SEL |= 0x01; // Enable A/D channel A0
ADC12CTL2 |= ADC12REFOUT; // Reference output on
ADC12CTL0 = ADC12ON+ADC12SHT02+ADC12REFON+ADC12REF2_5V;
// Turn on ADC12, Sampling time
// On Reference Generator and set to
// 2.5V
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12MCTL0 = ADC12SREF_1; // Vr+=Vref+ and Vr-=AVss
for ( i=0; i<0x30; i++); // Delay for reference start-up
ADC12CTL0 |= ADC12ENC; // Enable conversions
while (1)
{
ADC12CTL0 |= ADC12SC; // Start conversion
while (!(ADC12IFG & BIT0));
if (ADC12MEM0 >= 0x7ff) // ADC12MEM = A0 > 0.5Vref+?
P9OUT |= BIT0; // P1.0 = 0 Led不亮
else
P9OUT &=~ BIT0; // P1.0 = 1 Led点亮
}
应该说Vref+=2.5V,AVss=0,那么A0输入的电压在1.25V以上Led不亮,在1.25V以下亮
但实际情况是,我用稳压源输入直流电压直至1.6V时Led才不亮,这是为什么?难道我内部参考电压设置有错误,不是2.5V吗??偏差不应该有这么大啊!
求各位大虾帮忙看看,小弟先谢过了...