本帖最后由 zhpeng 于 2012-3-21 00:25 编辑
我是新手,在用T0、T1中断分别控制步进电机时,遇到用同样的参数,T1控制的电机比T0控制时的步进电机要快好几倍。以下是各自程序。请高手分析一下,不胜感激!
- #include "AT892051.h"
- #include "string.h"
- #define uchar unsigned char
- uchar code CCW[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90};
- uchar code CW[8]={0x90,0x10,0x30,0x20,0x60,0x40,0xc0,0x80};
- uchar i=0;
- void T1_init()
- {
- TMOD=0x01;
- TH1=41771/256;
- TL1=41771%256;
- EA=1;
- ET1=1;
- TR1=1;
- TF1=0;
- }
- void main(void)
- {
- T1_init();
- P1=0xf0;
- while(1);
- }
- void T1_time() interrupt 3
- {
- TH1=41771/256;
- TL1=41771%256;
- P1=CW[i];
- i++;
- if(i==8) i=0;
- }
复制代码
以上是用T1中断。
- #include "AT892051.h"
- #include "string.h"
- #define uchar unsigned char
- uchar code CCW[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90};
- uchar code CW[8]={0x90,0x10,0x30,0x20,0x60,0x40,0xc0,0x80};
- uchar i=0;
- void T0_init()
- {
- TMOD=0x01;
- TH0=41771/256;
- TL0=41771%256;
- EA=1;
- ET0=1;
- TR0=1;
- TF0=0;
- }
- void main(void)
- {
- T0_init();
- P1=0xf0;
- while(1);
- }
- void T0_time() interrupt 1
- {
- TH0=41771/256;
- TL0=41771%256;
- P1=CW[i];
- i++;
- if(i==8) i=0;
- }
复制代码
以上是用T0中断。
一周热门 更多>