C語言實現的數字鬧鐘

直接上代碼,因爲任性,不想解釋,太簡單了
用的C51開發板

#include<reg51.h>
unsigned    char    count=0,counts=0;
code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; 
unsigned    char    sshiwei,mshiwei,hshiwei;
unsigned    char    sgewei,mgewei,hgewei;
unsigned    char    s=0,m=0,h=0;
sbit    key1=P3^2;
sbit    key2=P3^3;
sbit    led=P3^1;
sbit out=P3^0;
void    int0_isr(void)  interrupt   0
{
    m++;
}
void    int1(void)  interrupt   2
{
    h++;
}
void    timer0_isr(void)    interrupt   1
{
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
    count++;
    counts++;
    if(count==10)
    {
     count=0;
     led=!led;
    }
    if(counts==20)
    {
    counts=0;
    s++;
    }
    if(s==60)
    {
        s=0;
        m++;
    }
    if(m==60)
    {
    m=0;
    h++;
    }
    if(h==24)
    {
    h=0;
    }
}
void delay(unsigned int cnt)
{
 while(--cnt);
}
void    main()
{
    led=0;
    TMOD=0X01;
    TH0=0X4C;
    TL0=0X00;
    TH1=(65536-1000)/256;
    TL1=(65536-1000)%256;
    TR0=1;
    TR1=1;
    ET0=1;
    ET1=1;
    IT0=1;
    IT1=1;
    EX0=1;
    EX1=1;
    EA=1;
    while(1)
    {
     P2=0Xff;
     sgewei=s/10;
     P0=tab[sgewei];
     P2=0Xef;
     delay(200);
     P2=0Xff;
     sshiwei=s%10;
     P0=tab[sshiwei];
     P2=0xdf;
     delay(200);
    P2=0Xff;
     mgewei=m/10;
     P0=tab[mgewei];
     P2=0Xfb;
     delay(200);
     P2=0Xff;
     mshiwei=m%10;
     P0=tab[mshiwei];
     P2=0xf7;
     delay(200);
     P2=0Xff;
     hgewei=h/10;
     P0=tab[hgewei];
     P2=0Xfe;
     delay(200);
     P2=0Xff;
     hshiwei=h%10;
     P0=tab[hshiwei];
     P2=0xfd;
     delay(200);
    }
}
 void timer3_isr(void) interrupt 3
    {
       ET0=0;
       TH1=(65536-1000)/256;
       TL1=(65536-1000)%256;
       if(m==3)
       {
         out=~out;
       }
       ET0=1;
    }
發佈了67 篇原創文章 · 獲贊 11 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章