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;//清除中断标志
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
当把这一栏注释掉时
数码管都显示0,没有采集到数据,不知道为什么挂死在这里
//******************************************************************************
// MSP430F20x2 Demo - ADC10, Sample A1, AVcc Ref, Set P1.0 if > 0.5*AVcc
//
// Description: A single sample is made on A1 with reference to AVcc.
// Software sets ADC10SC to start sample and conversion - ADC10SC
// automatically cleared at EOC. ADC10 internal oscillator times sample (16x)
// and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC10
// conversion complete, ADC10_ISR will force exit from LPM0 in Mainloop on
// reti. If A1 > 0.5*AVcc, P1.0 set, else reset.
//
// MSP430F20x2
// -----------------
// /|| XIN|-
// | | |
// --|RST XOUT|-
// | |
// >---|P1.1/A1 P1.0|-->LED
//
// L. Westlund
// Texas Instruments Inc.
// May 2006
// Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.41A
//******************************************************************************
#include "msp430x20x2.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE; // ADC10ON, interrupt enabled
ADC10CTL1 = INCH_1; // input A1
ADC10AE0 |= 0x02; // PA.1 ADC option select
P1DIR |= 0x01; // Set P1.0 to output direction
for (;;)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit
if (ADC10MEM < 0x1FF)
P1OUT &= ~0x01; // Clear P1.0 LED off
else
P1OUT |= 0x01; // Set P1.0 LED on
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Clear CPUOFF bit from 0(SR)
}
一周热门 更多>