第七届蓝桥杯单片机类代码
作者:互联网
//驱动自己加
#include<18B20.h>
u8 yi,er,san,si,wu,liu,qi,ba;
u16 code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0X40};
u16 time,zhankong,ding;
u8 moshi;
u8 dingshijian;
u8 wenducishu;
void Timer0Init(void) //10??@11.0592MHz
{
AUXR |= 0x80; //?????1T??
TMOD &= 0xF0; //???????
TL0 = 0xAE; //??????
TH0 = 0xFB; //??????
TF0 = 0; //??TF0??
TR0 = 0; //???0????
ET0=1;
EA=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 = 90;
do
{
while (--j);
} while (--i);
} void allinit()
{
P2=0xa0;
P0=0x00;
P2=0x80;
P0=0xff; }
void display()
{
P2=0xc0;
P0=0x80;
P2=0xff;
P0=~duan[yi];
Delay1ms();
P2=0xc0;
P0=0x40;
P2=0xff;
P0=~duan[er];
Delay1ms();
P2=0xc0;
P0=0x20;
P2=0xff;
P0=~duan[san];
Delay1ms();
P2=0xc0;
P0=0x10;
P2=0xff;
P0=~duan[si];
Delay1ms();
P2=0xc0;
P0=0x08;
P2=0xff;
P0=~duan[wu];
Delay1ms();
P2=0xc0;
P0=0x04;
P2=0xff;
P0=~duan[liu];
Delay1ms();
P2=0xc0;
P0=0x02;
P2=0xff;
P0=~duan[qi];
Delay1ms();
P2=0xc0;
P0=0x01;
P2=0xff;
P0=~duan[ba];
Delay1ms();
} void mie()
{
yi=16;er=16;san=16;si=16;wu=16;liu=16;qi=16;ba=16;
} void DS()
{
ba=17;
qi=4;
liu=17;
wu=16;
si=16;
san=zuizhong()/100;
san=zuizhong()/10%10;
er=zuizhong()%10;
yi=12;
} void anjian()//垃圾按键
{
u8 dat;
if(P30==0)
{
Delay10ms();
if(P30==0)
{
dat=1;
} wenducishu+=1;
while(P30==0);
}
if(P31!=1)
{
Delay10ms();
if(P31!=1)
{
dat=2;
}
while(P31==0);
}
if(P32!=1)
{
Delay10ms();
if(P32!=1)
{
dat=3;
}
while(P32==0);
}
if(P33!=1)
{
Delay10ms();
if(P33!=1)
{
dat=4;
}
while(P33==0);
}
if(dat==4)
{
moshi+=1;
}
if(moshi==4)
{
moshi=1;
}
if(dat==3)
{
dingshijian+=60;
}
// if(dingshijian>120)
// {
// dingshijian=0;
// }
if(dat==2)
{
dingshijian=0;
}
dat=0;
}
void shijianxianshi()
{
yi=dingshijian%10;
er=dingshijian%100/10;
san=dingshijian%1000/100;
si=dingshijian%10000/1000;
wu=16;
liu=17;
qi=moshi;
ba=17;
} void main()
{
allinit();
Timer0Init();
mie();
while(1)
{
anjian();
display();
if(wenducishu%2==1)
{
TR0=0;
DS();
}
else
{
TR0=1;
shijianxianshi();
} }
} void dinga()interrupt 1
{
TL0 = 0xAE; //??????
TH0 = 0xFB;
zhankong++;
time++;
if(time==10000&&dingshijian!=0)
{
dingshijian-=1;
time=0;
}
if(time>0)
{
if(moshi==1)//pwm???
{
if(zhankong<3)
P34=1;
else P34=0;
}
else if(moshi==2)
{
if(zhankong<4)
P34=1;
else P34=0;
}
else if(moshi==3)
{
if(zhankong<8)
P34=1;
else P34=0;
}
}
}
u8 yi,er,san,si,wu,liu,qi,ba;
u16 code duan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0X40};
u16 time,zhankong,ding;
u8 moshi;
u8 dingshijian;
u8 wenducishu;
void Timer0Init(void) //10??@11.0592MHz
{
AUXR |= 0x80; //?????1T??
TMOD &= 0xF0; //???????
TL0 = 0xAE; //??????
TH0 = 0xFB; //??????
TF0 = 0; //??TF0??
TR0 = 0; //???0????
ET0=1;
EA=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 = 90;
do
{
while (--j);
} while (--i);
} void allinit()
{
P2=0xa0;
P0=0x00;
P2=0x80;
P0=0xff; }
void display()
{
P2=0xc0;
P0=0x80;
P2=0xff;
P0=~duan[yi];
Delay1ms();
P2=0xc0;
P0=0x40;
P2=0xff;
P0=~duan[er];
Delay1ms();
P2=0xc0;
P0=0x20;
P2=0xff;
P0=~duan[san];
Delay1ms();
P2=0xc0;
P0=0x10;
P2=0xff;
P0=~duan[si];
Delay1ms();
P2=0xc0;
P0=0x08;
P2=0xff;
P0=~duan[wu];
Delay1ms();
P2=0xc0;
P0=0x04;
P2=0xff;
P0=~duan[liu];
Delay1ms();
P2=0xc0;
P0=0x02;
P2=0xff;
P0=~duan[qi];
Delay1ms();
P2=0xc0;
P0=0x01;
P2=0xff;
P0=~duan[ba];
Delay1ms();
} void mie()
{
yi=16;er=16;san=16;si=16;wu=16;liu=16;qi=16;ba=16;
} void DS()
{
ba=17;
qi=4;
liu=17;
wu=16;
si=16;
san=zuizhong()/100;
san=zuizhong()/10%10;
er=zuizhong()%10;
yi=12;
} void anjian()//垃圾按键
{
u8 dat;
if(P30==0)
{
Delay10ms();
if(P30==0)
{
dat=1;
} wenducishu+=1;
while(P30==0);
}
if(P31!=1)
{
Delay10ms();
if(P31!=1)
{
dat=2;
}
while(P31==0);
}
if(P32!=1)
{
Delay10ms();
if(P32!=1)
{
dat=3;
}
while(P32==0);
}
if(P33!=1)
{
Delay10ms();
if(P33!=1)
{
dat=4;
}
while(P33==0);
}
if(dat==4)
{
moshi+=1;
}
if(moshi==4)
{
moshi=1;
}
if(dat==3)
{
dingshijian+=60;
}
// if(dingshijian>120)
// {
// dingshijian=0;
// }
if(dat==2)
{
dingshijian=0;
}
dat=0;
}
void shijianxianshi()
{
yi=dingshijian%10;
er=dingshijian%100/10;
san=dingshijian%1000/100;
si=dingshijian%10000/1000;
wu=16;
liu=17;
qi=moshi;
ba=17;
} void main()
{
allinit();
Timer0Init();
mie();
while(1)
{
anjian();
display();
if(wenducishu%2==1)
{
TR0=0;
DS();
}
else
{
TR0=1;
shijianxianshi();
} }
} void dinga()interrupt 1
{
TL0 = 0xAE; //??????
TH0 = 0xFB;
zhankong++;
time++;
if(time==10000&&dingshijian!=0)
{
dingshijian-=1;
time=0;
}
if(time>0)
{
if(moshi==1)//pwm???
{
if(zhankong<3)
P34=1;
else P34=0;
}
else if(moshi==2)
{
if(zhankong<4)
P34=1;
else P34=0;
}
else if(moshi==3)
{
if(zhankong<8)
P34=1;
else P34=0;
}
}
}
标签:P2,dat,P0,16,void,蓝桥,单片机,0xff,第七届 来源: https://www.cnblogs.com/a1113775906/p/12121686.html