file:///C:\Users\Administrator\AppData\Roaming\Tencent\Users\1425274073\QQ\WinTemp\RichOle\VW3F0Q7O)OAES(@Y2PZBQ8L.pngfile:///C:\Users\Administrator\AppData\Roaming\Tencent\Users\1425274073\QQ\WinTemp\RichOle\VW3F0Q7O)OAES(@Y2PZBQ8L.png
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code FFW[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};
uchar code REV[]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};
sbit K1=P3^0;
sbit K2=P3^1;
sbit K3=P3^2;
sbit K4=P3^3;
sbit K5=P3^4;
sbit K6=P3^5;
sbit K7=P3^6;
sbit K8=P3^7;
void delayMS(uint ms)
{
uchar i;
while(ms--)
{
for(i=0;i<120;i++);
}
}
void SETP_MOTOR_FFW(uchar n)
{
uchar i,j;
uint ms=200;
for(i=0;i<5*n;i++)
{
for(j=0;j<8;j++)
{
if(K3==0) break;
if(K2==0) break;
if(K4==0)
{
P0=0xf6;
ms=50;
}
if(K5==0)
{
P0=0xee;
ms=500;
}
P1=FFW[j];
delayMS(ms);
}
}
}
void SETP_MOTOR_REV(uchar n)
{
uchar i,j;
uint ms=200;
for(i=0;i<5*n;i++)
{
for(j=0;j<8;j++)
{
if(K1==0) break;
if(K3==0) break;
if(K4==0)
{
P0=0xf5;
ms=50;
}
if(K5==0)
{
P0=0xed;
ms=500;
}
P1=REV[j];
delayMS(ms);
}
}
}
void SETP_MOTOR_FFW1(uchar n)
{
uchar i,j;
uint ms=200;
for(i=0;i<5*n;i++)
{
for(j=0;j<8;j++)
{
if(K8==0) break;
if(K7==0) break;
if(K4==0)
{
P0=0xf6;
ms=50;
}
if(K5==0)
{
P0=0xee;
ms=500;
}
P2=FFW[j];
delayMS(ms);
}
}
}
void SETP_MOTOR_REV1(uchar n)
{
uchar i,j;
uint ms=200;
for(i=0;i<5*n;i++)
{
for(j=0;j<8;j++)
{
if(K6==0) break;
if(K8==0) break;
if(K4==0)
{
P0=0xf5;
ms=50;
}
if(K5==0)
{
P0=0xed;
ms=500;
}
P2=REV[j];
delayMS(ms);
}
}
}
void main()
{
uchar N=6;
while(1)
{
uchar ms=50;
if(K1==0)
{
P0=0xfe;
SETP_MOTOR_FFW(N);
if(K3==0) break;
}
else if(K2==0)
{
P0=0xfd;
SETP_MOTOR_REV(N);
if(K3==0) break;
}
else
{
P0=0xfb;
P1=0x03;
}
if(K6==0)
{
P0=0xfe;
SETP_MOTOR_FFW1(N);
if(K8==0) break;
}
else if(K7==0)
{
P0=0xfd;
SETP_MOTOR_REV1(N);
if(K8==0) break;
}
else
{
P0=0xfb;
P2=0x03;
}
}
}
|