帮忙看看我写的频率计为什么没反应?

2019-03-24 19:43发布

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar shu=0,count=0;
uchar qian,bai,shi,ge;
long  f;
uchar code dutable[]={
0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};

void display(uchar qian,uchar bai,uchar shi,uchar ge);
void int0() interrupt 0
{
 TR1=1;
 shu++;
  if(shu==16)//计15
   shu=0;
  TR1=0;
  EX0=0;
}
void t0() interrupt 3
{
 count++;
}
void init()
{
 TMOD=0x10;
 TH1=0;
 TL1=0;
 IE=1;
 ET1=1;
 EX0=1;
 IT1=1;
}
void delay(uint z)
{
 uint x,y;
 for(x=z;x>0;x--)
  for(y=110;y>0;y--);
} void main()

 init();
 while(1)
 {    
 
   
  f=(count*65536+TH1*256+TL1)/15;
  f=1000000/f;
   qian=f/1000; 
   bai=f%1000/100;
   shi=f%100/10;
   ge=f%10;
 
  display(qian,bai,shi,ge);
  count=0;
  TH1=0;
  TL1=0;
  TR1=1;
  EX0=1;
 }
}
void display(uchar qian,uchar bai,uchar shi,uchar ge)
{
   P2=0x01;
 P0=dutable[qian];
 delay(5);
 
 P2=0x02;
 P0=dutable[bai];
 delay(5);  P2=0x04;
 P0=dutable[shi];
 delay(5);  P2=0x08;
 P0=dutable[ge];
 delay(5); 
} 写的是低频率计,加信号时没反应.如果要两位小数的,如何改??
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
_Justin
2019-03-25 05:06

说实话,没怎么看明白你的程序,首先当我看到你的main的时候,似乎EA=1你都不写!!我感觉有点蛋疼!那我看着你的程序写写吧,不知道行不行!对了,顺便说一下,我用的是T0和T1! 我没有仿真,不知道对不对,你可以试试,然后告诉我!至于那个小数点的,回头再说吧

 我又重新看了一下下,似乎有点不对。。。。你再试试这个

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar shu=0,count=0;
//sfr16 DPTR=0X82;//这个是用来存放定时器0中TH0,TL0中的值
uchar qian,bai,shi,ge;
long  f;
uchar code dutable[]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90};
void delay(uint z)
{
  uint x,y;
  for(x=z;x>0;x--)
   for(y=110;y>0;y--);
}

void init()
{
 IE=0X8A;
 TMOD=0X15;
 TH1=(65535-50000)/256;
 TL1=(65535-50000)%256;
 TR1=1;
 TH0=0;
 TL0=0;
 TR0=1; 
}
void display(uchar qian,uchar bai, uchar shi,uchar ge)
{
 P2=0X01;
 P0=dutable[qian];
 delay(5);
 
 P2=0X02;
 P0=dutable[bai];
 delay(5);
 
 P2=0X04;
 P0=dutable[shi];
 delay(5);
 
 P2=0X08;
 P0=dutable[ge];
 delay(5); 
}
void main()
{
 while(1)
 {
  init(); 
  if(shu==20)
  {
   shu=0;
   TR1=0;
//   delay(10); //这里是延时,矫正一下下误差,这种计数器准确率并不高!
   TR0=0;
//   DPL=TL0;
//   DPH=TH0;
//   f=DPTR;
   f=TH0*256+TL0;
   qian=f/1000;
   bai=f%1000/100;
   shi=f%100/10;
   ge=f%10;
  }
  display(qian,bai,shi,ge);
 }
}
void timer0() interrupt 1
{
 count++;
}
void timer1() interrupt 3
{
 TH1=(65535-50000)/256;
 TL1=(65535-50000)%256;
 shu++;  
}

[ 本帖最后由 _Justin 于 2011-10-9 10:53 编辑 ]

一周热门 更多>