新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 51單片機時鐘秒表課程設計

        51單片機時鐘秒表課程設計

        作者: 時間:2016-11-29 來源:網絡 收藏

        void Delayms(int ms)

        {

        while(ms)

        {

        unsigned char i;

        ms--;

        for (i=0; i<240; i++);

        }

        }

        void display()

        {

        char v,c;

        P3=0x11;

        v=Leds[Ledc];

        c=LEDTAB[v & 0x0f];

        if (v&0x10) c|=0x80;

        P2=c;

        P3=Ledc;

        Ledc++;

        if (Ledc>=8) Ledc=0;

        }

        void readkey() //讀按鍵

        {

        if(start==0) isStart = 1; //真為開始

        if(stop==0) isStart = 0; //假為停止

        if(key0 == 0) num_count = stu_num0; //選擇曾路榮

        if(key1 == 0) num_count = stu_num1;//選擇張洪榮

        if(key2 == 0) num_count = stu_num2;

        if(key3 == 0) num_count = stu_num3;

        if(key4 == 0) num_count = stu_num4;

        if(key5 == 0) num_count = stu_num5;

        }

        void t0int() interrupt 1 //1ms定時器中斷服務函數

        {

        TH0=(-1000)>>8;

        TL0=-1000;

        display();

        readkey();

        T1msc++;

        if (isStart) //開始倒計時

        {

        if ((T1msc%100)==0) //滿 0.1秒

        {

        temp--;

        if(temp==-1)

        {

        num_count--;

        temp = 10; //0.1秒恢復9

        }

        }

        if(num_count == -1) //

        {

        num_count = 99;

        num--;

        if(num == -1) num = 99;

        }

        }

        if (T1msc>=1000)

        {

        T1msc=0;

        }

        }

        void NumToLeds()

        {

        Leds[1]=num/10%10;

        Leds[2]=num%10;

        Leds[3]=num_count/10%10;

        Leds[4]=num_count%10+0x10;

        Leds[5]=temp; //0.1秒顯示

        }

        void main()

        {

        Delayms(10);

        TMOD=0x01;

        TR0=1;

        ET0=1;

        EA=1;

        while(1)

        {

        NumToLeds(); //送數據

        }

        }


        上一頁 1 2 下一頁

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 闽侯县| 汶上县| 台湾省| 武清区| 义乌市| 临安市| 福州市| 鞍山市| 南皮县| 大英县| 广昌县| 扎鲁特旗| 福建省| 宁河县| 新龙县| 胶南市| 新绛县| 玛沁县| 日照市| 牟定县| 漯河市| 东台市| 古丈县| 扬州市| 兴国县| 保定市| 乌拉特中旗| 久治县| 峨眉山市| 利川市| 安乡县| 宣汉县| 兴仁县| 蓬溪县| 江北区| 新干县| 阿拉善右旗| 梨树县| 和静县| 梁河县| 郸城县|