📄 c51_steptmoter_8255.c
字号:
#include <reg51.h>
#include <absacc.h>
unsigned char idata plus[9]=
{0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x00}; //正转
unsigned char idata minu[9]=
{0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x00}; //反转
unsigned char idata *x;
unsigned int DL=10000; // 转速控制
bit DR=0; // 转向控制
void initial()
{
EA=1;
EX0=1;
EX1=1;
IT0=1;
IT1=1;
}
void control(bit cf)
{
if(cf==0) x=&plus[0];
else x=&minu[0];
TMOD=0x01;
TH0=-DL/256;
TL0=-DL%256;
TR0=1;
}
void int_0() interrupt 0 using 0
{ P2=(P2&0x7f)|(~(P2&0x80)); }
void SpeedKey(unsigned char IntFlag)
{
if(IntFlag==0x01)
{
ET0=~ET0;
control(DR);
if(ET0==1) P2=P2&0xf7;
else P2=P2|0x08;
}
else if(IntFlag==0x02)
{
DR=~DR;
control(DR);
if(DR) P2=P2&0xfb;
else P2=P2|0x04;
}
else if(IntFlag==0x04)
{
DL+=DL/25;
if(DL>55000)
{
DL=55000;
P2=(P2|0x20)&0xdf;
}
P2=(P2|0x11)&0xfd;
}
else if(IntFlag==0x08)
{
DL-=DL/25;
if(DL<900)
{
DL=900;
P2=(P2|0x01)&0xef;
}
P2=(P2|0x22)&0xfe;
}
else P2=0xff;
}
void int_1() interrupt 2 using 1
{
P2=(P2&0xbf)|(~(P2&0x40));
// SpeedKey(~P0);
}
void step_time(void) interrupt 1 using 2
{
P1=*x++;
if(*x==0) x=x-8;
TH0=-DL/256;
TL0=-DL%256;
}
void main(void)
{
initial();
P2=0xff;
P0=0xff;
while(1)
{ }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -