找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 3671|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

基于51的頻率器分享(自動(dòng)換擋,每秒自動(dòng)更新)。入門欣賞用

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:76190 發(fā)表于 2015-4-5 18:15 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
//功能:4位數(shù)碼管顯示頻率,單位KHZ。 比如顯示 0.005=5HZ   00.05=50HZ   000.5=500HZ   0005.=5000HZ
//硬件:2051單片機(jī),P1.6到P1.0分別是 A到G,P1.7=DP,P3.5=D4,P3.4=D3,P3.1=D2,P3.0=D1
//       晶振;12Mhz
//使用說(shuō)明:自動(dòng)換擋,每秒自動(dòng)更新輸入頻率
//注明:該程序不是最終程序,更新程序請(qǐng)聯(lián)系中山董豪
//建議改進(jìn)增加晶振到24MHZ,以提高量程。
#include <reg52.h>               
#define uint unsigned int        
#define uchar unsigned char     

uchar one,two,three,four,five,six,seven;    //SEVEN最高位
uchar oneo,twoo,threeo,fouro,fiveo,sixo,seveno;
uchar dp4,dp3,dp2,dp1;
                                                                                                   

uchar code display[]={0x7E,0x30,0x6D,0x79,0x33,0x5B,0x5F,0x70,0x7F,0x7B,0x00}; //七段譯碼 P1.6=A
sbit DP=P1^7;
sbit P3_0=P3^0;
sbit P3_1=P3^1;
sbit P3_4=P3^4;
sbit P3_5=P3^5;
void main()
{   TMOD=0X11;
EA=1;
ET0=1; //1S   ,change gear
ET1=1; //DISPLAY
EX0=1; //INPUT : counter
IT0=1;   
PT0=1;
PX0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-6000)/256;
TL1=(65536-6000)%256;
TR0=1;
TR1=1;
while(1);
}

void int0() interrupt 0 using 0   
{ ////////////////////////////////////////////////////////////////// counter
   if(one<9)
   one++;
else
{one=0;
   if(two<9)
   two++;
   else
   {two=0;
    if(three<9)
    three++;
    else
    {three=0;
     if(four<9)
     four++;
     else
     {four=0;
      if(five<9)
      five++;
      else
      {five=0;
       if(six<9)
       six++;
       else
       {six=0;
        if(seven<9)
         seven++;
         else
         seven=0;
         //真實(shí)情況沒(méi)可能達(dá)到該值,12MHZ的機(jī)器頻率才1MHZ
          }
      }
     }
    }
   }
}
////////////////////////////////////////////////////////////////////////////// counter

}//int0 counter  


void timer0() interrupt 1 using 1           //1s
{ uchar i;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
   i++;
if(i==20)//1s
{
i=0;
////////////////////////////////////////////////////////////////////////////// change gear
   if(seven!=0)
    { oneo=four;
     twoo=five;
     threeo=six;
     fouro=seven;
     dp4=0;
     dp3=0;
     dp2=0;
     dp1=1; //0000.   千位
    }
   else if(six!=0)
    { oneo=three;
     twoo=four;
     threeo=five;
     fouro=six;
     dp4=0;
     dp3=0;
     dp2=1;
     dp1=0; //000.0   百位
    }
   else if(five!=0)
    { oneo=two;
     twoo=three;
     threeo=four;
     fouro=five;
        dp4=0;
     dp3=1;
     dp2=0;
     dp1=0; //00.00   十位
    }
      else
    { oneo=one;
     twoo=two;
     threeo=three;
     fouro=four;                                          
     dp4=1;
     dp3=0;
     dp2=0;
     dp1=0; //0.000   個(gè)位
    }

////////////////////////////////////////////////////////////////////////////// change gear
one=0;
two=0;
three=0;
four=0;
five=0;
six=0;
seven=0;
////////////////////////////////////////////////////////////////////////////////////1s
}
}//timer0 1s

void timer1() interrupt 3 using 3    //display
{    uchar j;
TH1=(65536-6000)/256;
TL1=(65536-6000)%256;

      if(j<4)
       j++;
      else
        j=1;
    ///////////////////////////////////////
         if(j==1)
          {
      P1=display[oneo];
     DP=dp1;
            }
      else if(j==2)
             {
      P1=display[twoo];
     DP=dp2;
        }
          else if(j==3)
             {
      P1=display[threeo];
      DP=dp3;
       }
       else if(j==4)
             {
      P1=display[fouro];
         DP=dp4;
       }


////////////////////////////////////////////////select
   if(j==1)
    {P3_0=0;P3_1=1;P3_4=1;P3_5=1;}
   else if(j==2)
    {P3_0=1;P3_1=0;P3_4=1;P3_5=1;}
   else if(j==3)
    {P3_0=1;P3_1=1;P3_4=0;P3_5=1;}
   else if(j==4)
    {P3_0=1;P3_1=1;P3_4=1;P3_5=0;}
//////////////////////////////////////////////

}//timer1 display

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:77387 發(fā)表于 2015-5-10 11:51 | 只看該作者
不是太懂啊
回復(fù)

使用道具 舉報(bào)

板凳
ID:75172 發(fā)表于 2015-5-30 10:20 | 只看該作者
無(wú)圖無(wú)真相啊
回復(fù)

使用道具 舉報(bào)

地板
ID:73994 發(fā)表于 2015-5-31 10:08 | 只看該作者
感覺(jué)很復(fù)雜的的  有點(diǎn)迷糊
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表