基于51单片机的频率计设计c语言程序.docx
《基于51单片机的频率计设计c语言程序.docx》由会员分享,可在线阅读,更多相关《基于51单片机的频率计设计c语言程序.docx(15页珍藏版)》请在冰豆网上搜索。
![基于51单片机的频率计设计c语言程序.docx](https://file1.bdocx.com/fileroot1/2023-4/16/106bbd94-d1b3-443c-959d-e3cb5d8cef43/106bbd94-d1b3-443c-959d-e3cb5d8cef431.gif)
基于51单片机的频率计设计c语言程序
基于51单片机的频率计设计,c语言程序
代码1:
#include
#defineuintunsignedint
#defineucharunsignedchar
#defineulongunsignedlong
sbitdula=P2^6;
sbitwela=P2^7;
sbitkey1=P1^0;
sbitkey2=P1^1;
sbitkey3=P1^2;
uchartt=0,mode;
ulongnum,num1;
ucharcodeshu[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,
0x7c,0x39,0x5e,0x79,0x71};
voiddelay(uintz)
{
uinti,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
voiddisplay(uchara,ucharb,ucharc,uchard,uchare,ucharf)
{
dula=1;
P0=shu[a];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(3);
dula=1;
P0=shu[b];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(3);
dula=1;
P0=shu[c];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(3);
dula=1;
P0=shu[d];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(3);
dula=1;
P0=shu[e];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(3);
dula=1;
P0=shu[f];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(3);
}
ulongread()
{
uchart1,th1,th2;
uintval;
while
(1)
{
th1=TH1;
t1=TL1;
th2=TH1;
if(th1==th2)
break;
}
val=th1*256+t1;
returnval;
}
voidkeyscan()
{
if(key1==0)
{
mode=1;
TMOD=0X90;
TH1=0;
TL1=0;
ET1=1;
TR1=1;
EX1=1;
EA=1;
IT1=1;
ET0=0;
}
if(key2==0)
{
mode=2;
TMOD=0X51;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0;
TL1=0;
ET0=1;
ET1=1;
TR1=1;
TR0=1;
EX1=0;
EA=1;
}
if(key3==0)
{
mode=3;
TMOD=0X51;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0;
TL1=0;
ET0=1;
ET1=1;
TR1=1;
TR0=1;
EX1=0;
EA=1;
}
}
voidmain()
{
uintaa,bb,cc,dd,ee,ff;
while
(1)
{
keyscan();
if(mode==1)
{
aa=num/100000;
bb=num/10000%10;
cc=num/1000%10;
dd=num/100%10;
ee=num/10%10;
ff=num%10;
display(aa,bb,cc,dd,ee,ff);
}
if(mode==2)
{
num=num1*2;
aa=num/100000;
bb=num/10000%10;
cc=num/1000%10;
dd=num/100%10;
ee=num/10%10;
ff=num%10;
display(aa,bb,cc,dd,ee,ff);
}
if(mode==3)
{
num=500000/num1;
aa=num/100000;
bb=num/10000%10;
cc=num/1000%10;
dd=num/100%10;
ee=num/10%10;
ff=num%10;
display(aa,bb,cc,dd,ee,ff);
}
}
}
voidT0_time()interrupt1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
if(tt>=10)
{
tt=0;
num1=read();
TH1=0;
TL1=0;
}
}
voidexter()interrupt2
{
num=read()+1;
TH1=0;
TL1=0;
}
代码2:
#include
#defineuintunsignedint
#defineucharunsignedchar
#defineulongunsignedlong
sbitdula=P2^6;
sbitwela=P2^7;
sbitkey1=P1^0;
sbitkey2=P1^1;
sbitkey3=P1^2;
uchartt=0,mode;
ulongnum,num1;
ucharcodeshu[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,
0x7c,0x39,0x5e,0x79,0x71};
voiddelay(uintz)
{
uinti,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
voiddisplay(uchara,ucharb,ucharc,uchard,uchare,ucharf)
{
dula=1;
P0=shu[a];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(3);
dula=1;
P0=shu[b];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(3);
dula=1;
P0=shu[c];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(3);
dula=1;
P0=shu[d];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(3);
dula=1;
P0=shu[e];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(3);
dula=1;
P0=shu[f];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(3);
}
ulongread()
{
uchart1,th1,th2;
uintval;
while
(1)
{
th1=TH1;
t1=TL1;
th2=TH1;
if(th1==th2)
break;
}
val=th1*256+t1;
returnval;
}
voidkeyscan()
{
if(key1==0)
{
mode=1;
TMOD=0X90;
TH1=0;
TL1=0;
ET1=1;
TR1=1;
EX1=1;
EA=1;
IT1=1;
ET0=0;
}
if(key2==0)
{
mode=2;
TMOD=0X51;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0;
TL1=0;
ET0=1;
ET1=1;
TR1=1;
TR0=1;
EX1=0;
EA=1;
}
if(key3==0)
{
mode=3;
TMOD=0X51;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=0;
TL1=0;
ET0=1;
ET1=1;
TR1=1;
TR0=1;
EX1=0;
EA=1;
}
}
voidmain()
{
uintaa,bb,cc,dd,ee,ff;
while
(1)
{
keyscan();
P1=0xff;
if(mode==1)
{
key1=0;
aa=num/100000;
bb=num/10000%10;
cc=num/1000%10;
dd=num/100%10;
ee=num/10%10;
ff=num%10;
display(aa,bb,cc,dd,ee,ff);
}
if(mode==2)
{
key2=0;
num=num1*2+3;
aa=num/100000;
bb=num/10000%10;
cc=num/1000%10;
dd=num/100%10;
ee=num/10%10;
ff=num%10;
display(aa,bb,cc,dd,ee,ff);
}
if(mode==3)
{
key3=0;
num=500000/num1;
aa=num/100000;
bb=num/10000%10;
cc=num/1000%10;
dd=num/100%10;
ee=num/10%10;
ff=num%10;
display(aa,bb,cc,dd,ee,ff);
}
}
}
voidT0_time()interrupt1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
if(tt>=10)
{
tt=0;
num1=read();
TH1=0;
TL1=0;
}
}
voidexter()interrupt2
{
num=read()+1;
TH1=0;
TL1=0;
}