#include "STC12C5A60S2.h"
void delay();
//Motor
sbit F1 = P0^0;
sbit F2 = P0^1;
sbit F3 = P0^2;
sbit F4 = P0^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}; //正转
unsigned int K, rate;
/**********************************************************
* *
* 步进电机驱动 *
***********************************************************/
void motor_ffw(void)
{
unsigned char i;
for (i=0; i<8; i++) //一个周期转30度
{
P0 = FFW[i]&0x1f; //取数据
delay(); //调节转速
}
}
/********************************************
延时程序
*********************************************/
void delay(void)
{
unsigned int k,t;
t=rate;
while(t--)
{
for(k=0; k<150; k++)
{ }
}
}
/********************************************************
*
*步进电机运行
*
*********************************************************/
void motor_turn(void)
{
unsigned char x;
rate=0x0a;
x=0x40;
do
{
motor_ffw(); //加速
rate--;
}while(rate!=0x01);
do
{
motor_ffw(); //匀速
x--;
}while(x!=0x01);
do
{
motor_ffw(); //减速
rate++;
}while(rate!=0x0a);
}
main()
{
while(1)
{
motor_turn();
}
} |