#include "reg52.h"
#include<intrins.h>
typedef unsigned int u16;
typedef unsigned char u8;
sbit moto1=P1^0;
sbit moto2=P1^1;
sbit key=P1^2;
void delay(u16 i)
{
u16 k;
for(k=0;k<i;k++);
}
void pwm(bit a,bit b,u16 d1,u16 d2)
{
moto1=a;
moto2=b;
delay(d1);
moto1=0;
moto2=0;
delay(d2);
}
void main()
{
u8 number=0;
while(1)
{
if(key==0)
{
delay(1);
if(key==0)
{
while(!key);
number++;
if(number>10)
number=0;
}
}
switch(number)
{
case(0):moto1=0,moto2=0;break;
case(1):pwm(1,0,171,19);break;
case(2):pwm(1,0,152,38);break;
case(3):pwm(1,0,133,57);break;
case(4):pwm(1,0,114,76);break;
case(5):pwm(1,0,95,95);break;
case(6):pwm(1,0,76,114);break;
case(7):pwm(1,0,57,133);break;
case(8):pwm(1,0,38,152);break;
case(9):pwm(1,0,19,171);break;
case(10):pwm(1,0,0,190);break;
default:;
}
}
}
|