- #include
- #define uint unsigned int
- #define uchar unsigned char
- uint counter0=0,counter_0=0;
- //uchar table[5]={0},num;
- bit flag=0;
- unsigned long number=0,num;
- void display(uint,uint,uint,uint,uint) ;
- uint i,j,k,n,a1,a2,a3,fre,tt,ge,shi,bai,qian,wang;
- uchar code tabledu[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98};
- uchar code tablewe[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- ***it wela = P2^7;
- ***it dula = P2^6;
- void delay_1ms(uint x)
- {
- uint i,j;
- for(j=0;j
- for(i=0;i<110;i++);
- }
- void delay_1ms(uint x)
- {
- uint i,j;
- for(j=0;j
- for(i=0;i<110;i++);
- }
- /************频率检测阶段的定时器0和计数器1的设置*********/
- void init_time()
- {
-
- IT1=1; //下降沿触发外部中断
- EX1=1; //外部中断开
- TMOD=0x01;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256; //定时器0 5ms
- ET0=1; //开定时器0中断
- EA=1; //开总中断
-
- }
- void INT1_TIME() interrupt 2
- {
-
- counter_0++;
- TR0=1; ////当有外部中断时,开始定时器0;
-
- }
- void T0_time() interrupt 1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- counter0++;
-
- }
- void display(uint ge,uint shi,uint bai,uint qian,uint wang)
- { dula=1;
- P0=tabledu[ge];
- dula=0;
- P0=0xff;
- wela=1;
- P0=tablewe[7];
- wela=0;
- delay_1ms(5);
- dula=1;
- P0=tabledu[shi];
- dula=0;
- P0=0xff;
- wela=1;
- P0=tablewe[6];
- wela=0;
- delay_1ms(5);
- dula=1;
- P0=tabledu[bai];
- dula=0;
- P0=0xff;
- wela=1;
- P0=tablewe[5];
- wela=0;
- delay_1ms(5);
- dula=1;
- P0=tabledu[qian];
- dula=0;
- P0=0xff;
- wela=1;
- P0=tablewe[4];
- wela=0;
- delay_1ms(5);
- dula=1;
- P0=tabledu[wang];
- dula=0;
- P0=0xff;
- wela=1;
- P0=tablewe[3];
- wela=0;
- delay_1ms(5);
-
- }
- void Dkisplay()
- {
-
-
- wang=number/10000;
- qian=number%10000/1000;
- bai=number%1000/100;
- shi=number%100/10;
- ge=number%10/1;
- display(ge,shi,bai,qian,wang);
-
-
- }
- void main()
-
- {
- init_time();
- dula=0;
- wela=0;
- while(1)
- {
- if(counter_0==1)
- {
- TR0=0;///关闭计数器0;
- num=TH0*256+TL0+counter0*65536;
- number=1000000/num;/////number=频率,机器周期1us,number=1/(num*0.000001)
- counter0=0;
- TR0=1;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- counter_0=0;
-
- }
- Dkisplay();
- }
- }
复制代码
|