#include"reg52.h"
void delay(unsigned int t);
sbit F1 = P1^0;
sbit F2 = P1^1;
sbit F3 = P1^2;
sbit F4 = P1^3;
sbit K1 = P2^0;
sbit K2 = P2^1;
sbit K3 = P2^2;
sbit K4 = P2^3;
unsigned char code FFW[8]= {0xfe,0xfc,0xfd,0xf9,0xfb,0xf3,0xf7,0xf6}; //反转
unsigned char code FFZ[8]= {0xf6,0xf7,0xf3,0xfb,0xf9,0xfd,0xfc,0xfe}; //正转

void  motor_ffw()
{
    unsigned char i;
    unsigned int  j;
    for(j=0; j<12; j++)         //转1*n圈
    {
        for (i=0; i<8; i++)      //一个周期转30度
        {
            if(K1==1) P1 = FFZ[i]&0x1f;  //取数据
            if(K2==1)P1 = FFW[i]&0x1f;
            if(K3==1) P0 = FFZ[i]&0x1f;  //取数据
            if(K4==1)P0 = FFW[i]&0x1f;
            delay(12);                   //调节转速
        }
    }
}

/******************************************************
*
*               延时程序
*
********************************************************/

void delay(unsigned int t)
{
    unsigned int k;
    while(t--)
    {
        for(k=0; k<100; k++)
        { }
    }
}

main()
{
    while(1)
    {
        motor_ffw();
    }
}
