- /*******************************************/
- #include <reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- char count=0;
- char time,i=0;
- unsigned char code table_UP []= {0x11,0x33,0x22,0x66,0x44,0xcc,0x88,0x99}; //前进
- unsigned char code table_Down []= {0x99,0x88,0xcc,0x44,0x66,0x22,0x33,0x11}; //后退
- unsigned char code table_Left []= {0x60,0x40,0x50,0x10,0x90,0x80,0xa0,0x20}; //左转
- unsigned char code table_right[]= {0x02,0x0a,0x08,0x09,0x01,0x05,0x04,0x06}; //右转
- unsigned int step; //记录脉冲数,即要走的步数
- uint beat; //步进电机每种驱动方式下的拍数
- char *p1,*p2;//存储运行方式表
- uint X=500;
- /*******************************************/
- //八拍驱动正转(N*360/400)度
- /*******************************************/
- void main()
- {
- TMOD=0x01;
- //TH0=0x33;
- //TL0=0xf5;
- TH0=(65536-X)/256; // 2ms
- TL0=(65536-X)%256;
- EA=1;
- ET0=1;
- EX0=1;
- TR0=1;
- while(1)
- {
- }
- }
- void time0() interrupt 1 using 1
- {
- //TH0=0x33;
- //TL0=0xf5;
- TH0=(65536-X)/256;
- TL0=(65536-X)%256;
- count++;
- if(count==10)//count==X
- {
- count=0;
- if(i<8)
- {
- P0=table_UP[i];i++;
- }
- if(i==8)
- {i=0;}
- }
- }
复制代码
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
刚用示波器看了下,估计是电路问题
一周热门 更多>