#include<AT89X51.H>
unsigned char set,flag1,flag2,flag3,flag4,flag5,flag6;
unsigned long aa;
sbit k1=P3^2;
sbit LED1=P2^5;
sbit LED2=P2^6;
sbit LED3=P2^7;
sbit G1=P2^0;
void TimerConfiguration()
{
TMOD = 0x01; //选择工作方式1
TH0 = 0x3C; //设置初始值
TL0 = 0xB0;
EA = 1; //打开总中断
ET0 = 1; //打开定时器0中断
//TR0 = 1; //启动定时器0
}
void Timer0() interrupt 1
{
TH0 = 0x3C; //设置初始值
TL0 = 0xB0;
aa++;
}
void main()
{
aa=0;
while(1)
{
scan_k1();
TimerConfiguration();
while(set==1)
{ TimerConfiguration();
scan_k1();
if(set==1)
if(aa==36000)//aa设置12000(10分钟)可以定时,36000就不可以??求解!
if(flag1==1)
{
G1=1;
TR0 =0;
}
else
{
flag1=1;
}
else
{
LED1=0;
LED2=1;
LED3=1;
G1=0;
TR0 =1;
}
}
while(set==2)
{ TimerConfiguration();
scan_k1();
if(set==2)
if(aa==144000)
if(flag2==1)
{
G1=1;
TR0 =0;
}
else
{
flag2=1;
}
else
{
LED1=1;
LED2=0;
LED3=1;
G1=0;
TR0 =1;
}
}
while(set==3)
{ TimerConfiguration();
scan_k1();
if(set==3)
if(aa==72000*3)
if(flag3==1)
{
G1=1;
TR0 =0;
}
else
{
flag3=1;
}
else
{
LED1=1;
LED2=1;
LED3=0;
G1=0;
TR0 =1;
}
}
while(set==4)
{ TimerConfiguration();
scan_k1();
if(set==4)
if(aa==72000*4)
if(flag4==1)
{
G1=1;
TR0 =0;
}
else
{
flag4=1;
}
else
{
LED1=0;
LED2=1;
LED3=0;
G1=0;
TR0 =1;
}
}
while(set==5)
{ TimerConfiguration();
scan_k1();
if(set==5)
if(aa==72000*5)
if(flag5==1)
{
G1=1;
TR0 =0;
}
else
{
flag5=1;
}
else
{
LED1=1;
LED2=0;
LED3=0;
G1=0;
TR0 =1;
}
}
while(set==6)
{ TimerConfiguration();
scan_k1();
if(set==6)
if(aa==72000*6)
if(flag6==1)
{
G1=1;
TR0 =0;
}
else
{
flag6=1;
}
else
{
LED1=0;
LED2=0;
LED3=0;
G1=0;
TR0 =1;
}
}
while(set==0)
{ TimerConfiguration();
scan_k1();
LED1=1;
LED2=1;
LED3=1;
G1=1;
TR0 =0;
//initial();
}
}
}
/*void Delay10ms(unsigned long c) //误差 0us
{
unsigned char a,b;
for(;c>0;c--)
for(b=38;b>0;b--)
for(a=130;a>0;a--);
}*/
void scan_k1()
{
unsigned int i;
if(k1==0)set++;
if(set==7) set=0;
F0:if(k1==0) goto F0;
for(i=0;i<20000;i++);
//aa=0;
}
|