低频计(0.00~99.99HZ)加入信号后一直显示0,希望大手给力

2019-03-24 19:40发布

低频计(0.00~99.99HZ)加入信号后一直显示0,希望大手给力贴代码,少废话//外部信号输入到INT1端口#include<reg52.h>#define uchar unsigned char#define uint unsigned int#define ulong unsigned longuint us100;     //对100us时间间隔单位计数,既有多少个100usuchar old_t0;     //外部频率输入时的T0值uchar old_us100;     //外部频率输入时的us100ulong f;     //存放频率值,单位HZuint qian,bai,shi,ge;uchar flag;     //标志位double f_temple; uchar code f_table[]={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 display(uint qian,uchar bai,uchar shi,uchar ge){ P2=0X01; P0=f_table[qian]; delay(5);
P2=0X02; P0=f_table[bai]+0x80; delay(5);
P2=0X04; P0=f_table[shi]; delay(5);
P0=0X08; P0=f_table[ge]; delay(5);} 
void init(){ TMOD=0X02; TH0=-100; TL0=-100; ET0=1; TR0=1; IT1=1; EX1=1; us100=0; flag=0; old_t0=0; old_us100=0; f_temple=0; f=0; EA=1;}
void t0_intr() interrupt 1{ us100++;}
void x1_intr() interrupt 2{ static uchar sts=0; uchar temp1,temp2; switch(sts) { case 0: sts=1; break; case 1: sts=2; TR0=0; old_t0=TL0; old_us100=us100; TR0=1; break; case 11: { TR0=0; temp1=TL0; temp2=us100; f_temple=(double)1000000/((temp2-old_us100)*100+(temp1-old_t0))/10; f=(ulong)f_temple*100; flag++; qian=f/1000; bai=f%1000/100; shi=f%100/10; ge=f%10;    TR0=1; } sts=0; break; } }
void main(){ init(); while(1) { if(flag!=0) { flag=0; display(qian,bai,shi,ge); } }}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
5条回答
_Justin
1楼-- · 2019-03-25 03:17
没人a!
自己顶!
_Justin
2楼-- · 2019-03-25 06:31

我都有点失望了!
baihushan2011
3楼-- · 2019-03-25 09:03
有再详细一点的说明没有?
骏驰飞车族
4楼-- · 2019-03-25 13:16
 精彩回答 2  元偷偷看……
51新手
5楼-- · 2019-03-25 17:58

#include <reg52.h>

#define uint unsigned int
#define uchar unsigned char

sbit E=P2^7;
sbit RW=P2^6;
sbit RS=P2^5;
sbit k1=P1^7;
sbit k2=P1^3;

unsigned long count;
uint n, ajcs, yc=0;
void delay(uchar z)
{
 uchar x, y;

 for (x = 110; x > 0; x--)
 {
  for (y = z; y > 0; y--);
 }
}

void writecom(uchar com)    //液晶的写指令
{
 RS=0;
 E=0;
 P0=com;
 delay(5);
 E=1;
 delay(5);
 E=0;  
}

void writedate(uchar date)     //液晶的写数据
{
 RS=1;
 E=0;
 P0=date;
 delay(5);
 E=1;
 delay(5);
 E=0;
}

void xianshi(uchar dz, unsigned long dx) //显示数字变化
{
 uint shiwan, wan, qian, bai, shi, ge;

 shiwan=dx/100000;
 wan=dx/10000%10;
 qian=dx/1000%10;
 bai=dx/100%10;
 shi=dx/10%10;
 ge=dx%10;

 writecom(0x80+dz);
 writedate(0x30+shiwan);
 writedate(0x30+wan);
 writedate(0x30+qian);
 writedate(0x30+bai);
 writedate(0x30+shi);
 writedate(0x30+ge); 
}
void inti1()  //液晶的初始化
{  
 RW=0;

 writecom(0x38);
 writecom(0x0c);
 writecom(0x06);
 writecom(0x01);
 writecom(0x80);
}

void inti2()      //中断的初始化
{
 EA=1;
 TMOD=0x51;
 TH0=0x4C;
 TL0=0x28;
 TH1=0;
 TL1=0;
 ET0=1;
 TR0=1;
 TR1=1;
}

void inti3()
{
 T2CON = 0x34;
  TH2 = 0xFF; 
  TL2 = 0xDC;
  RCAP2H = 0xFF;
  RCAP2L = 0xDC;
  SCON = 0x50;
  TR2 = 1;
 TI=1;

void fs(uchar x)
{
 while(TI == 0);  
 SBUF = x+0x30;
 TI = 0; 
}

void chuankou(unsigned long count)
{
 uint shiwan, wan, qian, bai, shi, ge;
 k1=0;
 
 shiwan=count/100000;
 wan=count/10000%10;
 qian=count/1000%10;
 bai=count/100%10;
 shi=count/10%10;
 ge=count%10;
 if (k2 == 0)
 {
  delay(5);
  if(k2==0)
  {
   ajcs++;
   while(!k2);
   if (ajcs==1)
   {
    ajcs=0;
    fs(shiwan);
    fs(wan);
    fs(qian);
    fs(bai);
    fs(shi);
    fs(ge);
    while(TI == 0);  
    SBUF = 'H';
    TI = 0;
    while(TI == 0);  
    SBUF = 'Z';
    TI = 0;
    while(TI == 0);  
    SBUF = ' ';
    TI = 0; 
   }
  }
 }
}

void timer0() interrupt 1
{
 n++;
 TH0=0x4C;
 TL0=0x28;
 if (TF1==1)
 {
  yc=yc+1;
  TF1=0;
 }  
 if(n==20)
 {
  n=0;
  EA=0;
   count=TH1*256+TL1+yc*65536;
  yc=0;
  TH1=0;
  TL1=0; 
  EA=1;
 }
}

void main()
{

 inti1();
 inti2();
 inti3();

 while(1)
 {
  chuankou(count);
  xianshi(2,count);
 }
}

 

一周热门 更多>