標題: 單片機數(shù)碼管秒表程序 [打印本頁]

作者: v如此富有覅    時間: 2022-4-18 13:24
標題: 單片機數(shù)碼管秒表程序
制作一個數(shù)碼管秒表,用兩個led數(shù)碼管顯示,最小計時單位為100ms,范圍為0.1-9.9s,按下第一個功能鍵后開始計時,第二次按下時停止

#include <reg51.h>
unsigned char code discode1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
unsigned char code discode2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char timer=0;
unsigned char second;
unsigned char key=0;
main()
{
        TMOD=0x01;
        ET0=1;
        EA=1;
        second=0;
        P0=discode1[second/10];
        P2=discode2[second%10];
        while(1)
        {
                if((P3&0x01)==0x00)
                {
                   key++;
                   switch(key)
                   {
                        case 1:
                                   TH0=0xee;
                                   TL0=0x00;
                                   TR0=1;
                                   break;
                        case 2:
                                TR0=0;
                                break;
                        case 3:
                                key=0;
                                second=0;
                                P0=discode1[second/10];
                                P2=discode2[second%10];
                                break;
                   }
                   while((P3&0x01)==0x00);
                }
        }
}
void int_T0() interrupt 1 using 0
{
        TR0=0;
        TH0=0xee;
        TL0=0X00;
        timer++;        
         if(timer==20)
         {
                 timer=0;
                second++;
                P0=discode1[second/10];
          P2=discode2[second%10];
         }
        if(second==99)
        {
                 TR0=0;
                second=0;
                key=2;
        }
        else
        {

                TR0=1;
        }
}

附件里面是仿真圖,不含代碼(自行生成hex文件)僅供參考,請自行測試,如有錯誤請告知: 制作LED數(shù)碼管秒表.zip (40.65 KB, 下載次數(shù): 13)





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1