这是个调速系统的C语言程序,谁能帮我注解一下各语句的主要功能

主要是测试电动机的转速,然后显示到液晶屏上面

#include <reg51.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
#define ON 0
#define OFF 1
sbit PWM=P3^5;
sbit MP=P3^4;
bit FLAG=0;
uchar code dispbit[6]={0x20,0x10,0x08,0x04,0x02,0x01};

uchar code seg[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
//0,1,2,3,4,5,6,7,8,9
uchar disbuf[6]={0,0,0,0,10,10};
uint temp[6];
uint discount=0;
uint timecount=0;//定时的次数
uint T0count=0;
uint hus=0;
uint k=60;
uint Vc;
uint Vs;
uint tm=3000;
uint x;
void t0_serv() interrupt 1
{ T0count++;
}
void t1_serv() interrupt 3
{
PWM=1;
TH1=(65536-tm)/256;
TL1=(65536-tm)%256;
hus++;
if(hus==tm)
{ PWM=0;
TH1=(25536+tm)/256;
TL1=(25536+tm)%256;

}
timecount++;
if(timecount==250)
{
//FLAG=1;
TR0=0;
hus=0;
timecount=0;
Vc=T0count*65536+TH0*256+TL0;
Vs=144;
if(abs(Vc-Vs)>5)
{ tm=abs(k*(Vc-Vs));
T0count=0;
TR0=1;
TR1=1;
ET0=1;
ET1=1;
EA=1;
}
FLAG=1;
TR0=0;
timecount=0;
}
P0=dispbit[discount];
P1=seg[disbuf[discount]];
discount++;
if(discount==6)
{ discount=0;
}
}
void main()
{ uint i;
TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-tm)/256;
TL1=(65536-tm)%256;
TR0=1;
TR1=1;
ET0=1;
ET1=1;
EA=1;
while(1)
{ if(FLAG==1)
{ FLAG=0;
x=T0count*65536+TH0*256+TL0;
for(i=0;i<6;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++)
{
disbuf[i]=temp[i];
}

timecount=0;
T0count=0;
TH0=0;
TL0=0;
T0count=0;
TR0=1;

}
}

}
怎么给 怎么联系你

呵呵,这个是一个单片机的问题,我可以给你解释,但是必须把分给我
#include <reg51.h> 头文件包含
#include <math.h>
#define uchar unsigned char 用Uchar 定义unsigned char
#define uint unsigned int
#define ON 0 //电动机开关的宏
#define OFF 1
sbit PWM=P3^5; //与电动机通信的端口 定时器1外部中断
sbit MP=P3^4; //定时器0外部中断
bit FLAG=0; //数据是否需要显示的标志
uchar code dispbit[6]={0x20,0x10,0x08,0x04,0x02,0x01}; //选择led的六个中的一个

uchar code seg[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};//0——9显示代码
//0,1,2,3,4,5,6,7,8,9
uchar disbuf[6]={0,0,0,0,10,10}; //数据缓冲区,j就是屏幕显示的缓冲数据
uint temp[6]; //显示速度分成显示字符的缓冲区
uint discount=0; //显示位数的定位
uint timecount=0; //定时的次数
uint T0count=0; //to计数器的溢出次数
uint hus=0;
uint k=60;
uint Vc;
uint Vs;
uint tm=3000; //外部定时器1的初始值,就是测转最多多少次
uint x;
void t0_serv() interrupt 1 //外部定时器0中断延时定时器到了,TOCUNT加一,时间
{ T0count++;
}
void t1_serv() interrupt 3 //外部定时器1中断延时定时器到了响应中断
{
PWM=1;
TH1=(65536-tm)/256; /定时器1初始化
TL1=(65536-tm)%256;
hus++;
if(hus==tm) //是否到3000次
{ PWM=0;
TH1=(25536+tm)/256; //定时器0初始化
TL1=(25536+tm)%256;

}
timecount++; //时间加一
if(timecount==250) //最多多少时间
{
//FLAG=1; //需要显示啦
TR0=0; //初始化
hus=0;
timecount=0;
Vc=T0count*65536+TH0*256+TL0;
Vs=144;
if(abs(Vc-Vs)>5) //得到的值与144相比
{ tm=abs(k*(Vc-Vs));
T0count=0;
TR0=1;
TR1=1;
ET0=1;
ET1=1;
EA=1;
}
FLAG=1;
TR0=0;
timecount=0;
}
P0=dispbit[discount];
P1=seg[disbuf[discount]];
discount++;
if(discount==6)
{ discount=0;
}
}
void main()
{ uint i;
TMOD=0x15; //设置定时器启动模式
TH0=0;//定时器0的初始值
TL0=0;
TH1=(65536-tm)/256;//定时器1的初始值
TL1=(65536-tm)%256;
TR0=1; //启动定时器
TR1=1;
ET0=1;//启动两个中断
ET1=1;
EA=1; //开中断
while(1)
{ if(FLAG==1)
{ FLAG=0;
x=T0count*65536+TH0*256+TL0;//显示初始化 0
for(i=0;i<6;i++)
{temp[i]=0;
}
i=0;
while(x/10)
{
temp[i]=x%10;//将x放入缓冲区
x=x/10;
i++;
}
temp[i]=x;
for(i=0;i<6;i++)
{
disbuf[i]=temp[i];//将临时缓冲区的数据放入显示缓冲区
}

timecount=0;//定时器的归零初始化
T0count=0;
TH0=0;
TL0=0;
T0count=0;
TR0=1;

}
}

}
温馨提示:答案为网友推荐,仅供参考
相似回答