注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
yusiaochong的个人空间 https://home.eeworld.com.cn/space-uid-416682.html [收藏] [复制] [分享] [RSS]
日志

想调用平均值函数

已有 557 次阅读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;
  }
}

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册