- #include <REGX52.H>
- #define uint unsigned int;
- //#define forwordDir 0;
- //#define backDir 1;
- sbit Pulse=P1^0;
- sbit Dir=P1^1;
- sbit En=P1^2;
- uint clock,i,x;
- uint counter=0;
- //void forword(void)
- //{
- // TR0 = 1;
- // TH0 = (65536 -clock)/256;
- // TL0 = (65536 -clock)%256;
- // Dir = 0;
- // En = 0;
- //}
- void back(void)
- {
- TR0 = 1;
- TH0= (65536 - clock)/256;
- TL0 = (65536 - clock)%256;
- Dir = 1;
- En = 0;
- }
- void stop(void)
- {
- TR0 = 0;
- }
- void InitBJDJ(void)
- {
- TMOD =0x01;
- EA =1;
- ET0=1;
- }
- void main(void)
- {
- clock =75;
- x=1600;
- InitBJDJ();
- while(1)
- {
- back();
-
- if(counter>=x)// 我想要的效果是:8细分,1600个脉冲走完一圈。 但是电机一直在转,不会停
- {
- En=1;
- }
- }
- void time0(void) interrupt 1
- {
- TH0= (65536-clock)/256;
- TL0 = (65536 -clock)%256;
- Pulse = ~Pulse;
- counter++;
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
两相四线的57步进电机
一周热门 更多>