新聞中心

        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 下一頁

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 柯坪县| 新泰市| 西和县| 信阳市| 朔州市| 苏州市| 梁平县| 大厂| 晋中市| 吉安县| 宜春市| 萍乡市| 青神县| 正宁县| 乌兰县| 札达县| 重庆市| 洛川县| 湘西| 苍梧县| 自治县| 凤阳县| 喀喇沁旗| 肃北| 波密县| 义乌市| 合水县| 永丰县| 和硕县| 安远县| 望谟县| 房山区| 进贤县| 香格里拉县| 乐昌市| 云龙县| 香港| 米泉市| 土默特右旗| 龙陵县| 凤冈县|