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

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

        單片機C語言頻率計源碼

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

         此程序是在51hei單片機開發板上面做的,如需要移植到自己的電路上,修改相應的端口即可,開發板完整的電路圖下載:  點這里 (注意:只需要看相關部分即可,其他部分可以忽略)

        //********************************頻率計*********************************
        //*******************************計數最大值1MHZ***************************
        //*****************************手把手教你單片機開發板**********************
        //*********************************2012/9/8***********************
        #include <reg52.h>
         
        typedef unsigned char uint8;
        typedef unsigned int  uint16;
        typedef unsigned long uint32;
         
        uint8 code block[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf};
         
        uint8 a[6];
        uint16 counter=0;
         
        sbit ADDR0 = P1^0; //A0 
        sbit ADDR1 = P1^1; //A1
        sbit ADDR2 = P1^2; //A2
        sbit ADDR3 = P1^3; //E1|E2
        sbit ENLED = P1^4; //E3**38譯碼器######
        sfr16 DPTR  = 0x82;
         
        void refresh_LS();
        void timer1_int_init()
        {
        TMOD = 0x51;
        TH1  = 0x00;
        TL1  = 0x00;
        TR1  = 1;
        EA   = 1;
        ET0  = 1;
         
        }
        void timer0_init()
        {
        TH0  = 0xfe;
        TL0  = 0x33;
        TR0  = 1;  
        }
         
        void interrupt_SHOW() interrupt 1
        {
        static uint8 i=0;
        static uint32 record=0;
           TH0 = 0xFE;
           TL0 = 0x33;
        counter++;
        DPL = TL1;
        DPH = TH1;
        if(DPTR==50000)
        {
        i++;
        TH1 = 0x00;
        TL1 = 0x00;
        }
        record=(i>=1)?i*50000:DPTR;
         if(counter == 2000)
        {
          i=0;
          counter=0;
          if(record == 1000000)
          {
           a[0] = 11;
        a[1] = 11;
        a[2] = 11;
        a[3] = 11;
        a[4] = 11;
        a[5] = 1;
          }
          else
            {
        a[0] = record%10;
        a[1] = record/10%10;
        a[2] = record/100%10;
        a[3] = record/1000%10;
        a[4] = record/10000%10;
        a[5] = record/100000%10;
        }
        record=0;
        TH1 = 0x00;
        TL1 = 0x00;
         
        }
        refresh_LS();
        }
        void refresh_LS()
        {
        static uint8 j=0;
        switch(j)
        {
        case 0: ADDR0 = 0; ADDR1 = 0; ADDR2 = 0; P0 = block[a[0]]; j++; break;
        case 1: ADDR0 = 1; ADDR1 = 0; ADDR2 = 0; P0 = block[a[1]]; j++; break;
        case 2: ADDR0 = 0; ADDR1 = 1; ADDR2 = 0; P0 = block[a[2]]; j++; break;
        case 3: ADDR0 = 1; ADDR1 = 1; ADDR2 = 0; P0 = block[a[3]]; j++; break;
        case 4: ADDR0 = 0; ADDR1 = 0; ADDR2 = 1; P0 = block[a[4]]; j++; break;
        case 5: ADDR0 = 1; ADDR1 = 0; ADDR2 = 1; P0 = block[a[5]]; j=0; break;
        default:break; 
        }
        }
         
        main()
        {
        ENLED = 0; ADDR3 = 1;
        timer1_int_init();
        timer0_init();  
        while(1);
        }
        關閉窗口

        相關文章

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