AVR (ATMEGA)软件滤波方法程序(限值平均滤波法)
- UID
- 1062083
- 性别
- 男
|
AVR (ATMEGA)软件滤波方法程序(限值平均滤波法)
int data;
int shuzu[7]={0x00,0x00,0x00,0x00,0x00,0x00,0x00};
/****************限值平均滤波法****************/
/*********去最大值最小值,剩下的取平均*********/
int filter(int newdata, uchar n)
{
int max, min, sum;
uchar i;
shuzu[0]=newdata;
max=shuzu[0];
min=shuzu[0];
sum=shuzu[0];
for(i=n-1; i!=0; i--)
{
if(shuzu>max)max=shuzu;
else if(shuzu<MIN) min="shuzu;
sum+=shuzu;
shuzu=shuzu[i-1];
}
i=n-2;
sum=sum-max-min+i/2;
sum=sum/i;
return((int)sum);
}
void main()
{uchar i;
uchar table[5];
long a;
DDRA=0X00;
PORTA=0X00;
DDRB=0X00;
PORTB=0XFF;
DDRC=0X00;
PORTC=0X00;
DDRD=0x00;
PORTD=0X00;
DDRE=0X00;
PORTE=0X00;
DDRF=0X00;
PORTF=0X00;
DDRG=0X00;
PORTG=0X00;
SEI(); //开总中断
DDRF=0XFF;
LCD1602_initial();
LCD1602_gotoXY(1,13);
LCD1602_sendbyte(iDat,5+0x30);
while(1)
{
if(PINB==0B11111110)
{
delayms(1000);
data=data+100;
a=filter(data,7);
LCD1602_gotoXY(1,3);
table[0]=a/100000;
table[1]=a%100000/10000;
table[2]=a%10000/1000;
table[3]=a%1000/100;
table[4]=a%100/10;
table[5]=a%10;
for(i=0;i<6;i++)
{
//LCD1602_sendbyte(iDat,0x30+R_dat0);
LCD1602_sendbyte(iDat,0x30+table);
}
}
}
}
关键字:AVR ATMEGA 软件滤波 限值平均滤波法 |
|
|
|
|
|