[求助] MSP430FE4252 电压采集

changjianqiyuan   2014-5-16 09:59 楼主
#include
#include "LCD.h"

#define BEEP(x) (x?(P1OUT&=~BIT2):(P1OUT|=BIT2))
//Led
#define LED_Init   (P1DIR|=BIT2+BIT3+BIT5+BIT6)//初始化
#define LED_G(x)   (x?(P1OUT&=~BIT3):(P1OUT|=BIT3))//红色灯
#define LED_B(x)   (x?(P1OUT&=~BIT5):(P1OUT|=BIT5))//红色灯
#define LED_R(x)   (x?(P1OUT&=~BIT6):(P1OUT|=BIT6))//红色灯

#define POW_R(x) (x?(P1OUT&=~BIT4):(P1OUT|=BIT4))//红色灯

#define Num_of_Results 8

/* Arrays to store SD16 conversion results */
/* NOTE: arrays need to be global to */
/* prevent removal by compiler */
//static unsigned int results[Num_of_Results];

static unsigned int results;

int main(void)
{
  volatile unsigned int i;                  // Use volatile to prevent removal
                                            // by compiler optimization

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  FLL_CTL0 |= XCAP14PF;                     // Configure load caps
  for (i = 0; i < 10000; i++);              // Delay for 32 kHz crystal to
                                            // stabilize
   LCD_Init();

// for (i = 0; i < 0x3600; i++);             // Delay for 1.2V ref startup
    P1DIR|=BIT4+BIT7;
    P1OUT&=~(BIT4);
   // P1OUT|=(BIT4);
    P1OUT|=BIT7;
    LED_Init;
    BEEP(0);
    LED_R(0);
    LED_G(1);
    LED_B(0);
  
SD16CTL = SD16REFON+SD16SSEL0; // 1.2V ref, SMCLK
SD16INCTL0 |= SD16INCH_0 + SD16INTDLY0; // Interrupt on 3rd sample
SD16CCTL0 |= SD16IE ; // Enable interrupt
for (i = 0; i < 0x3600; i++); // Delay for 1.2V ref startup

_EINT(); // Enable general interrupts

SD16CCTL0 |= SD16SC; // Set bit to start conversion
_BIS_SR(LPM0_bits); // Enter LPM0

}

#pragma vector=SD16_VECTOR
__interrupt void SD16ISR(void)
{
static unsigned int index = 0;

switch (SD16IV)
{
case 2: // SD16MEM Overflow
break;
case 4: // SD16MEM0 IFG

results= SD16MEM0; // Save CH0 results (clears IFG),set break point here

break;
case 6: // SD16MEM1 IFG
break;
case 8: // SD16MEM2 IFG

break;
}
}

单步运行的结果是SD16MEM0的值在乱跳  ,外部已经加有一个稳定的电压测试点 大概是200mv

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复