📄 step heixian_hao1.c
字号:
#include "reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit STK_CP1=P1^3;
sbit STK_DIR1=P1^2;
sbit STK_CP2=P1^1;
sbit STK_DIR2=P1^0;
sbit speed=P1^4;
uchar th0,tl0,th1,tl1;
void time0() interrupt 1 //电机1
{ TR0=0; TH0=th0; TL0=tl0; TR0=1;
STK_CP1=~STK_CP1;
}
void time1() interrupt 3 //电机2
{ TR1=0; TH1=th1; TL1=tl1; TR1=1;
STK_CP2=~STK_CP2;
}
void int0() interrupt 0 //右转
{ th0=0xec; tl0=0x78; //5ms
th1=0xf0; tl1=0x60; //4ms
}
void int1() interrupt 2 //左转
{ th0=0xf0; tl0=0x60; //4ms
th1=0xec; tl1=0x78; //5ms
}
main()
{ EA=0;
TMOD=0x11;
th0=0xec; tl0=0x78;
TH0=th0; TL0=tl0;
TR0=1; ET0=1;
th1=0xec; tl1=0x78;
TH1=th1; TL1=tl1;
TR1=1; ET1=1;
IT0=1; EX0=1;
IT1=1; EX1=1;
EA=1;
STK_DIR1=0;
STK_DIR2=1;
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -