#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; } }
|