//热敏电阻检测函数
unsigned int ADC_Ntc_Detect( )
{
unsigned int data16;
P6SEL = 0x04;
ADC12CTL0 = ADC12ON + ADC12SHT0_2;
ADC12CTL1 = ADC12CSTARTADD1 + ADC12SHP;
ADC12MCTL2 = ADC12INCH_2;
ADC12IE = 0x04;
ADC12CTL0 |= ADC12ENC+ADC12SC;
_EINT();
while(adc_sign!='o');
adc_sign = 0;
data16 = adc_data2;
return data16;
}
//中断函数
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: break; // Vector 6: ADC12IFG0
case 8: break; // Vector 8: ADC12IFG1
case 10:
adc_data2 = ADC12MEM2;
adc_sign='o'; //adc_sign 全局变量
break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}
P6.2-----TEMP_ADC2 如图
现在 室温大约18度 但是串口显示adc_data2 结果为0x0195 左右,感觉数据不对,请问是哪里出了问题?多谢!
楼上什么情况,为什么
一周热门 更多>