|
msp430LAUNCHPAD的5种ADC滤波算法验证--有PCB哦!!
[复制链接]
国庆放假10天,除了玩也做了一点东西!
很久以前我们论坛的网友“常见泽”分享430的5种ADC滤波算法,我闲来无事就为MSP430LAUNCHPAD做了一个扩展板!
下面这个是PCB文件和代码:
ADC滤波测试-1.zip
(7.54 MB, 下载次数: 1077)
ADC滤波测试-1.zip
(7.54 MB, 下载次数: 1077)
- /*
- 算术平均滤波法
- A、方法:
- 连续取N个采样值进行算术平均运算
- N值较大时:信号平滑度较高,但灵敏度较低
- N值较小时:信号平滑度较低,但灵敏度较高
- N值的选取:一般流量,N=12;压力:N=4
- B、优点:
- 适用于对一般具有随机干扰的信号进行滤波
- 这样信号的特点是有一个平均值,信号在某一数值范围附近上下波动
- C、缺点:
- 对于测量速度较慢或要求数据计算速度较快的实时控制不适用
- 比较浪费RAM
- */
- #include
- #define uchar unsigned char
- #define uint unsigned int
- unsigned char i,j;
- long result,resultsum,resultq = 0;
- uchar ge,shi,bai,qian;
- #define SER ( 1 << 1 ) //也是所谓的DS
- #define SRCLK ( 1 << 0 ) //也是所谓的SHCP
- #define RCLK ( 1 << 2 ) //也是所谓的STCP
- void delay_1ms(void)
- {
- unsigned int i;
- for (i=0;i<1000;i++);
- }
- void delay_nms(unsigned int n)
- {
- unsigned int i=0;
- for (i=0;i
- delay_1ms();
- }
- uchar table[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 };
- void Write595(uchar data)
- {
- P2OUT &= ~RCLK;
- for( i=0;i<8;i++ )
- {
- if(data&0x80)
- {
- P2OUT |= SER;
- }
- else
- {
- P2OUT &= ~SER;
- }
- P2OUT &= ~SRCLK;
- P2OUT |= SRCLK;
- data <<= 1;
- }
- P2OUT |= RCLK;
- }
- void ADC_init(void)
- {
- P1SEL |= 0x01;
- ADC10AE0 |= 0x01; // P1.0 ADC option select
- ADC10CTL1 = INCH_0+SHS_1;
- }
- void main(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)
- {
- while(1); // If calibration constants erased
- // do not load, trap CPU!
- }
- //8Mhz
- BCSCTL1 = CALBC1_8MHZ; // Set range
- DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation */
- P1DIR |= (BIT2|BIT3|BIT4|BIT5);
- P2DIR |= 0xff;
- TACCTL0 = CCIE; // Enable interrupt
- TACCR0 = 32-1; // PWM Period
- TACCTL1 = OUTMOD_3; // TACCR1 set/reset
- TACCR1 = 2; // TACCR1 PWM Duty Cycle
- TACTL = TASSEL_1 + MC_1; // ACLK, up mode
- ADC_init();
- _EINT();
- while(1)
- {
- result = resultq/30;
- result = result*1500/1024;
- qian = result/1000;
- bai = result/100%10;
- shi = result/10%10;
- ge = result%10;
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[ge]);
- P1OUT &= ~( 1 << 2 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[shi]);
- P1OUT &= ~( 1 << 3 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[bai]);
- P1OUT &= ~( 1 << 4 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[qian]);
- P1OUT &= ~( 1 << 5 );
- delay_nms(1);
- }
- }
- /********************************************************************/
- // ADC10 interrupt service routine
- #pragma vector=ADC10_VECTOR
- __interrupt void ADC10_ISR(void)
- {
- ADC10CTL0 &= ~ENC; // ADC10 disabled
- ADC10CTL0 = 0; // ADC10, Vref disabled completely
- if(j<31)
- {
- if(j!=0)
- {
- resultsum += ADC10MEM;
- }
- j++;
- }
- else
- {
- resultq = resultsum;
- resultsum = 0;
- j = 0;
- }
- }
- /****************************************************************/
- // Timer A0 interrupt service routine
- #pragma vector=TIMER0_A0_VECTOR
- __interrupt void Timer_A(void)
- {
- ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
- ADC10CTL0 |= ENC; // ADC10 enable set
- }
复制代码- /*
- 加权递推平均滤波法
- A、方法:
- 是对递推平均滤波法的改进,即不同时刻的数据加以不同的权
- 通常是,越接近现时刻的数据,权取得越大。
- 给予新采样值的权系数越大,则灵敏度越高,但信号平滑度越低
- B、优点:
- 适用于有较大纯滞后时间常数的对象
- 和采样周期较短的系统
- C、缺点:
- 对于纯滞后时间常数较小,采样周期较长,变化缓慢的信号
- 不能迅速反应系统当前所受干扰的严重程度,滤波效果差
- */
- #include
- #define uchar unsigned char
- #define uint unsigned int
- const int coefficient[10]= {1,2,3,4,5,6,7,8,9,10};
- const int coesum = 55;
- unsigned char i,j,n;
- long resultsum,resultend,resultsum1,resultq = 0;
- unsigned int result[11];
- uchar ge,shi,bai,qian;
- #define SER ( 1 << 1 ) //也是所谓的DS
- #define SRCLK ( 1 << 0 ) //也是所谓的SHCP
- #define RCLK ( 1 << 2 ) //也是所谓的STCP
- void delay_1ms(void)
- {
- unsigned int i;
- for (i=0;i<1000;i++);
- }
- void delay_nms(unsigned int n)
- {
- unsigned int i=0;
- for (i=0;i
- delay_1ms();
- }
- uchar table[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 };
- void Write595(uchar data)
- {
- P2OUT &= ~RCLK;
- for( i=0;i<8;i++ )
- {
- if(data&0x80)
- {
- P2OUT |= SER;
- }
- else
- {
- P2OUT &= ~SER;
- }
- P2OUT &= ~SRCLK;
- P2OUT |= SRCLK;
- data <<= 1;
- }
- P2OUT |= RCLK;
- }
- void ADC_init(void)
- {
- P1SEL |= 0x01;
- ADC10AE0 |= 0x01; // P1.0 ADC option select
- ADC10CTL1 = INCH_0+SHS_1;
- }
- void main(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)
- {
- while(1); // If calibration constants erased
- // do not load, trap CPU!
- }
- //8Mhz
- BCSCTL1 = CALBC1_8MHZ; // Set range
- DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation */
- P1DIR |= (BIT2|BIT3|BIT4|BIT5);
- P2DIR |= 0xff;
- TACCTL0 = CCIE; // Enable interrupt
- TACCR0 = 32-1; // PWM Period
- TACCTL1 = OUTMOD_3; // TACCR1 set/reset
- TACCR1 = 2; // TACCR1 PWM Duty Cycle
- TACTL = TASSEL_1 + MC_1; // ACLK, up mode
- ADC_init();
- _EINT();
- while(1)
- {
- resultend = resultq*1500/1024;
- qian = resultend/1000;
- bai = resultend/100%10;
- shi = resultend/10%10;
- ge = resultend%10;
- P1OUT &= ~(( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[ge]);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[ge]);
- P1OUT &= ~( 1 << 2 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[shi]);
- P1OUT &= ~( 1 << 3 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[bai]);
- P1OUT &= ~( 1 << 4 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[qian]);
- P1OUT &= ~( 1 << 5 );
- delay_nms(1);
- }
- }
- /********************************************************************/
- // ADC10 interrupt service routine
- #pragma vector=ADC10_VECTOR
- __interrupt void ADC10_ISR(void)
- {
- ADC10CTL0 &= ~ENC; // ADC10 disabled
- ADC10CTL0 = 0; // ADC10, Vref disabled completely
- if(j<11)
- {
- result[j] = ADC10MEM;
- j++;
- }
- else
- {
- for(n=0;n<10;n++)
- {
- result[n] = result[n+1];
- resultsum += result[n]*coefficient[n];
- }
- resultsum /= coesum;
- resultq = resultsum;
- resultsum = 0;
- j = 0;
- }
- //ADC10CTL0 |= ENC; // ADC10 enable set
- }
- /****************************************************************/
- // Timer A0 interrupt service routine
- #pragma vector=TIMER0_A0_VECTOR
- __interrupt void Timer_A(void)
- {
- ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
- ADC10CTL0 |= ENC; // ADC10 enable set
- }
复制代码- /*
- 限幅滤波法(又称程序判断滤波法)
- A、方法:
- 根据经验判断,确定两次采样允许的最大偏差值(设为A)
- 每次检测到新值时判断:
- 如果本次值与上次值之差<=A,则本次值有效
- 如果本次值与上次值之差>A,则本次值无效,放弃本次值,用上次值代替本次值
- B、优点:
- 能有效克服因偶然因素引起的脉冲干扰
- C、缺点
- 无法抑制周期性的干扰
- 平滑度差
- */
- #include
- #define uchar unsigned char
- #define uint unsigned int
- #define A 2
- unsigned char j = 0;
- long result[31],resultsum,resultend,resultq = 0;
- uchar ge,shi,bai,qian;
- #define SER ( 1 << 1 ) //也是所谓的DS
- #define SRCLK ( 1 << 0 ) //也是所谓的SHCP
- #define RCLK ( 1 << 2 ) //也是所谓的STCP
- void delay_1ms(void)
- {
- unsigned int i;
- for (i=0;i<1000;i++);
- }
- void delay_nms(unsigned int n)
- {
- unsigned int i=0;
- for (i=0;i
- delay_1ms();
- }
- uchar table[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 };
- //uchar table[]={ 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E };
- void Write595(uchar data)
- {
- uchar i;
- P2OUT &= ~RCLK;
- for( i=0;i<8;i++ )
- {
- if(data&0x80)
- {
- P2OUT |= SER;
- }
- else
- {
- P2OUT &= ~SER;
- }
- P2OUT &= ~SRCLK;
- P2OUT |= SRCLK;
- data <<= 1;
- }
- P2OUT |= RCLK;
- }
- /*void ADC_init(void)
- {
- P1SEL |= 0x01;
- ADC10CTL0 = SREF_1 + REFON + ADC10ON + ADC10IE + ADC10SHT_2; //
- ADC10AE0 |= 0x01; // P1.0 ADC option select
- ADC10CTL1 = INCH_0+ADC10SSEL_2;
- ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
- }*/
- void ADC_init(void)
- {
- P1SEL |= 0x01;
- ADC10AE0 |= 0x01; // P1.0 ADC option select
- ADC10CTL1 = INCH_0+SHS_1;
- }
- void main(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)
- {
- while(1); // If calibration constants erased // do not load, trap CPU!
- }
- //8Mhz
- BCSCTL1 = CALBC1_8MHZ; // Set range
- DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation */
- P1DIR |= (BIT2|BIT3|BIT4|BIT5);
- P2DIR |= 0xff;
- TACCTL0 = CCIE; // Enable interrupt
- TACCR0 = 32-1; // PWM Period
- TACCTL1 = OUTMOD_3; // TACCR1 set/reset
- TACCR1 = 2; // TACCR1 PWM Duty Cycle
- TACTL = TASSEL_1 + MC_1; // ACLK, up mode
- ADC_init();
- _EINT();
- while(1)
- {
- resultend = resultq*1500/1024;
- qian = resultend/1000;
- bai = resultend/100%10;
- shi = resultend/10%10;
- ge = resultend%10;
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[ge]);
- P1OUT &= ~( 1 << 2 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[shi]);
- P1OUT &= ~( 1 << 3 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[bai]);
- P1OUT &= ~( 1 << 4 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[qian]);
- P1OUT &= ~( 1 << 5 );
- delay_nms(1);
- }
- }
- /********************************************************************/
- // ADC10 interrupt service routine
- #pragma vector=ADC10_VECTOR
- __interrupt void ADC10_ISR(void)
- {
- ADC10CTL0 &= ~ENC; // ADC10 disabled
- ADC10CTL0 = 0; // ADC10, Vref disabled completely
- if(j<31)
- {
- result[j] = ADC10MEM;
- if(j>=2)
- {
- if((result[j] - result[j-1]>A)||(result[j-1] - result[j]>A))
- resultsum = result[j-1];
- else
- resultsum = result[j];
- }
- j++;
- }
- else
- {
- resultq = resultsum;
- j = 0;
- }
- }
- /****************************************************************/
- // Timer A0 interrupt service routine
- #pragma vector=TIMER0_A0_VECTOR
- __interrupt void Timer_A(void)
- {
- ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
- ADC10CTL0 |= ENC; // ADC10 enable set
- }
复制代码- /*
- 中位值滤波法
- A、方法:
- 连续采样N次(N取奇数)
- 把N次采样值按大小排列
- 取中间值为本次有效值
- B、优点:
- 能有效克服因偶然因素引起的波动干扰
- 对温度、液位的变化缓慢的被测参数有良好的滤波效果
- C、缺点:
- 对流量、速度等快速变化的参数不宜
- */
- #include
- #define uchar unsigned char
- #define uint unsigned int
- #define X 31
- unsigned char i,j,k,n;
- long resultsum,temp,resultq = 0;
- uint result[31];
- uchar ge,shi,bai,qian;
- #define SER ( 1 << 1 ) //也是所谓的DS
- #define SRCLK ( 1 << 0 ) //也是所谓的SHCP
- #define RCLK ( 1 << 2 ) //也是所谓的STCP
- void delay_1ms(void)
- {
- unsigned int i;
- for (i=0;i<1000;i++);
- }
- void delay_nms(unsigned int n)
- {
- unsigned int i=0;
- for (i=0;i
- delay_1ms();
- }
- uchar table[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 };
- void Write595(uchar data)
- {
- P2OUT &= ~RCLK;
- for( i=0;i<8;i++ )
- {
- if(data&0x80)
- {
- P2OUT |= SER;
- }
- else
- {
- P2OUT &= ~SER;
- }
- P2OUT &= ~SRCLK;
- P2OUT |= SRCLK;
- data <<= 1;
- }
- P2OUT |= RCLK;
- }
- void ADC_init(void)
- {
- P1SEL |= 0x01;
- ADC10AE0 |= 0x01; // P1.0 ADC option select
- ADC10CTL1 = INCH_0+SHS_1;
- }
- void main(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)
- {
- while(1); // If calibration constants erased // do not load, trap CPU!
- }
- //8Mhz
- BCSCTL1 = CALBC1_8MHZ; // Set range
- DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation */
- P1DIR |= (BIT2|BIT3|BIT4|BIT5);
- P2DIR |= 0xff;
- TACCTL0 = CCIE; // Enable interrupt
- TACCR0 = 32-1; // PWM Period
- TACCTL1 = OUTMOD_3; // TACCR1 set/reset
- TACCR1 = 2; // TACCR1 PWM Duty Cycle
- TACTL = TASSEL_1 + MC_1; // ACLK, up mode
- ADC_init();
- _EINT();
- while(1)
- {
- resultsum = resultq;
- resultsum = resultsum*1500/1024;
- qian = resultsum/1000;
- bai = resultsum/100%10;
- shi = resultsum/10%10;
- ge = resultsum%10;
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[ge]);
- P1OUT &= ~( 1 << 2 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[shi]);
- P1OUT &= ~( 1 << 3 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[bai]);
- P1OUT &= ~( 1 << 4 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[qian]);
- P1OUT &= ~( 1 << 5 );
- delay_nms(1);
- }
- }
- /********************************************************************/
- // ADC10 interrupt service routine
- #pragma vector=ADC10_VECTOR
- __interrupt void ADC10_ISR(void)
- {
- ADC10CTL0 &= ~ENC; // ADC10 disabled
- ADC10CTL0 = 0; // ADC10, Vref disabled completely
- if(j
- {
- result[j] = ADC10MEM;
- j++;
- }
- else
- {
- for(n=0;n
- {
- for(k=0;k
- {
- if(result[k]>result[k+1])
- {
- temp = result[k];
- result[k] = result[k+1];
- result[k+1] = temp;
- }
- }
- }
- resultq = result[(X-1)/2];
- j = 0;
- }
- //ADC10CTL0 |= ENC; // ADC10 enable set
- }
- /****************************************************************/
- // Timer A0 interrupt service routine
- #pragma vector=TIMER0_A0_VECTOR
- __interrupt void Timer_A(void)
- {
- ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
- ADC10CTL0 |= ENC; // ADC10 enable set
- }
复制代码- /*
- 中位值平均滤波法(又称防脉冲干扰平均滤波法)
- A、方法:
- 相当于“中位值滤波法”+“算术平均滤波法”
- 连续采样N个数据,去掉一个最大值和一个最小值
- 然后计算N-2个数据的算术平均值
- N值的选取:3~14
- B、优点:
- 融合了两种滤波法的优点
- 对于偶然出现的脉冲性干扰,可消除由于脉冲干扰所引起的采样值偏差
- C、缺点:
- 测量速度较慢,和算术平均滤波法一样
- 比较浪费RAM
- */
- #include
- #define uchar unsigned char
- #define uint unsigned int
- #define X 31
- unsigned char i,j,k,n,m;
- long resultsum,temp,resultend,resultq = 0;
- uint result[31];
- uchar ge,shi,bai,qian;
- #define SER ( 1 << 1 ) //也是所谓的DS
- #define SRCLK ( 1 << 0 ) //也是所谓的SHCP
- #define RCLK ( 1 << 2 ) //也是所谓的STCP
- void delay_1ms(void)
- {
- unsigned int i;
- for (i=0;i<1000;i++);
- }
- void delay_nms(unsigned int n)
- {
- unsigned int i=0;
- for (i=0;i
- delay_1ms();
- }
- uchar table[]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 };
- void Write595(uchar data)
- {
- P2OUT &= ~RCLK;
- for( i=0;i<8;i++ )
- {
- if(data&0x80)
- {
- P2OUT |= SER;
- }
- else
- {
- P2OUT &= ~SER;
- }
- P2OUT &= ~SRCLK;
- P2OUT |= SRCLK;
- data <<= 1;
- }
- P2OUT |= RCLK;
- }
- void ADC_init(void)
- {
- P1SEL |= 0x01;
- ADC10AE0 |= 0x01; // P1.0 ADC option select
- ADC10CTL1 = INCH_0+SHS_1;
- }
- void main(void)
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)
- {
- while(1); // If calibration constants erased
- // do not load, trap CPU!!
- }
- //8Mhz
- BCSCTL1 = CALBC1_8MHZ; // Set range
- DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation */
- P1DIR |= (BIT2|BIT3|BIT4|BIT5);
- P2DIR |= 0xff;
- TACCTL0 = CCIE; // Enable interrupt
- TACCR0 = 32-1; // PWM Period
- TACCTL1 = OUTMOD_3; // TACCR1 set/reset
- TACCR1 = 2; // TACCR1 PWM Duty Cycle
- TACTL = TASSEL_1 + MC_1; // ACLK, up mode
- ADC_init();
- _EINT();
- while(1)
- {
- resultend = resultq/29;
- resultend = resultend*1500/1024;
- qian = resultend/1000;
- bai = resultend/100%10;
- shi = resultend/10%10;
- ge = resultend%10;
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[ge]);
- P1OUT &= ~( 1 << 2 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[shi]);
- P1OUT &= ~( 1 << 3 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[bai]);
- P1OUT &= ~( 1 << 4 );
- delay_nms(1);
- P1OUT |= (( 1 << 2 )|(1<<3)|(1<<4)|(1<<5));
- Write595(table[qian]);
- P1OUT &= ~( 1 << 5 );
- delay_nms(1);
- }
- }
- /********************************************************************/
- // ADC10 interrupt service routine
- #pragma vector=ADC10_VECTOR
- __interrupt void ADC10_ISR(void)
- {
- ADC10CTL0 &= ~ENC; // ADC10 disabled
- ADC10CTL0 = 0; // ADC10, Vref disabled completely
- if(j
- {
- result[j]= ADC10MEM;
- j++;
- }
- else
- {
- for(n=0;n
- {
- for(k=0;k
- {
- if(result[k]>result[k+1])
- {
- temp = result[k];
- result[k] = result[k+1];
- result[k+1] = temp;
- }
- }
- }
- for(m=1;m<30;m++)
- {
- resultsum += result[m];
- }
- resultq = resultsum;
- resultsum = 0;
- j = 0;
- }
- }
- /****************************************************************/
- // Timer A0 interrupt service routine
- #pragma vector=TIMER0_A0_VECTOR
- __interrupt void Timer_A(void)
- {
- ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;
- ADC10CTL0 |= ENC; // ADC10 enable set
- }
复制代码
[ 本帖最后由 IC爬虫 于 2012-10-8 18:17 编辑 ]
|
赞赏
-
1
查看全部赞赏
-
|