#include<reg52.h>
sbit squ_out=P1^7 ;
void main()
{
bit squ_mirror;
unsigned int a,b;
EA =0;
while(1){
for(a=106;a;a--)for(b=1085;b;b--);
squ_out = squ_mirror = ~ squ_mirror;
}
}
周期小了一点点,大约少了57微秒左右。
如果要很准,你的晶振也真的很准,就用下面这个:
#include<reg52.h>
sbit squ_out=P1^7 ;
void main()
{
bit squ_mirror;
unsigned int a,b;
unsigned char c;
EA =0;
while(1){
for(a=106;a;a--)for(b=1085;b;b--);
for(c=12;c;c--);
c++;
squ_out = squ_mirror = ~ squ_mirror;
}
}