这是一个来自单片机开发板的源程序,原理图的下载地址:http://www.51hei.com/f/ks51.pdf
下面是源代码:
/**
*************************************************************************************************
* @file main.c
* @author xr
* @date 2014年3月18日20:00:03
* @note 步进电机的参数:减速比:1:64步进角:5.625/64 发动频率:>=550 发动时刻最小:1.08ms
* @brief 串口通讯操控步进电机单片机STC89C52RC MCU晶振11.0592MHZ
*************************************************************************************************
*/
#include
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long ulong;
//步进电机八拍形式相值编码 A-AB-B-BC-C-CD-D-DA
uchar code table[] = {
0xE, 0xC, 0xD, 0x9, 0xB, 0x3, 0x7, 0x6
};
uint tmp = 0;
bit dir = 0;
ulong beats = 0;//拍数
uchar angle = 0;//圈数
void timer0_Config();
void motor_Config(ulong angle);
void Uart_Config(uint baud);
void main()
{
timer0_Config();//发动时刻设定为2ms
Uart_Config(9600);
while (1)
{
switch (angle)
{
case 2:
{
motor_Config(2*360);
angle = 0;
break;
}
case 3:
{
motor_Config(3*360);
angle = 0;
break;
}
case 4:
{
motor_Config(4*360);
angle = 0;
break;
}
case 5:
{
motor_Config(5*360);
angle = 0;
break;
}
case 6:
{
motor_Config(6*360);
angle = 0;
break;
}
case 7:
{
motor_Config(7*360);
angle = 0;
break;
}
case 8:
{
motor_Config(8*360);
angle = 0;
break;
}
case 9:
{
P1 |= 0x0F;
beats = 0;
angle = 0;
break;
}
default:
break;
}
}
}