求at89c51单片机倒计时20d程序 用现有的改一下 求大神

2024-12-03 01:44:30
推荐回答(1个)
回答1:

#include

sbit feng=P1^3;//蜂鸣器?

unsigned char shu[]={0x90,0x80,0xf8,0x82,0x92,0x99,0xb0,0xa4,0xf9};//段选

void dealy()

{

    unsigned int i=3000;

    while(i--);

} 

void dealy1()

{

    unsigned int i=500;

    while(i--);

}

void dispaly(unsigned char num)

{

    unsigend char shi;

    unsiegnd char ge;

    shi=num/10;

    ge=num%10;

    //显示个位

    P3=0xfe;

    P0=shu[ge];

    delay();

    delay();

    //显示十位

    P3=0xfd;

    P0=shu[shi];

    delay();

    delay();

}

void main()

{

    unsigned char i=20;

    while(1)

    {

        feng=1;

        if(i==0)

            i=20;

        delay();

        delay();

        feng=0;

        delay();

        display();

        i--;

    }

} 

//还是用定时器中断进行数的加减比较好,使用软件延时的话上面的程序用起来数码管很可能会闪烁