1 #include <reg51.h>
2 #include <string.h>
3 #include <math.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #define uchar unsigned char
7 #define uint unsigned int
8 #define ulong unsigned long
9
10 code uchar m[]={0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6,0x00};
11 // 0 1 2 3 4 5 6 7 8 9 灭
12 data uchar NS[]={0x0,0x0,0x0,0x0};//标准频率计数
13 data uchar NX[]={0x0,0x0,0x0,0x0};//待测频率计数
14 data ulong NSS,NXX,MM,F;
15 data ulong temp1,temp2;
16 data uchar shuju[]={0,0,0,0,0,0,0,0};//数码管数据
17 sbit CLR = P2^3;
18 sbit SEL2 = P2^2;
19 sbit SEL1 = P2^1;
20 sbit SEL0 = P2^0;
21 sbit CL = P2^4;
22 sbit START = P2^7;
23 //int i,j,k,l;
24 char *pNS;
//清零
25 char *pNSS;
26 char *pNX;
27 char *pNXX;
28
29 void delay(uint x);
30 void display();
31 void operation();
32 void outdata();
33
34 long powcyc(long c1,long c2)
35 {
36 long c3=1;
37 uchar ii;
38 for(ii=0;ii<c2;ii++)
39 {
40
41
c3*=c1; }
42 return c3;
43 }
44
45 void delay(uint x)
46 {
47 uchar j;
48 while((x--)!=0)
49 {
50 for(j=0;j<125;j++)
51
52
{;} }
53 }
54
55 void display()
56 {
57 uchar i;
58 for(i=0;i<8;i++)
59 {
60 TI=0;
61
62
63
SBUF=m[shuju[i]];
while(TI==0);
}
64 }
65
66
67 void outdata()
68 {
69
70
71
72
73
74
75
76
77
78 uchar i;
for(i=0;i<8;i++)
{
if(i==0)
{
shuju[0]=F/powcyc(10,7);
temp1=F%powcyc(10,7);
}
{
else
79 shuju[i]=temp1/powcyc(10,7-i);temp1=F%powcyc(10,7-i);
80 }
81 }
82 }
83 main()
84 {
85
86 uchar j,i,k,l; P0=0xff;
87 P2=0xff;
88
89 //Added by john 20060623 for(j=0;j<8;j++)
90 {
91 shuju[j] = 10; //all off
92 }
93 display();
94 delay(500); //delay 500ms
95
96 for(j=0;j<8;j++)
97 {
98
99
shuju[j] = j;
}
//0-7
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
display();
delay(500); //delay 500ms
for(j=0;j<8;j++)
{
shuju[j] = j + 2;
}
display();
delay(500);
//2-9
//delay 500ms for(i=0;i<3;i++)
{
for(j=0;j<8;j++)
{
shuju[j] = 11;
}
display();
delay(500);
//all on
//delay 500ms
for(j=0;j<8;j++)
{
shuju[j] = 10;
}
display();
delay(500);
}
//Added by john 20070623
while(1)
{
P0=0xff;
P2=0xff;
START=1;
display();
pNS=NS;
pNSS=&NSS;
pNX=NX;
pNXX=&NXX;
CLR=0;
CLR=1;
CLR=0;
CL=0;
CL=1;
delay(100);
CL=0;
//all off
//delay 500ms
if(START==0);
{
SEL2=SEL1=SEL0=0;
for(i=0;i<4;i++)
{NS[3-i]=P0;P2+=1;}
SEL2=1;SEL1=0;SEL0=0;
for(j=0;j<4;j++)
{NX[3-j]=P0;P2+=1;}
for(k=0;k<4;k++)
{*(pNSS+k)=*(pNS+k);}
for(l=0;l<4;l++)
157 {*(pNXX+l)=*(pNX+l);} 158 MM=NSS/NXX;
159 F=50000000/MM; 160 outdata();
161 162 } }
163 164 } 165。