基于51单片机的频率计设计-c语言程序PDF.pdf
基于 51 单片机的频率计设计,c 语言程序代码 1:#include #define uint unsigned int #define uchar unsigned char #define ulong unsigned long sbit dula=P26; sbit wela=P27; sbit key1=P10; sbit key2=P11; sbit key3=P12; uchar tt=0,mode; ulong num,num1; uchar code shu=0 x3f,0 x06,0 x5b,0 x4f, 0 x66,0 x6d,0 x7d,0 x07,0 x7f,0 x6f,0 x77, 0 x7c,0 x39,0 x5e,0 x79,0 x71; void delay(uint z) uint i,j; for(i=z;i0;i-) for(j=110;j0;j-); void display(uchar a,uchar b,uchar c,uchar d,uchar e,uchar f) dula=1; P0=shua; dula=0; P0=0 xff; wela=1; P0=0 xfe; wela=0; delay(3); dula=1; P0=shub; dula=0; P0=0 xff; wela=1; P0=0 xfd; wela=0; delay(3); dula=1; P0=shuc; dula=0; P0=0 xff; wela=1; P0=0 xfb; wela=0; delay(3); dula=1; P0=shud; dula=0; P0=0 xff; wela=1; P0=0 xf7; wela=0; delay(3); dula=1; P0=shue; dula=0; P0=0 xff; wela=1; P0=0 xef; wela=0; delay(3); dula=1; P0=shuf; dula=0; P0=0 xff; wela=1; P0=0 xdf; wela=0; delay(3); ulong read() uchar t1,th1,th2; uint val; while(1) th1=TH1; t1=TL1; th2=TH1; if(th1=th2) break; val=th1*256+t1; return val; void keyscan() 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; void main() uint aa,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); void T0_time() interrupt 1 TH0=(65536-50000)/256; TL0=(65536-50000)%256; tt+; if(tt=10) tt=0; num1=read(); TH1=0; TL1=0; void exter() interrupt 2 num=read()+1; TH1=0; TL1=0; 代码 2:#include #define uint unsigned int #define uchar unsigned char #define ulong unsigned long sbit dula=P26; sbit wela=P27; sbit key1=P10; sbit key2=P11; sbit key3=P12; uchar tt=0,mode; ulong num,num1; uchar code shu=0 x3f,0 x06,0 x5b,0 x4f, 0 x66,0 x6d,0 x7d,0 x07,0 x7f,0 x6f,0 x77, 0 x7c,0 x39,0 x5e,0 x79,0 x71; void delay(uint z) uint i,j; for(i=z;i0;i-) for(j=110;j0;j-); void display(uchar a,uchar b,uchar c,uchar d,uchar e,uchar f) dula=1; P0=shua; dula=0; P0=0 xff; wela=1; P0=0 xfe; wela=0; delay(3); dula=1; P0=shub; dula=0; P0=0 xff; wela=1; P0=0 xfd; wela=0; delay(3); dula=1; P0=shuc; dula=0; P0=0 xff; wela=1; P0=0 xfb; wela=0; delay(3); dula=1; P0=shud; dula=0; P0=0 xff; wela=1; P0=0 xf7; wela=0; delay(3); dula=1; P0=shue; dula=0; P0=0 xff; wela=1; P0=0 xef; wela=0; delay(3); dula=1; P0=shuf; dula=0; P0=0 xff; wela=1; P0=0 xdf; wela=0; delay(3); ulong read() uchar t1,th1,th2; uint val; while(1) th1=TH1; t1=TL1; th2=TH1; if(th1=th2) break; val=th1*256+t1; return val; void keyscan() 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; void main() uint aa,bb,cc,dd,ee,ff; while(1) keyscan(); P1=0 xff; 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); void T0_time() interrupt 1 TH0=(65536-50000)/256; TL0=(65536-50000)%256; tt+; if(tt=10) tt=0; num1=read(); TH1=0; TL1=0; void exter() interrupt 2 num=read()+1; TH1=0; TL1=0;