步进电机c语言驱动原理,《步进电机【驱动电路+C语言驱动程序】》.doc

《步进电机【驱动电路+C语言驱动程序】》.doc

/**********************************************/

/*********兰州交通大学电子电工实验中心*********/

/*******************2009-8-2********************/

/*********************************************/

#include"reg51.h"

#include"intrins.h"

#include"math.h"

#include"absacc.h"

#define PORTA XBYTE[0x8500]

#define PORTB XBYTE[0x8502]

#define PORTC XBYTE[0x8504]

#define PORTC0 XBYTE[0x8506]

#define nop _nop_()

#define Right_RUN 1

#define Left_RUN 0

unsigned long RunSpeed=76;

unsigned char RUNState=1;

sbit RS=P2^0;

sbit RW=P2^1;

sbit E=P2^2;

sbit P17=P1^7;

bit flag=0;

unsigned char xx[]="speed(n/min):";

unsigned char SD[]="76";

char state[2][14]={"direction:cw","direction:ccw"};

unsigned char FLG,INMA=0;

unsigned char t,s=0x01;

unsigned int a;

main()

{

void OPJIAN();

unsigned char JIAN();

unsigned char JIANZHI();

void speed();

void SHOW_LCD();

void show_state();

void write1();

void writ2(unsigned char i);

void delay();

void time();

void busy();

unsigned char i;

i=0x90;

PORTC0=i;

i=0x01;

TMOD=i;

t=0x10;

a=0x0f;

TH0=0x10;

TL0=0x0f;

FLG=INMA;

SHOW_LCD();

show_state();

EA=1;

ET0=1;

TR0=1;

while(1)

{

i=JIAN();

if(i!=0)

{

time();

time();

}

i=JIAN();

if(i!=0)

{

INMA=JIANZHI();

OPJIAN();

time();

}

if(FLG!=INMA||flag==1)

{ FLG=INMA;

SHOW_LCD();

show_state();

flag=0;

}

}

}

void SHOW_LCD()/*lcd设置程序*/

{

P1=0x38;

write1();

delay();

P1=0x38;

write1();

delay();

P1=0x38;

write1();

delay();

P1=0x01;

write1();

delay();

P1=0x0f;

write1();

delay();

P1=0x06;

write1();

delay();

P1=0x0c;

write1();

}

void show_state()/*状态显示程序*/

{

unsigned char i=0;

P1=0x80;

write1();

while(xx[i]!='\0')

{

writ2(xx[i]);

i++;

delay();

}

i=0;

while(SD[i]!='\0')

{

writ2(SD[i]);

delay();

i++;

}

P1=0xc0;

write1();

i=0;

if(RUNState==Right_RUN)

while(state[0][i]!='\0')

{

writ2(state[0][i]);

i++;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值