hebolin
級別: 探索解密
精華主題: 0
發(fā)帖數(shù)量: 4 個
工控威望: 134 點
下載積分: 399 分
在線時間: 14(小時)
注冊時間: 2013-06-18
最后登錄: 2020-07-03
查看hebolin的 主題 / 回貼
樓主  發(fā)表于: 2014-03-06 23:12
#include<reg52.h>
#include <intrins.h>

#define uchar unsigned char
#define uint unsigned int

uchar temp,t0,t1,bai,shi,ge,mm0,mm1;
uint shu;

sbit dula = P2^6;
sbit wela= P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x76,0x79,0x38,0x3f,0
};

void init();
void display(uchar aa,uchar bb,uchar cc, uchar bai,uchar shi,uchar ge);
void dey (uint z);

void main()
{
        init();
        while(1)
                {
                if(mm0!=1)
                display(7,6,5,bai,shi,ge);
                else
                display(16,17,18,18,19,20);
                }

}

void init()
{
        TH0=(65536-5000)/256;
        TL0=(65536-5000)%256;
        TH1=(65536-5000)/256;
        TL1=(65536-5000)%256;
        temp=0xfe;
        shu=432;
        P1=temp;
        TMOD=0X11;
        EA=1;
        ET0=1;
        ET1=1;
        TR1=1;
        TR0=1;
        
}

void timer0() interrupt 1
{
    TH0=(65536-5000)/256;
    TL0=(65536-5000)%256;
    t0++;
    if(mm0!=1)
    {
        if(t0==10)
        {
            t0=0;
            temp=_crol_(temp,1);
            P1=temp;
        }
    }
    else
    {
    if(t0=t0%4==0)
        {
        P1=~P1;
        if(t0==60)
            {
            TR0=0;
            P0=0XFF;
            mm1=1;

            }
        }
    }
}
void timer1() interrupt 3
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
t1++;
if(t1==2)
    {
    t1=0;
    shu--;
    bai=shu/100;
    shi=shu%100/10;
    ge=shu%10;
    

        if(shu==398)
        {
        TR0=0;
        t0=0;
        TH0=(65536-5000)/256;
        TL0=(65536-5000)%256;
        TR0=1;
        mm0=1;
        P1=0xff;
        TR1=0;
        }
    }
}

void display(uchar aa,uchar bb,uchar cc, uchar bai,uchar shi, uchar ge)
{
         dula=1;  //aa
        P0=table[aa];
        dula=0;
        P0=0Xff;
        wela=1;
        P0=0xfe;
        wela=0;
        dey(1);

        dula=1;  //bb
        P0=table[bb];
        dula=0;
        P0=0Xff;
        wela=1;
        P0=0xfd;
        wela=0;
        dey(1);

        dula=1;  //cc
        P0=table[cc];
        dula=0;
        P0=0Xff;
        wela=1;
        P0=0xfb;
        wela=0;
        dey(1);

        dula=1;//bai
        P0=table[bai];
        dula=0;
        P0=0Xff;
        wela=1;
        P0=0xf7;
        wela=0;
        dey(1);

        dula=1;
        P0=table[shi];//shi
        dula=0;
        P0=0Xff;
        wela=1;
        P0=0xef;
        wela=0;
        dey(1);

        dula=1;
        P0=table[ge];//ge
        dula=0;
        P0=0Xff;
        wela=1;
        P0=0xdf;
        wela=0;
        dey(1);

}


void dey (uint z)
{
    int x,y;
    for(x=z;x>0;x--)
    for(y=100;y>0;y--);
}