#include <reg52.h>
#define uchar unsigned char;
#define uint unsigned int;
uchar flag=1,rate=50,date=50,
time,x,y,z;
sbit pa=P1^1;
sbit a1=P1^3;
sbit a2=P1^5;
sbit vcc=P3^0;
sbit pb=P3^1;
sbit b1=P3^3;
sbit b2=P3^5;
sbit key1=P2^1;
sbit key2=P2^2;
sbit key3=P2^3;
sbit key4=P2^4;
sbit key5=P2^5;
void control();
void delay(uint z);
void init();
void main()
{
init();
control();
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void control()
{
if(key1==0)
{
delay(5);
if(key1==0)
{
flag!=flag;
}
while(!key1);
}
if(key2==0)
{
delay(5);
if(key2==0)
{
rate+=5;
if(rate==100)
{
rate=0;
}
}
while(!key2);
}
if(key3==0)
{
delay(3);
if(key3==0)
{
rate-=5;
}
while(!key3);
if(rate==0)
{
rate=0;
}
}
if(key4==0)
{
delay(5);
if(key4==0)
{
date+=5;
}
while(!key4);
if(date==100)
{
date=0;
}
}
if(key5==0)
{
delay(5);
if(key5==0)
{
date-=5;
}
while(!key5);
if(date==0)
{
date=0;
}
}
}
void init()
{
TMOD=0x01;
TH1=(65536-10)/256;
TL1=(65536-10)%256;
EA=1;
ET0=1;
TR0=1;
}
void timer0() interrupt 1
{
TH1=(65536-10)/256;
TL1=(65536-10)%256;
time++;
if(flag==1)
{ if(time==100)
{
time=0;
}
if(time<rate)
{
vcc=0;
delay(2);
vcc=1;
pa=1;
a1=1;
a2=0;
b1=1;
b2=0;
}
else
{
vcc=0;
delay(2);
vcc=1;
pa=0;
a1=1;
a2=0;
b1=1;
b2=0;
}}
else{
if(time==100)
{
time=0;
}
if(time<rate)
{
vcc=0;
delay(2);
vcc=1;
pa=1;
a1=0;
a2=1;
b1=0;
b2=1;
}
else
{
vcc=0;
delay(2);
vcc=1;
pa=0;
a1=0;
a2=1;
b1=0;
b2=1;
}}}
-
一周热门 更多>