📄 bjdj.bak
字号:
/*----------------------------------------------------
P3_0 - pc1
P3_1 - pc2
P3_2 - fx1
P3_3 - fx2
P3_4 - enable1
P3_5 - enable2
------------------------------------------------------*/
#include "AT89x051.H"
int flag = 0;
int cycle = 0;
int tl0 = 0x02;
int th0 = 0xF3;
int end = 0;
int step = 0;
/////////////////////////////////////////////////////////////////////////
// 晶振频率=12MHz; 预分频率=12
// 参数设定值: V0 = 20; 折点1= 100; 折点2 = 750 极限转速 = 1000 rpm
// Point0= 0;第一折点= 12;第二折点= 120; 终点步数= 140
// 电机转动一周对应脉冲数=800; 编程响应(CTn rewrite)补偿步数 = 8
/////////////////////////////////////////////////////////////////////////
void T0_SVR(void) interrupt 1
{
TH0=th0;
TL0=tl0;
cycle++;
P3_0 = ~P3_0;
P3_1 = ~P3_1;
if(step==0)
{
if(cycle==19)
{
flag = 1;
cycle = 0;
step++;
}
else flag = 0;
}
else if(cycle==1)
{
flag = 1;
cycle = 0;
}
}
void main(void)
{
int i = 0;
TMOD = 0x01;
TH0 = 0xF3;
TL0 = 0x02;
TR0 = 1;
ET0 = 1;
EA = 1;
P3_0 = 0;
P3_1 = 0;
P3_2 = 1;
P3_3 = 1;
P3_4 = 1;
P3_5 = 1;
while(1)
{
if(cycle==0 && flag==1 && end==0)
{
if(step==0)
{
i++;
if(i==19)
{
step++;
i = 0;
}
}
else if(step==1)
{
tl0 = (62210 + 162*i) & 255;
th0 = ((62210 + 162*i) & 65280)/256;
i++;
if(i==108)
{
i = 0;
step++;
}
}
else if(step==2)
{
tl0 = (65446 + i) & 255;
th0 = ((65446 + i) & 65280)/256;
if(i==108)
{
i = 0;
step = 0;
end = 1;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -