可以把基于单片机直流电机转速检测电路图和c语言程序发给我吗?我没分了,万分感谢,谢谢
#include<reg52.h>
#include <intrins.h>
#define TIME_CYLC 100
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
uchar qian,bai,shi,ge, mqian, mbai, mshi, mge,dj=10,timer2=0;
ulong num2=0,num=0,num1=0,timer1=0;
uint x;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f};
void shuma(uchar qian,uchar bai,uchar shi,uchar ge);
void shuma1(uchar mqian,uchar mbai,uchar mshi,uchar mge);
void delay(uchar);
sbit PWM=P1^0;
sbit zt=P1^7;//暂停
sbit jia=P1^3;//加设置
sbit jian=P1^4;//减设置
sbit M1=P1^1;//正极设?
sbit M2=P1^2;//负极设置
sbit fz=P1^6;//反转按键
sbit zf=P1^5;//正转按键
sbit jas=P3^7;//加速按键
sbit js=P3^6;//减速按键
bit biaozhi=0;//计算转速
void keyscan();
void main()
{
M1=1;
M2=0;
TMOD=0x01;
ET0=1;
EA=1; //开总中断
EX0=1;
IT0=1; //下降沿触发
TR0= 1;
x=0;
while(1)
{
keyscan();
shuma(qian,bai,shi,ge);
shuma1(mqian,mbai,mshi,mge);
if(timer1>100) timer1=0;//总周期T
if(timer1<dj) PWM=1;//获得低电平时间
else PWM=0;
if(biaozhi==1)
{ EA=0; //num2=num1*45;
num1=(x/10+0.6)*10-6;
delay(5);
x=0;
biaozhi =0;
timer2=0;
EA=1;
}
}
}
void shuma(uchar qian,uchar bai,uchar shi,uchar ge)//设定数码管显示
{
qian=num/1000;
bai=num/100%10;
shi=num%100/10;
ge=num%10;
P2=0xfe;
P0=table[qian];//送入段选数据4
delay(10);
P2=0xfd;
P0=table[bai];//送入段选数据3
delay(10);
P2=0xfb;
P0=table[shi];//送入段选数据2
delay(10);
P2=0xf7;
P0=table[ge];//送入段选数据1
delay(10);
}
void shuma1(uchar mqian,uchar mbai,uchar mshi,uchar mge)//实际转速显示
{
num2=60*num1;
mqian=num2/1000;
mbai=num2/100%10;
mshi=num2%100/10;
mge=num2%10;
P2=0xef;
P0=table[mqian];//送入段选数据4
delay(10);
P2=0xdf;
P0=table[mbai];//送入段选数据3
delay(10);
P2=0xbf;
P0=table[mshi];//送入段选数据2
delay(10);
P2=0x7f;
P0=table[mge];//送入段选数据1
delay(10);
P2=0xff;
P0=0xff;
delay(10);
}
/************************************* [T0(0.5ms)中断] 中断中做 PWM 输出(电机调速) *************************************/
void T0zd() interrupt 1 // 1为 定时器0的中断号
{ TF0=0; TH0 = 0xfe; //12
TL0 = 0x0c;
timer1++;
timer2++;
if(timer2>TIME_CYLC) //500um*100
{ biaozhi=1; //timer2=0;
}
}
void int0(void) interrupt 0 using 0
{ EX0=0;
x++; //中断计数
EX0=1;
}
/*键盘控制程序*/
void keyscan()//键盘扫描控制
{ if(zt==0) //暂停
{ delay(5);
if(zt==0)
{EA=~EA;
M1=0;
M2=0;
}
}
if(jia==0) //设定值增加
{ delay(10);
if(jia==0)
{++num;
if(num==3000)
num=0;
}
}
if(jian==0)//设定值减小
{ delay(10);
if(jian==0)
{ num--;
if(num==-1)
num=3000;
}
}
if(fz==0)//电机反转p1.5
{ delay(5);
if(fz==0)
{M1=0;
M2=1; //while(!zf);
}
}
if(zf==0)//电机正转p1.6
{ delay(5);
if(zf==0)
{ M1=1;
M2=0;
//while(!zf);
}
}
if(jas==0)//电机加速p3.7
{ delay(5);
if(jas==0)
{ if(dj<100)
dj++;
else dj=100;
}
}
if(js==0)//电机减速p3.6
{ delay(5);
if(js==0)
{
if(dj>0)
dj--;
else dj=0;
}
}
}
void delay(uchar a)//延时函数
{ uchar i,j;
for(i=a;i>0;i--)
for(j=110;j>0;j--);
}