#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code zheng[]={
0xf3,0xf6,0xfc,0xf9};
uchar code fan[]={
0xf9,0xfc,0xf6,0xf3};
//uchar t;
bit flag=0;
uint shijian;
uchar temp;
void delay(uint z)
{
uint i,j;
for(i=0;i<z;i++)
for(j=0;j<80;j++);
}
/*void timer_init()
{
TMOD=0X01;//???0,??1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
EA=1;
TR0=1;
} */
void motor_z()
{
uchar i;
for(i=0;i<4;i++)
{
P2=zheng[i];
delay(shijian);
}
}
void motor_f()
{
uchar i;
for(i=0;i<4;i++)
{
P2=fan[i];
delay(shijian);
}
}
void keyscan()
{
P3=0XFF;
delay(1);
if(P3!=0xff)
{
temp=P3;
switch(temp)
{
case 0xfe:
{flag=~flag;break; }
case 0xfd:
{if(shijian<=60)
{shijian=50;}
else
{shijian=shijian-100;}
break; }
case 0xfb:
{if(shijian>=600)
{shijian=650;}
else
{shijian=shijian+100;}
break; }
default : break;
}
while(temp==P3);
}
}
void main()
{
shijian=350;
//timer_init();
while(1)
{
keyscan();
if(flag==0)
{
motor_z();
}
else
{
motor_f();
}
}
}
/*void timer() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(t>=200)
{
t=0;
flag=~flag;
}
t++;
} */
|