背景图片
合泰单片机驱动步进电机程序 - 啊和的博客

合泰单片机驱动步进电机程序 - 啊和的博客 合泰单片机驱动步进电机程序 - 啊和的博客

合泰单片机驱动步进电机程序

/*****************************************************************************************
			函数名称  : stepping_move
			描述	  : 步进电机驱动
			入口参数  : 0顺时针 1逆时针   度数
			返回值    : 无
*****************************************************************************************/
void stepping_move(unsigned char direction,unsigned int degree)
{
 du = degree*1.42;
 bujindianji_on=1;
if(direction==0)bujindianji_fx=0;
if(direction==1)bujindianji_fx=1;
}

void __attribute((interrupt(0x0C))) TB0(void)   //8ms定时中断一次
{

_tb0f=0;                                       //清除中断标志位

if(bujindianji_on==1&&bujindianji_fx==1&&zhuanquan_ed<=du)
{
	iii++;
	if(iii==1)
{
Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=1;
	Motor_B=0;
	Motor_C=0;
	Motor_D=0;
}
if(iii==2)
{
	Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;	
	Motor_A=1;
	Motor_B=1;
	Motor_C=0;
	Motor_D=0;
}
if(iii==3)
{
	Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;	
	Motor_A=0;
	Motor_B=1;
	Motor_C=0;
	Motor_D=0;
}
if(iii==4)
{
		Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=0;
	Motor_B=1;
	Motor_C=1;
	Motor_D=0;
}
if(iii==5)
{
	Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=0;
	Motor_B=0;
	Motor_C=1;
	Motor_D=0;
}
if(iii==6)
{
	Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=0;
	Motor_B=0;
	Motor_C=1;
	Motor_D=1;

	}
	if(iii==7)
{	
	Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=0;
	Motor_B=0;
	Motor_C=0;
	Motor_D=1;
}
if(iii==8)
{
	Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=1;
	Motor_B=0;
	Motor_C=0;
	Motor_D=1;
}
	if(iii==8) {iii=0;zhuanquan_ed++;}
if(zhuanquan_ed==( unsigned int )du){
	bujindianji_on=0;
	zhuanquan_ed=0;
	Motor_A=0;
	Motor_B=0;
	Motor_C=0;
	Motor_D=0;
	iii=0;
}
}

if(bujindianji_on==1&&bujindianji_fx==0&&zhuanquan_ed<=du)
{
iii++;
if(iii==1)
{
Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=1;
	Motor_B=0;
	Motor_C=0;
	Motor_D=1;	
}

if(iii==2)
{
Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=0;
	Motor_B=0;
	Motor_C=0;
	Motor_D=1;	
}

if(iii==3)
{
Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=0;
	Motor_B=0;
	Motor_C=1;
	Motor_D=1;
}
if(iii==4)
{
Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=0;
	Motor_B=0;
	Motor_C=1;
	Motor_D=0;
}
if(iii==5)
{
Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=0;
	Motor_B=1;
	Motor_C=1;
	Motor_D=0;
}

if(iii==6)
{
Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=0;
	Motor_B=1;
	Motor_C=0;
	Motor_D=0;
}
if(iii==7)
{
Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=1;
	Motor_B=1;
	Motor_C=0;
	Motor_D=0;
}
if(iii==7)
{
Motor_A=0;Motor_B=0;Motor_C=0;Motor_D=0;
	Motor_A=1;
	Motor_B=0;
	Motor_C=0;
	Motor_D=0;
}
if(iii==8) {iii=0;zhuanquan_ed++;}
if(zhuanquan_ed==( unsigned int )du){
	bujindianji_on=0;
	zhuanquan_ed=0;
	Motor_A=0;
	Motor_B=0;
	Motor_C=0;
	Motor_D=0;
	iii=0;
}
}




}

评论 0

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论