?? 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 + -