⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plj_zuizhongcx.c

📁 利用8051的定时器用来计数作为频率计的基础。测频范围是1--10000HZ
💻 C
字号:
 #include<reg51.h> 
unsigned char code dispbit[]={0x08,0x04,0x02,0x01,0x80,0x40,0x20,0x10};//	weixuantong
unsigned char code dispcode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80, 0x90}; 
static unsigned char dispbuf[6]={0,0,0,0,0,0};
static unsigned char temp[6]={0,0,0,0,0,0}; 
static unsigned int timecount=0;
//unsigned int T0count;

unsigned int x=0; 
unsigned long m=0; 
unsigned int n=0; 
unsigned int t=0;


void main(void) 
{
  unsigned char i=0;
  n=0;
  TMOD=0x15; 
  TH0=0;                      //T0jishu
  TL0=0; 
  TH1=0x3C; 
  TL1=0xAF;
  TR1=1; 
  TR0=1;
    
  ET0=1; 
  ET1=1;  
  EA=1;
  while(1) 
 { 
   for(i=0;i<6;i++)
   {
	temp[i]=m%10; 
    dispbuf[i]=temp[i];
    P2=dispbit[i];           //数码管显示
    P0=dispcode[dispbuf[i]]; //数码管显示
    m=m/10;
   }
   m=x+65536*t;
  
 }
}

void t1(void) interrupt 3 using 0 
{ 
  TH1=0x3C; 
  TL1=0xAF;
  timecount++;
  if(timecount==20) //中断250次后从0开始,即满1秒后就显示输出
    { 
      TR0=0; 
	  TR1=0;
	  t=n;
	  x=0;
	  x=TH0*256+TL0;
      m=0;
      m=x+65535*t;
	  TH1=0x3C; 
      TL1=0xAF;
	  TH0=0;
	  TL0=0;
	  n=0;
      timecount=0; 
	  TR0=1;
	  TR1=1;
    }
}
void timer0() interrupt 1
{
  TH0=0; 
  TL0=0;
  n++;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -