void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
// Stop watchdog timer to prevent time out reset
if (CALBC1_8MHZ == 0xFF || CALDCO_8MHZ == 0xFF)
{
while(1); // If calibration constants erased, trap CPU!!
}
// Configure Basic Clock
BCSCTL1 = CALBC1_8MHZ; // Set range
DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation*/
ADC10CTL0= ADC10ON+REFON+ADC10SHT_3+MSC+ADC10IE+SREF_1;
ADC10CTL1= CONSEQ_3+INCH_10;
ADC10CTL0&=~ADC10IFG;
_EINT();//打开中断
__delay_cycles(10);
while(1)
{
while (ADC10CTL1 & BUSY);// Wait if ADC10 core is active
ADC10SA = 0x200; // Data buffer start
ADC10CTL0 |= ENC+ADC10SC;//使能转换并且开始转换
__delay_cycles(1);
display();
}
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10ISR(void)
{
char index=0;
int i;
results[index++]=ADC10MEM;
if(index==NUM)
{
unsigned long sum,real;
index=0;
for(i=0;i<NUM;i++)
{
sum+=results[i];
}
sum>>=5; //除以32求平均值
real=((1.5*sum/1023)-0.986)/0.00355;//扩大1000倍
data_temp[3]=real/1000; //千位
data_temp[2]=(real%1000)/1000; //百位
data_temp[1]=real%100/10; //十位
data_temp[0]=real%10; //个位
__delay_cycles(10);
//display();
}
ADC10CTL0&=~ADC10IFG;//清除中断标志
}
|