在下新手,不明白怎样控制舵机,下面是我在网上找到的哟个程序,但是看的不是太懂,还请给位路过的朋友帮帮忙,,帮我解释一下,谢谢!
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit MOTOR = P0^2;
uint time[4] = {1500, 0, 1500, 2000}; //¸ßµçƽʱ¼ä1.5ms, 0ms, 1.5ms, 2ms
uchar level = 0;
uchar count = 0;
uchar delayflag = 1;
void main( )
{
MOTOR = 0;
TMOD = 0x01;
TH0 = 0x10000;
TL0 = 0x10000;
EA = 1;
ET0 = 1;
TR0 = 1;
while(1);
}
void int0() interrupt 1
{
if (level == 0)
{
MOTOR = 1;
TH0 = (65536 - time[count]) / 256; //¸ßµçƽ±£³Öʱ¼ä
TL0 = (65536 - time[count]) % 256;
level = 1;
}
else
{
MOTOR = 0;
TH0 = (65536 - (18000 - time[count])) / 256; //µÍµçƽ±£³Öʱ¼ä
TL0 = (65536 - (18000 - time[count])) % 256;
delayflag ++;
if (delayflag == 10) //ÊDz¨Ðα£³Ö50´Î
{
delayflag = 1;
count ++;
if (count == 4) count = 0; //תµ½ÏÂÒ»¸ö²¨ÐÎ
}
level = 0;
}
}
比如说做标记的那部分该怎么理解??还有,,舵机的转速很慢,,该怎样使它的转速变快,
如何控制其转速??而且,,舵机只能逆时针旋转!!求指教!!:)
|