基于51单片机的测速模块数码管显示
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
void delay(uint count)
{
uint i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}
void display(uint shi, uint ge)
{
P0=table[shi];dula=1;dula=0;
P0=0xfe; wela=1;wela=0;delay(5);
}
}
void time1() interrupt 3
{ TH1=(65536-46080)/256;
TL1=(65536-46080)%256;
pp++;
}
TL0=0;
TR0=1;
Init();
while(1)
{ if(pp==20)
{ pp=0;
num=read(); //脉冲个数
TH0=0;
TL0=0;
}
a=num/20.0;//转速
b=3.14*a*6*10;//速度cm/s
shi=b/100;
ge=(b-100*shi)/10;
display(shi,ge);
P0=table[ge]; dula=1;dula=0;
P0=0xfd; wela=1;wela=0;delay(5);
}
uint read()
{ uchar tl,th1,th2;
uint val;
while(1)
{ th1=TH0;
tl=TL0;
th2=TH0;
if(th1==th2)
break;
}
val=th1*256+tl;
return val;
}
void Init()
{ ET1=1;
TR1=1;
EA=1;
TH1=(65536-46080)/256;
TL1=(65536-46080)%256;
}wenku.baidu.com
void main()
{ float a,b;
uint num;
TMOD=0x15;
TH0=0;
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uint shi,ge,pp,val;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
{
uint i,j;
for(i=0;i<count;i++)
for(j=0;j<120;j++);
}
void display(uint shi, uint ge)
{
P0=table[shi];dula=1;dula=0;
P0=0xfe; wela=1;wela=0;delay(5);
}
}
void time1() interrupt 3
{ TH1=(65536-46080)/256;
TL1=(65536-46080)%256;
pp++;
}
TL0=0;
TR0=1;
Init();
while(1)
{ if(pp==20)
{ pp=0;
num=read(); //脉冲个数
TH0=0;
TL0=0;
}
a=num/20.0;//转速
b=3.14*a*6*10;//速度cm/s
shi=b/100;
ge=(b-100*shi)/10;
display(shi,ge);
P0=table[ge]; dula=1;dula=0;
P0=0xfd; wela=1;wela=0;delay(5);
}
uint read()
{ uchar tl,th1,th2;
uint val;
while(1)
{ th1=TH0;
tl=TL0;
th2=TH0;
if(th1==th2)
break;
}
val=th1*256+tl;
return val;
}
void Init()
{ ET1=1;
TR1=1;
EA=1;
TH1=(65536-46080)/256;
TL1=(65536-46080)%256;
}wenku.baidu.com
void main()
{ float a,b;
uint num;
TMOD=0x15;
TH0=0;
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
uint shi,ge,pp,val;
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};