<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        頻率計程序

        作者:佚名   來源:本站原創   點擊數:  更新時間:2014年03月27日   【字體:

        下面是頻率計的電路圖 采用的是51單片機

         

        以下是程序源代碼:
         #include <reg52.h>
         #define  value P2
         #define  place  P0
         unsigned  char  d[4];
         usigned  char Num[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
         sbit  addrC=P1^0;
         sbit  addrB=P1^1;
          sbit  addrA=P1^2;
          sbit  clear=P1^3;

        sbit   ledG=P1^4;
         sbit   ledY=P1^5;
         sbit   ledR=P1^6;

        unsigned  char  count;
         unsigned  char  gears;
        unsigned  int  tN;
         unsigned  int fCnt;
         unsigned long regCnt;
         unsigned  int  pCnt;

        void Delay( unsigned  int  DelayTime)
        {
              while(DelayTime--);
        }
        void display()
        {
               if(gears==1)
                 {
                    d[3]=0;
                    d[2]=pCnt/100;
                    d[1]=(pCnt%100)/10;
                    d[0]=pCnt% 10;

                     place=0xfe;value=Num[d[3]];Delay(300);
                     place=0xfd;value=Num[d[2]];Delay(300); 
                     place=0xfb;value=Num[d[1]];Delay(300);
                     place=0xf7;value=Num[d[0]];Delay(300);
                
                     ledG=1;
                     ledY=1;
                     ledR=0;
        }

        else if(gears==2)
        {
              d[3]=pCnt/1000;
              d[2]=(pCnt%1000 )/100;
              d[1]=(pCnt%100)/10;
              d[0]=pCnt%10;

               place=0xfe;value=Num[d[3]];Delay(300);
               place=0xfd;value=Num[d[2]];Delay(300);
               place=0xfb;value=Num[d[1]]+0x80;Delay(300);
               place=0xf7;value=Num[d[0]];Delay(300);

                ledG=1;
                ledY=0;
                ledR=1;
        }
        else  if(gears==3)
        {
                    d[3]=pCnt/1000;
                    d[2]=(pCnt%1000)/100;
                    d[1]=(pCnt%100)/10;
                    d[0]=pCnt% 10;

                    place=0xfe;value=Num[d[3]]+0x80;Delay(300);
                    place=0xfd;value=Num[d[2]];Delay(300);
                    place=0xfb;value=Num[d[1]];Delay(300);
                    place=0xf7;value=Num[d[0]];Delay(300);

                    ledG=0;
                    ledY=1;
                    ledR=1;
        }
         else  if(gears==4)
        {
                    d[3]=0;
                    d[2]=0;
                    d[1]=0;
                    d[0]=0;

                    place=0xfe;value=Num[d[3]];Delay(300);
                    place=0xfd;value=Num[d[2]];Delay(300);
                    place=0xfb;value=Num[d[1]];Delay(300);
                    place=0xf7;value=Num[d[0]];Delay(300);

                    ledG=0;
                    ledY=0;
                    ledR=0;
             }
        }
         void  intialize()
        {
              clear=1;
              addrB=0;
              addrC=0;   
              addrA=0; 
         
              gears=1;
              ledG=1;
               ledY=1;
               ledR=0;
         
              TMOD=0X61;
               ET0=1;
               TR0=1;
               TH0=0x3c;
               TL0=0xb0 ;
                tN=20;
                ET1=1;
                TR1=1;
                TH1=0xff;
                 TL1=0xff;
                 EA=1;
        }
        void  main()
        {
           intialize();
           while(1)
              {
                   display();
               }
        }
         void  timer0() interrupt 1
        {
                 count++;
                 if(count==tN)
                 {
                      ET1=0 ;
                      TR1=0;
                    regCnt=fCnt;
                      fCnt =0;
                     count=0;
                     clear=0;
                     clear=1;
                     if(gears==1)
                       {
                            if(regCnt<1000)
                                    {
                                          pCnt=regCnt;
                                     }
                                      else
                                     {
                                           gears=2;
                                            addrA=1;
                                            TH1=0xec;
                                             TL1=0xec;
                                       }
                               }
                   else  if(gear==2 )
                       {
                               regCnt=regCnt*10*20/100;
                               if(regCnt<10000)
                                   {
                                        pCnt=regCnt;
                                     }
                                     else
                                       {
                                          gears=3;
                                           TH1=0xce;
                                           TL1=0xce;
                                          }
                                   }
                             else  if(gears==3)
                                    {  
                                       regCnt=regCnt*10*50/1000;
                                       if(regCnt<2500)
                                   {
                                        pCnt=regCnt;
                                     }
                                     else
                                       {
                                          gears=4; 
                                         }
                                       }
                                         ET1=1;
                                         TR1=1;
                                       }
                                            TH0=0x3c;
                                          //(65536-50000)/256
                                                 TL0=0xb0;
                                           //(65536-50000)%256
                                        }
                                
                                void  tally1()  interrupt  3
                                {
                                       fCnt++;
                                 }

         

        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮