[求助] 想调用平均值函数

yusiaochong   2012-5-23 09:15 楼主

#include <msp430g2231.h>
#include <intrinsics.h>

 

long volMeasured[8];
unsigned char volMeasuredPosition = 0;
long volAverage;

 

//  定义一个求平均值函数
long Measured[8];
long Average(long Measured[8])
{
  unsigned int i;
  long average = 0;
  for(i = 0;i < 8;i ++)
    average += Measured;
  average >>= 3 ;
  return(average);
 
}

 

// 主函数
void main(void)
{
  //unsigned char i;
  WDTCTL = WDTPW + WDTHOLD;
  ADC10CTL0 = SREF_1 + ADC10SHT_0 + ADC10ON + REFON;
  ADC10CTL0 |= REF2_5V;
  ADC10CTL1 = INCH_1+CONSEQ_0+ADC10DIV_0+ADC10SSEL_2;
  ADC10AE0 |= BIT1;
 
  while(1)
  {
    ADC10CTL0 |= ENC + ADC10SC;
    volMeasured[volMeasuredPosition++] = ADC10MEM;
    if(volMeasuredPosition == 8)
      volMeasuredPosition = 0;


    volAverage = Average(long volMeasured[8]);                 //     为什么我这边调用平均值函数时,编译时会错误?


        P1DIR |= BIT0;
     if(volAverage >0x01FF )    //当电压>1.2V时,红灯亮
        P1OUT |= BIT0;
     else
        P1OUT &= ~BIT0;
  }
}

回复评论 (1)

回复楼主

把自己注释里的volAverage = Average(long volMeasured[8]); 改成volAverage = Average(volMeasured[8]);
点赞  2012-5-23 16:25
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复