標題: 單片機雙數碼管1分鐘計時新手入門 [打印本頁]

作者: 業(yè)務繁忙    時間: 2020-6-9 14:00
標題: 單片機雙數碼管1分鐘計時新手入門
#include<reg51.h>
unsigned char code c[]={0xc0,0xf9,0xA4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char code cd[]={0x90,0x80,0xf8,0x82,0x92,0x99,0xb0,0xA4,0xf9,0xc0};
unsigned char second;
unsigned  char tcount;

void  main()
{
    TMOD=0x01;
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
    ET0=1;
        EA=1;
        TR0=1;
        tcount=0;
        second=0;
        P0=c[second/10];//0
        P2=c[second%10];//0
        while(1)//50ms
        {
           if(TF0==1)           //開啟查詢
           {
                    tcount++;
             if(tcount==20)//1s
        {
                tcount=0;
                second++;//1
                   if(second==60)
                    {
                        second=0;
                        }
                P0=c[second/10];
            P2=c[second%10];
            }
           TF0=0;   //手動置0
           TH0=(65336-50000)/256;
           TL0=(65336-50000)%256;           
           }        
        }
}
void t0(void) interrupt 1 using 0
{

}


雙數碼管.zip

76.58 KB, 下載次數: 3, 下載積分: 黑幣 -5






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