MSP430F149AD转换时,先选的SREF0,可以测电压,想把范围调大一点,然后就选SREF_2,即参考电压是Veref+,公式转换那里也改了乘以5,其它没改,结果,数码管一直显示5V,什么线都没连,也是5Vfile:///C:UsersSVIPAppDataRoamingTencentUsers1851693695QQWinTempRichOle}~D8O8EM0AKOTAI__X_E5AS.png
file:///C:UsersSVIPAppDataRoamingTencentUsers1851693695QQWinTempRichOle}~D8O8EM0AKOTAI__X_E5AS.png
-
#include "12864.h"
uchar x,y,z,i=0;
uint a[],num=0;
float temp=0;
void ADC_INIT()
{
ADC10CTL0|=REFON+REF2_5V+SREF_1;
ADC10CTL0|=ADC10IE+ADC10ON+ADC10SHT_2+MSC;//采样保持时间16*ADC10CLK,多次采样控制位
ADC10CTL1|=INCH_1+CONSEQ_2+ADC10DIV_0;//输入通道选择A1,单通道多次转换
ADC10AE0=0x02; //A1模拟信号输入使能
ADC10DTC1|=0x0a;
delay(40);
}
void ADC_Display()
{
temp=num*2.5/1023;
temp=temp*100;
x=(uint)temp/100;
y=(uint)temp/10%10;
z=(uint)temp%10;
display(2,3);
Dis_SZ(x);
write_dat('.');
Dis_SZ(y);
Dis_SZ(z);
write_dat('v');
}
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1SEL|=BIT1;
P1DIR&=~BIT1;
ADC_INIT();
lcd_init();
delay(40);
display(1,0);
Dis_HZ("电压读数:",5);
while(1)
{
ADC10CTL0&=~ENC;
while(ADC10CTL1&ADC10BUSY);
ADC10SA=(int)a;
ADC10CTL0|=ENC+ADC10SC;
_EINT();//关闭C PU,开启总中断
LPM0;
for(i=0;i<5;i++)
{
num=num+a[2*i];
}
num=num/5;
ADC_Display();
}
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
LPM0_EXIT;// Clear CPUOFF bit from 0(SR)
}
这是G2553的
一周热门 更多>