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

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

        使用定時器中斷讓數碼管動態顯示做秒表

        作者:余春雨老師   來源:本站原創   點擊數:  更新時間:2014年04月26日   【字體:

        此程序的電路圖下載:http://www.thefapper.com/f/ks51.pdf   只需要看數碼管部分即可,其他部分可忽略掉. 

         

        #include <reg52.h>

        typedef unsigned char uchar;

        typedef unsigned int uint;

        typedef unsigned long ulong;

        sbit ENLED = P1^4;

        sbit ADDR0 = P1^0;

        sbit ADDR1 = P1^1;

        sbit ADDR2 = P1^2;

        sbit ADDR3 = P1^3;

        uchar led_char[] = {

        0xC0, 0xF9, 0xA4, 0xB0,

        0x99, 0x92, 0x82, 0xF8,

        0x80, 0x90, 0x88, 0x83,

        0xC6, 0xA1, 0x86, 0x8E};

        uchar led_buf[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};

        uchar cnt = 0;

        uchar key = 0;

        ulong sec = 0;

        void main()

        {

         

        EA = 1;

        ENLED = 0;

        ADDR3 = 1;

        TMOD = 0x10;

        TH1 = 0xEE;

        TL1 = 0x00;

        ET1 = 1;

        TR1 = 1;

        while(1)

        {

        if(200 == cnt)

        {

        cnt = 0;

        sec++;

        led_buf[0] = led_char[sec%10];

        led_buf[1] = led_char[sec/10%10];

        led_buf[2] = led_char[sec/100%10];

        led_buf[3] = led_char[sec/1000%10];

        led_buf[4] = led_char[sec/10000%10];

        led_buf[5] = led_char[sec/100000%10];

        }

        }

         

         

        }

        void interruptTimer0() interrupt 3

        {

          TH1 = 0xEE;

        TL1 = 0x00;

        cnt++;

        P0 = 0xFF;

        switch(key)

        {

        case 0: ADDR2 = 0;ADDR1 = 0;ADDR0 = 0;P0 = led_buf[0];key++;break;

        case 1: ADDR2 = 0;ADDR1 = 0;ADDR0 = 1;if(sec>9) P0 = led_buf[1];key++;break;

        case 2: ADDR2 = 0;ADDR1 = 1;ADDR0 = 0;if(sec>99) P0 = led_buf[2];key++;break;

        case 3: ADDR2 = 0;ADDR1 = 1;ADDR0 = 1;if(sec>999) P0 = led_buf[3];key++;break;

        case 4: ADDR2 = 1;ADDR1 = 0;ADDR0 = 0;if(sec>9999) P0 = led_buf[4];key++;break;

        case 5: ADDR2 = 1;ADDR1 = 0;ADDR0 = 1;if(sec>99999) P0 = led_buf[5];key = 0;break;

        default:break;

        }

        }

         
        關閉窗口

        相關文章

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