哪位大侠帮我看看代码,有重谢
时间:10-02
整理:3721RD
点击:
- #include<reg52.h>
- #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};
- sbit wela = P2^7;
- sbit dula = P2^6;
- void delay_1ms(uint x)
- {
- uint i,j;
- for(j=0;j<x;j++)
- for(i=0;i<110;i++);
- }
- void delay_1ms(uint x)
- {
- uint i,j;
- for(j=0;j<x;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();
- }
- }
哪位大侠能跟我说错在哪,显示在数码管的值一直是63
不知道,有点看不太懂
我自己一直是用汇编写的,没怎么接触过C,能给我解释下你那里面变量的意义和整个程序做什么吗?