标题: 倒计时程序 1602液晶从5~0倒计时6秒,到0时计时停止程序停止 [打印本页]

作者: nius    时间: 2015-4-10 02:57
标题: 倒计时程序 1602液晶从5~0倒计时6秒,到0时计时停止程序停止

倒计时程序初级——范列
#include<reg51.h>

#define uchar unsigned char
#define uint unsigned int
uchar code xian1[]="you win!";
uchar code xian2[]="I Iove You^-^";
uchar code tishi[]="into the clock";
uchar code ling[]="00";
uchar code shu1[]="1";
uchar code shu2[]="2";
uchar code shu3[]="3";
uchar code shu4[]="4";
uchar code shu5[]="5";
uchar code shu0[]="0";
uchar cc,num1,num2,num3,num4,num5,num6;
sbit rs=P1^0;
sbit rw=P1^1;
sbit e=P1^2;
void timer(uint s)
{
uint x,c;
for(x=s;x>0;x--)
        for(c=110;c>0;c--);
}
void zhiling(uchar p)
{

rs=0;
rw=0;
P2=p;
timer(5);
e=1;
timer(5);
e=0;
}
void shuju(uchar y)
{
rs=1;
rw=0;
P2=y;
timer(5);
e=1;
timer(5);
e=0;
}

void init()
{

zhiling(0x38);
zhiling(0x0c);
zhiling(0x06);
zhiling(0x01);
}

void djs()
{

ET1=1;
TR1=1;

}
void timerkai()
{
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
ET1=0;
TR1=0;
num3=0;
num5=6;
num6=0;
}
void main()
{
init();
zhiling(0x80);
for(cc=0;cc<8;cc++)
        {
        shuju(xian1[cc]);
        timer(5);
        }
zhiling(0x80+0x42);
for(cc=0;cc<13;cc++)
        {
        shuju(xian2[cc]);
        timer(5);
        }
timerkai();
        while(1)
                {
                if(num2==5|num3==1)
                        {
                        num3=1;
                        djs();
                                init();
                                zhiling(0x80+0x01);
                                for(cc=0;cc<14;cc++)
                                        {
                                        shuju(tishi[cc]);
                                        timer(5);
                                        }
                                zhiling(0x80+0x48);
                                for(cc=0;cc<2;cc++)
                                        {
                                        shuju(ling[cc]);
                                        timer(5);
                                        }
                        while(1)
                                {
                                if(num5==1)
                                        {
                                        zhiling(0x80+0x49);
                                        for(cc=0;cc<1;cc++)
                                                {
                                                shuju(shu1[cc]);
                                                timer(5);
                                                }                                       
                                        }
                                if(num5==2)
                                        {
                                        zhiling(0x80+0x49);
                                        for(cc=0;cc<1;cc++)
                                                {
                                                shuju(shu2[cc]);
                                                timer(5);
                                                }                                       
                                        }
                                if(num5==3)
                                        {
                                        zhiling(0x80+0x49);
                                        for(cc=0;cc<1;cc++)
                                                {
                                                shuju(shu3[cc]);
                                                timer(5);
                                                }                                       
                                        }
                                if(num5==4)
                                        {
                                        zhiling(0x80+0x49);
                                        for(cc=0;cc<1;cc++)
                                                {
                                                shuju(shu4[cc]);
                                                timer(5);
                                                }                                       
                                        }
                                if(num5==5)
                                        {
                                        zhiling(0x80+0x49);
                                        for(cc=0;cc<1;cc++)
                                                {
                                                shuju(shu5[cc]);
                                                timer(5);
                                                }                                       
                                        }
                                if(num5==6)
                                        {
                                        zhiling(0x80+0x49);
                                        for(cc=0;cc<1;cc++)
                                                {
                                                shuju(shu0[cc]);
                                                timer(5);
                                                }                                       
                                        }
                                if(num6==1)
                                        {
                                       
                                        }
                                }
                        }
                }

}
void t0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num1++;
        if(num1==20)
                {
                num2++;
                num1=0;
                if(num2==6)
                        {
                        num2=0;
                        }
                }
}
void t1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
num4++;
if(num4==20)
        {
        num5--;
        num4=0;
        if(num5==0)
                {
                num5=6;
                TR1=0;
                ET1=0;
                num6=1;
                }
        }
}

设计者:薛羽豪







欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1