|
#include "reg52.h"
#include "intrins.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit k1=P3^0;
sbit pwm1=P2^0;
bit flag1,flag2,flag3;
u8 count;
void delay(u16 a)
{
while(a--);
}
void main()
{
count++;
while(1)
{
u8 i;
for(i=0;i<3;i++)
{
if(k1==0)
{
delay(1000);
if(k1==0)
{
switch(i)
{
case(0):
flag1=0;break;
case(1):
flag2=0;break;
case(2):
flag3=0;break;
}
}
while(!k1);
delay(1000);
while(!k1);
}
if(flag1==0)
{
if(count>=100) count=0;
if(count<=80) pwm1=0;
else pwm1=1;
}
if(flag2==0)
{
if(count>=100) count=0;
if(count<=50) pwm1=0;
else pwm1=1;
}
if(flag3==0)
{
if(count>=100) count=0;
if(count<=20) pwm1=0;
else pwm1=1;
}
}
}
} |
|