background image

#include<reg51.h>
#define uchar unsigned char
#define uint  unsigned int
uchar idata table1[]={0xf3,0xf9,0xfC,0xf6,0xff}; //正转
uchar idata table2[]={0xf3,0xf6,0xfc,0xf9,0xff}; //反转
sbit  key1=P0^7;

//

 

方向控制 以 direct 为标志

sbit  key2=P0^6;

//

 

速度控制 以 mode 为标志(加速)

sbit  key3=P0^5;

//

 

速度控制 以 mode 为标志(减速)

sbit  key4=P0^4;

//停止

   以 stop 为标志

static uchar  mode=1;

//速度控制

bit   direct=0;

//方向控制

bit   stop=0;

//停止标志

bit   flag=0;

//中断标志

uchar sn=200;

//步数

uchar idata *control_mode;

//控制速度指针

/**************************************************************/
/****************延时部分**************************************/

void delay1ms()
{

uchar i,j=8;
while(j--)
{

for(i=0;i<125;i++)
{;}

}

}
/**************************************************************/
/****************移动控制**************************************/
void move()
{

uchar i;
if(direct)

    {

control_mode=table1;

}
else
{

control_mode=table2;

}
do
{