《步进电机控制及其LCD显示(共6页).doc》由会员分享,可在线阅读,更多相关《步进电机控制及其LCD显示(共6页).doc(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上#include AT89X51.hint delay();void inti_lcd();void show_lcd(int);void cmd_wr();void ShowState();void clock(unsigned int Delay) ;void DoSpeed(); /计算速度/正转值#define RIGHT_RUN 1/反转值#define LEFT_RUN 0sbit RS=0xA0;sbit RW=0xA1;sbit E=0xA2;char SpeedChar=SPEED(n/min):;char StateChar=RUN STATE:;
2、char STATE_CW=CW;char STATE_CCW=CCW;char SPEED3=050;unsigned int RunSpeed=50;/速度unsigned char RunState=RIGHT_RUN; /运行状态main()/*定时器设置*/TMOD=0x66; /定时器0,1都为计数方式;方式2;EA=1;/开中断TH0=0xff;/定时器0初值FFH;TL0=0xff;ET0=1;TR0=1;TH1=0xff;/定时器1初值FFH;TL1=0xff;ET1=1;TR1=1; IT0=1;/脉冲方式EX0=1;/开外部中断0:加速IT1=1;/脉冲方式EX1=1;/
3、开外部中断1:减速 inti_lcd(); DoSpeed(); ShowState(); while(1) clock(RunSpeed); P0_1=P0_10x01; /定时器0中断程序:正转void t_0(void) interrupt 1RunState=RIGHT_RUN; P0_0=1; P1=0x01; cmd_wr(); ShowState(); /定时器1中断:反转void t_1(void) interrupt 3RunState=LEFT_RUN; P0_0=0; P1=0x01; cmd_wr(); ShowState(); /中断0:加速程序void SpeedU
4、p() interrupt 0 if(RunSpeed=12) RunSpeed=RunSpeed-2; DoSpeed(); P1=0x01; cmd_wr(); ShowState(); /中断1:减速程序void SpeedDowm() interrupt 2 if(RunSpeed=100) RunSpeed=RunSpeed+2; DoSpeed(); P1=0x01; cmd_wr(); ShowState(); int delay() /判断LCD是否忙 int a;start: RS=0; RW=1; E=0; for(a=0;a0;Delay-) for(i=0;i124;i+); void DoSpeed() SPEED0=(1000*6/RunSpeed/100)+48; SPEED1=1000*6/RunSpeed%100/10+48; SPEED2=1000*6/RunSpeed%10+48;专心-专注-专业