第八届蓝桥杯单片机类代码
作者:互联网
//驱动自己加
#include<1302.h>#include<DS18B20.h>
u16 code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0X40};
u8 yi,er,san,si,wu,liu,qi,ba;
u8 shizhongshezhicishu=0;//????瓯?箨??
u8 naozhong[3]={0,0,0};
u16 dingshishijian;
u16 dingshishijian1;
u8 kongzhishanshuo;
u8 naozhongcishu;
u8 jia,jian;
u8 chucunshijian[3];
u8 kai;
void Delay1ms();
void display(); void Delay200ms() //@11.0592MHz
{
unsigned char i, j, k; _nop_();
_nop_();
i = 9;
j = 104;
k = 139;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
} void Timer0Init(void) //1??@11.0592MHz
{
AUXR |= 0x80; //?????1T??
TMOD &= 0xF0; //???????
TL0 = 0xCD; //??????
TH0 = 0xD4; //??????
TF0 = 0; //??TF0??
TR0 = 0;
EA=1;
ET0=1;//???0????
TMOD &= 0x0F; //???????
TL1 = 0xCD; //??????
TH1 = 0xD4; //??????
TF1 = 0; //??TF1??
TR1 = 0;
ET1=1;
} void Delay10ms() //@11.0592MHz
{
unsigned char i, j; i = 108;
j = 145;
do
{
while (--j);
} while (--i);
}
void Delay1ms() //@11.0592MHz
{
unsigned char i, j; _nop_();
_nop_();
_nop_();
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
}
void allinit()
{
P2=0xa0;
P0=0x00;
P2=0x80;
P0=0xff;
}
void display()//陏??1?醸???
{
P2=0xc0;
P0=0x80;
P2=0xff;
P0=~duan[ba];
Delay1ms();
P2=0xc0;
P0=0x40;
P2=0xff;
P0=~duan[qi];
Delay1ms();P2=0xc0;
P0=0x20;
P2=0xff;
P0=~duan[liu];
Delay1ms();P2=0xc0;
P0=0x10;
P2=0xff;
P0=~duan[wu];
Delay1ms();P2=0xc0;
P0=0x08;
P2=0xff;
P0=~duan[si];
Delay1ms();P2=0xc0;
P0=0x04;
P2=0xff;
P0=~duan[san];
Delay1ms();
P2=0xc0;
P0=0x02;
P2=0xff;
P0=~duan[er];
Delay1ms();
P2=0xc0;
P0=0x01;
P2=0xff;
P0=~duan[yi];
Delay1ms();
} void juzhen()//??????
{
u8 dat;
kai=0;
jia=0;
jian=0;
if(P30==0)
{
Delay10ms() ;
if(P30==0)
{
dat=4;kai=1;
}
while(P30==0)
{
}
}
if(P31==0)
{
Delay10ms() ;
if(P31==0)
{
dat=3;
kai=1;
}
while(P31==0)
{
}
}
if(P32==0)
{
Delay10ms();
if(P32==0)
{
dat=2;kai=1;
}
while(P32==0)
{
}
}
if(P33==0)
{
Delay10ms() ;
if(P33==0)
{
dat=1;
kai=1;
} } if(dat==4&&naozhongcishu==0)
{ P14=1;
P17=0;
shizhongshezhicishu+=1;
}
if(shizhongshezhicishu==4)
{
shizhongshezhicishu=0;
}
if(dat==3&&shizhongshezhicishu==0)
{
naozhongcishu+=1;
}
if(naozhongcishu==4)
{
naozhongcishu=0;
}
if(dat==2)
{
jia=1;
}
if(dat==1&&(shizhongshezhicishu!=0||naozhongcishu!=0))
{
while(P33==0)
{
jian=1;
}
}
if(P33==0&&shizhongshezhicishu!=1&&naozhongcishu!=1)
{
while(P33==0)
{
yi=16;er=16;san=16;si=16;wu=16;
dat=zuizhong();
liu=dat/100;qi=dat/10%10;ba=dat%10;
display();
}
}
} //void shanshuo()//??e
//{
//yi=16;er=16;san=16;si=16;wu=16;liu=16;qi=16;ba=16;
//}
void shanshuo1()
{
chucunshijian[0]=chucunshijian[0]+jia-jian;
TR0=1;
yi=16;er=16;san=17;si= chucunshijian[1]/16;wu=chucunshijian[1]%16;liu=17;qi=chucunshijian[2]/16;ba=chucunshijian[2]%16;
} void shanshuo2()
{TR0=1; chucunshijian[1]=chucunshijian[1]+jia-jian; yi=chucunshijian[0]/16;er=chucunshijian[0]%16;san=17;si=16;wu=16;liu=17;qi=chucunshijian[2]/16;ba=chucunshijian[2]%16;
} void shanshuo3()
{TR0=1; chucunshijian[2]=chucunshijian[2]+jia-jian; yi=chucunshijian[0]/16;er=chucunshijian[0]%16;san=17;si=chucunshijian[1]/16;wu=chucunshijian[1]%16;liu=17; qi=16; ba=16;
}
void zhengchang()
{
yi=chucunshijian[0]/16;er=chucunshijian[0]%16;san=17;si=chucunshijian[1]/16;wu=chucunshijian[1]%16;liu=17;qi=chucunshijian[2]/16;ba=chucunshijian[2]%16;
}
void zhengchang1()
{
yi=shijian[0]/16;er=shijian[0]%16;san=17;si=shijian[1]/16;wu=shijian[1]%16;liu=17;qi=shijian[2]/16;ba=shijian[2]%16;
} void sanshanshuo()
{
chucunshijian[0]=shijian[0];
chucunshijian[1]=shijian[1];
chucunshijian[2]=shijian[2];
switch(shizhongshezhicishu)
{ case 1:
if(kongzhishanshuo==0)
{
shanshuo1();
}
else if(kongzhishanshuo==1)
{
zhengchang();
}
break;
case 2:
if(kongzhishanshuo==0)
{
shanshuo2();
}
else if(kongzhishanshuo==1)
{
zhengchang();
}
break;
case 3:
if(kongzhishanshuo==0)
{
shanshuo3();
}
else if(kongzhishanshuo==1)
{
zhengchang();
}
break;
}
write(0x8e,0x00);
write(0x80,chucunshijian[0]);
write(0x82,chucunshijian[1]);
write(0x84,chucunshijian[2]);
write(0x8e,0x80);
}
void naozhongkongzhi()
{
yi=naozhong[0]/10;er=naozhong[0]%10;san=17;si=naozhong[1]/10;
wu=naozhong[1]%10;liu=17;qi=naozhong[2]/10;ba=naozhong[2]%10;
}
void naozhongxianshi()
{
TR0=1;
if(naozhongcishu==1&&kongzhishanshuo==0)
{
naozhong[0]=naozhong[0]+jia-jian;
naozhongkongzhi();
}
else if(naozhongcishu==1&&kongzhishanshuo==1)
{
yi=16;er=16;san=17;si=naozhong[1]/10;
wu=naozhong[1]%10;liu=17;qi=naozhong[2]/10;ba=naozhong[2]%10;
}
if(naozhongcishu==2&&kongzhishanshuo==0)
{
naozhong[1]=naozhong[1]+jia-jian;
naozhongkongzhi();
}
else if(naozhongcishu==2&&kongzhishanshuo==1)
{
yi=naozhong[0]/10;er=naozhong[0]%10;san=17;si=16;
wu=16;liu=17;qi=naozhong[2]/10;ba=naozhong[2]%10;
}
if(naozhongcishu==3&&kongzhishanshuo==0)
{
naozhong[2]=naozhong[2]+jia-jian;
naozhongkongzhi();
}
else if(naozhongcishu==3&&kongzhishanshuo==1)
{
yi=naozhong[0]/10;er=naozhong[0]%10;san=17;si=naozhong[1]/10;
wu=naozhong[1]%10;liu=17;qi=16;ba=16;
}
}
void naozhongxiang()
{
P2=0xcf;
P0=0xff;
P2=0xff;
P0=0xff;
TR1=1;
while(1)
{
P2=0x80;
P0=0x00;
Delay200ms();
P2=0x80;
P0=0xff;
Delay200ms();
juzhen();
if(kai==1)
{
break;
}
}
dingshishijian=0;
TR1=0;
}
void main()
{
Timer0Init();
wr();
allinit();
while(1)
{
juzhen();
re();
if(shizhongshezhicishu==0&&naozhongcishu==0)
{
zhengchang1();
}
else{
sanshanshuo();
naozhongxianshi();
}
// moshixuanze();
// re();
display();
if(shijian[0]==naozhong[0]&&shijian[1]==naozhong[1]&&shijian[2]==naozhong[2])
{
naozhongxiang();
}
}
} void ding0()interrupt 1
{ TL0 = 0xCD; //??????
TH0 = 0xD4;
dingshishijian++;
if(dingshishijian==1000&&kongzhishanshuo==0)
{
kongzhishanshuo=1;
dingshishijian=0;
}
else if(dingshishijian==1000&&kongzhishanshuo==1)
{
kongzhishanshuo=0;
dingshishijian=0;
}
} void ding1()interrupt 3
{
TL1 = 0xCD;
TH1 = 0xD4;
//??????
dingshishijian1++;
}
标签:P2,P0,第八届,16,void,chucunshijian,蓝桥,单片机,naozhong 来源: https://www.cnblogs.com/a1113775906/p/12121693.html