專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

51單片機(jī)數(shù)字頻率計(jì)-帶仿真文件

作者:佚名   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2012年07月08日   【字體:

51單片機(jī)做的數(shù)字頻率計(jì),源程序和仿真圖請(qǐng)從下面的鏈接下載:
http://www.torrancerestoration.com/f/51數(shù)字頻率計(jì).rar

#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
unsigned char code dispbit[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//共陰數(shù)碼管
unsigned char code dispcode[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//顯示0-9
unsigned char count[8]={0,0,0,0,0,0,0,0};
unsigned int T0count=0;
unsigned char  time1tick=0;
unsigned char i=0;
unsigned long  x;

void pulse_init(void)
{
 TMOD=0x16;//T0工作在方式2,計(jì)數(shù)器模式
 TH0=0x00;
 TL0=0x00;
 TH1=0xb1;//20ms中斷一次
 TL1=0xe0;
 ET0=1;
 ET1=1;
 EA=1;

}
void delay(uint ms)
{
 unsigned char i,j;
 for(i=0;i<ms;i++)
  for(j=0;j<250;j++)
  {
   _nop_();
   _nop_();
   _nop_();
   _nop_();
  }
}
static void time0_int(void) interrupt 1 using 0
{

 T0count++; //T0為計(jì)數(shù)器模式
}

void t1(void) interrupt 3 using 0

  time1tick++;
  TH1=0xb1;//20ms中斷一次
  TL1=0xe0;
  if(time1tick==50)//定時(shí)1s
  {
      time1tick=0;
         EA=0;      
         TR0=0;
   TR1=0;
          
       
        
  }  
 
 
}

void display(void)
{       
                x=256*T0count+TL0-4; //轉(zhuǎn)換成10進(jìn)制
                x=x/17.3;
  i=7;//數(shù)碼管的顯示高位表示數(shù)據(jù)的低位
  while(x)//賦值
  {
   count[i]=x%10;
   x=x/10;
   i--;
  }
   count[i]=x;
  for(i=0;i<8;i++)
  {
     P1=dispbit[i];
   P0=dispcode[count[i]];
   delay(1);
  }
 
}
void main()
{
  pulse_init();
  TR1=1;//開啟timer
  TR0=1;
  while(1)display();
}
 

關(guān)閉窗口

相關(guān)文章