四线双极性步进马达时序程序
/*
LB11847 步进电机驱动
*/
#include
//代表输出电流值
//分别代表
// 17.39% 26.08% 34.78% 43.48% 52.17% 60.87% 69.56% 73.91% 78.26% 82.61% 86.95% 91.30% 95.65% 100%
//对应端口
// IB4 IB3 IB2 IB1 IA4 IA3 IA2 IA1
// RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0
const unsigned char TableA[] = {0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x0F,0x0F,0x0f,0x0f,0x0f,0x0f};// 电流输出值对应
const unsigned char TableB[] = {0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0xA0,0xB0,0xC0,0xD0,0xE0,0xF0,0xF0,0xF0,0xf0,0xf0,0xf0,0xf0};
// 正转反转时许设定
// 1.单相通电
// 正转时序
// A/ B A B/
// 反转时序
// B/ A B A/
// 2.两相通电
// 正转时序
// A/B AB AB/ A/B/
// 反转时序
// A/B/ AB/ AB A/B
// 3.半步方式
// 正转时序
// A/ A/B B AB A AB/ B/ A/B/
// 反转时序
// A/B/ B/ AB/ A AB B A/B A/
// 步进电机对应
// 从带蓝边开始 依次 A B A/ B/
// 操作时序
// PHASE ENABLE OUTAorB OUTA/orB/
// H L H L
// L L L H
// - H OFF OFF
const unsigned char PositiveTable[]={0x08,0x06,0x09,0x02}; // 正转时序
const unsigned char ReverseTable[]={0x02,0x09,0x06,0x08}; // 反响时序
const unsigned char PositiveTable1[]={0x04,0x05,0x01,0x00}; // 正转时序
const unsigned char ReverseTable1[]={0x00,0x01,0x05,0x04}; // 反响时序
const unsigned char PositiveTable2[] ={0x08,0x04,0x06,0x05,0x09,0x01,0x02,0x00}; // 8拍正转时序
const unsigned char ReverseTable2[]={0x00,0x02,0x01,0x09,0x05,0x06,0x04,0x08};
#define Timer1_Int 0xFF80 // 定时器1初始化值
const unsigned char PositiveTable3[]={0x08,0x06,0x09,0x02}; // 正转时序
#define PHASEA RC0 // 输出管脚使能
#define ENABLEA RC1
#define PHASEB RC2
#define ENABLEB RC3
unsigned char Point_CurrentA; // A相电流输出指针
unsigned char Point_CurrentB; // B相电流输出指针
unsigned char Point_Running; // 转动指针
unsigned char Delay_Counter; // 延时计数器
unsigned int Timer_Add;
unsigned char Add_Pluse;
volatile bit A_Add;
volatile bit A_Plus;
volatile bit B_Add;
volatile bit B_Plus;
volatile bit Positive_Reverse_Flage; // 正反标志
volatile bit Positive_ReverseA;
volatile bit Positive_ReverseB;
//#define A_Add 1 // A相电流加操作
//#define A_Pluse 2 // A相电流减操作
//#define B_Add 3 // B相电流加操作
//#define B_Pluse 4 // B相电流减操作
void Pic_Int();
void delay(unsigned int asd)
{
unsigned int i;
for(i=0;i{}
}
//*****************************************
//中断函数
//*****************************************
void interrupt SDI()
{
if(TMR1IF) // 定时器中断
{
TMR1IF = 0;
if(Timer_Add{
//Timer_Add++;
}
TMR1H = (unsigned char)(Timer_Add>>4); // 定时器计时初始化
TMR1L = (unsigned char)(Timer_Add&0x00ff);
Delay_Counter++;
if(Delay_Counter>=1);
{
Delay_Counter = 0;
PORTC = PositiveTable[Point_Running]; // 正转时