|
电路原理图如下:
//************************
authour:yeah
//************************
用数码管显示频率直接上源码:
- #include<reg52.h>
- sfr AUXR = 0x8E ;
- sfr P0M0 = 0x93 ;
- sfr P0M1 = 0x94 ;
- sfr P2M0 = 0x95 ;
- sfr P2M1 = 0x96 ;
- sbit P00 = P0^0;
- sbit P01 = P0^1;
- sbit P02 = P0^2;
- sbit P03 = P0^3;
- sbit P04 = P0^4;
- sbit P05 = P0^5;
- sbit P06 = P0^6;
- sbit P07 = P0^7;
- sbit P10 = P1^0;
- sbit P11 = P1^1;
- sbit P12 = P1^2;
- sbit P13 = P1^3;
- sbit P14 = P1^4;
- sbit P15 = P1^5;
- sbit P16 = P1^6;
- sbit P17 = P1^7;
- sbit P20 = P2^0;
- sbit P21 = P2^1;
- sbit P22 = P2^2;
- sbit P23 = P2^3;
- sbit P24 = P2^4;
- sbit P25 = P2^5;
- sbit P26 = P2^6;
- sbit P27 = P2^7;
- sbit P33 = P3^3;
- int length=20080; //时间长度计数值
- int hz_length;
- float hz_length1,cha;
- unsigned char code Tab[]={0x5F,0x06,0x9B,0x8F,0x0C6,0x0CD,0x0DD,0x07,0x0DF,0x0CF};
- char cishu=0;
- int QIAN,BAI,SHI,G;
- char BIT_COUNT=0;
- int a,b,low,high;
- void main()
- {
- P2M0=0x00;
- P2M1=0xFF;
- P0M0=0x00;
- P0M1=0xFF;
- P0=0x00 ;
- AUXR=0x00 ;
- TMOD=0x10 ;
- TH0=0xEC;
- TL0=0x78;
- EA=1;
- EX1=1;
- IT1=1;
- ET0=1;
- TR0=1;
- PX1=1;
- P33=1;
- while(1)
- ;
- }
- void int1(void) interrupt 2
- {
- if(cishu==0)
- {
- TH1=0;
- TL1=0;
- TR1=1;
- cishu=1;
- }
- else if(cishu==1)
- {
- TR1=0;
- high=TH1;
- low=TL1;
- a=low/16;
- b=low-a*16;
- length=a*16+b;
- a=high/16;
- b=high-16*a;
- length=length+b*16*16+a*16*16*16;
- cishu=0;
- }
-
- }
- /*
- 显示
- */
- void Time0(void) interrupt 1
- {
- hz_length1=(1000000.0/length); //转化为HZ
- hz_length=1000000/length;
- cha=hz_length1-length;
- if (cha>=0.5)
- hz_length=hz_length+1;
- QIAN=(int)(hz_length/1000);
- BAI=(int)((hz_length-1000*QIAN)/100);
- SHI=(int)((hz_length-1000*QIAN-100*BAI)/10);
- G=(int)(hz_length-1000*QIAN-100*BAI-10*SHI);
- if(BIT_COUNT==0)
- {
- P04=0;
- if (QIAN==0)
- {
- P2=0x00;
- P07=0;
- BIT_COUNT=BIT_COUNT+1;
- }
- else
- {
- P2=Tab[QIAN];
- P07=1;
- BIT_COUNT=BIT_COUNT+1;
- }
- }
- else if(BIT_COUNT==1)
- {
- P07=0;
- if((QIAN==0)&&(BAI==0))
- {
- P2=0x00;
- P06=0;
- BIT_COUNT=BIT_COUNT+1;
- }
- else
- {
- P2=Tab[BAI];
- P06=1;
- BIT_COUNT=BIT_COUNT+1;
- }
- }
- else if(BIT_COUNT==2)
- {
- P06=0;
- P2=Tab[SHI];
- P05=1;
- BIT_COUNT=BIT_COUNT+1;
- }
- else if(BIT_COUNT==3)
- {
- BIT_COUNT=0;
- P05=0;
- P2=Tab[G];
- P04=1;
- }
复制代码
|
-
-
原理图.doc
61.5 KB, 下载次数: 8, 下载积分: 黑币 -5
评分
-
查看全部评分
|