#include<msp430g2553.h>
#define chang 32
int f=1;
int a[chang];
void max_min();
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
ADC10CTL0 &= ~ENC;//初始化前关闭或默认关闭
ADC10CTL0 = ADC10ON + ADC10SHT_3 + ADC10IE + ADC10SC;
ADC10CTL1 = CONSEQ_2 + ADC10DIV_7;//分频、连续采样
ADC10DTC1 = 0x2f; //数据块长度
ADC10SA = (int)a;
__bis_SR_register(GIE); //开总中断
ADC10CTL0 |= ENC+ADC10SC;//开模数转换
while(f);
max_min();
while(1);
}
/*******************************/
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR_HOO(void)
{
f=0;
}
/*******************************/
void max_min()
{ int i,max,min;
max=min=a[0];
for(i=1;i<chang;i++)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
;
}
} |