单片机的C语言编程

这是一个测输入信号频率的代码,谁能把每句都翻译,最好能讲明白点
#include <AT89X51.h>
unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};
unsigned char dispbuf[8]={0,0,0,0,0,0,10,10};
unsigned char temp[8];
unsigned char dispcount;
unsigned char T0count;
unsigned char timecount;
bit flag;
unsigned long x;

void main(void)
{
unsigned char i;

TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
TR1=1;
TR0=1;
ET0=1;
ET1=1;
EA=1;

while(1)
{
if(flag==1)
{
flag=0;
x=T0count*65536+TH0*256+TL0;
for(i=0;i<8;i++)
{
temp[i]=0;
}
i=0;
while(x/10)
{
temp[i]=x%10;
x=x/10;
i++;
}
temp[i]=x;
for(i=0;i<6;i++)
{
dispbuf[i]=temp[i];
}
timecount=0;
T0count=0;
TH0=0;
TL0=0;
TR0=1;
}
}
}

void t0(void) interrupt 1 using 0
{
T0count++;
}

void t1(void) interrupt 3 using 0
{
TH1=(65536-5000)/256;
TL1=(65536-5000)%256;
timecount++;
if(timecount==200)
{
TR0=0;
timecount=0;
flag=1;
}
P2=0xff;
P0=dispcode[dispbuf[dispcount]];
P2=dispbit[dispcount];
dispcount++;
if(dispcount==8)
{
dispcount=0;
}
}

#include <AT89X51.h> //包含头文件
unsigned char code dispbit[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //定义数码管位选码
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x6f,0x00,0x40};//定义数码管段选码
unsigned char dispbuf[8]={0,0,0,0,0,0,10,10}; //显示码数组,因为只用了六个数码管,所以将最后两位赋值为10对应与段码0x00,表示不亮
unsigned char temp[8]; //暂存数组
unsigned char dispcount; //扫描位的记录
unsigned char T0count; //计数次数
unsigned char timecount; //定时器5ms中断的次数
bit flag; //定义标志位
unsigned long x; //定义变量用来存放频率值

void main(void)
{
unsigned char i;

TMOD=0x15; //定义定时器0为计数方式,定时器1为记时方式,均工作在方式1
TH0=0; //定时器0初值高8位为0
TL0=0; //定时器0初值低8位为0
TH1=(65536-5000)/256; //定时器1初值高8位
TL1=(65536-5000)%256; //定时器1初值低8位,即定时5ms
TR1=1;//启动定时器1
TR0=1;//启动定时器0
ET0=1;//开定时器0中断
ET1=1;//开定时器1中断
EA=1; //开总中断

while(1)
{
if(flag==1) //如果定时时间到了1s
{
flag=0; //标志位清零
x=T0count*65536+TH0*256+TL0; //获得整型的频率值,T0count计数器在1s内溢出的次数,每溢出一次就计数了T0count*65536次,再加上当前计数寄存器的值即为实际计数总数
for(i=0;i<8;i++)
{
temp[i]=0; //暂存缓冲区清零
}
i=0;
while(x/10) //将频率值的每一位分离出来,存进temp数组,例如63239分离为6、3、2、3、9
{
temp[i]=x%10;
x=x/10;
i++;
}
temp[i]=x;

for(i=0;i<6;i++)
{
dispbuf[i]=temp[i]; //将暂存数组的数据赋给显示数组
}
timecount=0; //记时清零
T0count=0; //计数清零
TH0=0; //定时器0初值清零
TL0=0; //定时器0初值清零
TR0=1; //重新启动定时器0,其实是作为计数器来用
}
}
}

void t0(void) interrupt 1 using 0 //每个计数中断一次
{
T0count++; //计数加一
}

void t1(void) interrupt 3 using 0 //5ms产生一次中断
{
TH1=(65536-5000)/256; //
TL1=(65536-5000)%256; //重装初值
timecount++;
if(timecount==200) //当timecount=200时,即为1s
{
TR0=0; //关闭定时器0,为了读出定时器0计数个数
timecount=0; //timecount清零,重新计时
flag=1; //置标志位通知主程序1s已到
}
/**********以下为数码管扫描部分**********/
//因为放在该中断程序中,故每5ms扫描一位数码管
P2=0xff; //先关闭所有数码管
P0=dispcode[dispbuf[dispcount]]; //先确定相应数码管的段码,送入段码
P2=dispbit[dispcount]; //送入位码
dispcount++; //下一次应该扫描下一位数码管所以要加一
if(dispcount==8) //因为共有8个数码管
{
dispcount=0; //扫描完第7个,回头扫描第0个
}
}
温馨提示:答案为网友推荐,仅供参考