#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define ADC0809 XBYTE[0x0B000] //P2.6选通
float sum=0,fjg;
uint i,j,*q,*p,sd=5;
sbit p1_0=P1^0;
void wait(uint n);
void main(void)
{ j=0;
TMOD=0X01;//设置定时器0
TH0=0XFC;//定时时间设为1ms
TL0=0X18;
EA=0;//先关中断
EA=1;//开总中断
ET0=1;
//TR0=1;
for(; ;)
{
if(j=20){
do{}while(!TF0);
q=0x30;
for(i=0;i20;i++) //转化后的数值求均方根
{sum=sum+(*q)*(*q);
q++;
}
sum=sum/20;
fjg=sqrt(sum);
if(fjg>sd) //判断是否跳闸
p1_0=1;
j=0;
}}
}
void power(void)
{ uchar x;
for(;;)
{ADC0809=0x01;
wait(1000);
x=ADC0809;
P2=x;
}
}
void wait(uint n)
{ uint i,j;
for(i=0;i
for(j=0;j100;j++);
}
timer0()interrupt 1 using 1
{*p=ADC0809;
p++;
TH0=0XFC;
TL0=0X18;
TR0=1;
j++;
}