AT89S52定时器2控制舵机,但是总是调不好,哪位帮忙看下程序哪里有问题?

#include<reg52.h>#defineuintunsignedint#defineucharunsignedcharsbitsteering=P2^4;void... #include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit steering=P2^4;
void steering_engine_initial() //initialize Timer2
{
T2CON = 0x00;
TCLK = 0;
RCLK = 0;
CP_RL2 = 0;
steering = 1;
ET2 = 1;
}
void steering_engine_up()
{
steering_engine_initial();
TH2 = (65536-2000)/256; //initialize register T2
TL2 = (65536-2000)%256;
while(1)
{
/*---High Level:BEGIN---*/
TR2 = 1;
RCAP2H = (65536-18000)/256; //set low level previously
RCAP2L = (65535-18000)%256;
while(TR2==1);
/*---High Level:END---*/
/*---Low Level:BEGIN---*/
RCAP2H = (65536-2000)/256; //set high level previously
RCAP2L = (65536-2000)%256;
TR2 = 1;
while(TR2==1);
/*---Low Level:END---*/
}
}
void steering_engine_down() //1000 19000
{
steering_engine_initial();
TH2 = (65536-1000)/256; //initialize register T2
TL2 = (65536-1000)%256;
while(1)
{
/*---High Level:BEGIN---*/
TR2 = 1;
RCAP2H = (65536-19000)/256; //set low level previously
RCAP2L = (65536-19000)%256;
while(TR2==1);
/*---High Level:END---*/
/*---Low Level:BEGIN---*/
TR2 = 1;
RCAP2H = (65536-1000)/256; //set high level previously
RCAP2L = (65536-1000)%256;
while(TR2==1);
/*---Low Level:END---*/
}
}
void steering_engine_stop()
{
steering_engine_initial();
TH2 = (65536-1500)/256;
TL2 = (65536-1500)%256;
while(1)
{
/*---High Level:BEGIN---*/
TR2 = 1;
RCAP2H = (65536-18500)/256; //set low level previously
RCAP2L = (65536-18500)%256;
while(TR2==1);
/*---High Level:END---*/
/*---Low Level:BEGIN---*/
RCAP2H = (65536-1500)/256; //set high level previously
RCAP2L = (65536-1500)%256;
TR2 = 1;
while(TR2==1);
/*---Low Level:END---*/
}
}
void steering_engine_intr() interrupt 5
{
TF2 = 0 ; //问题在这里,加这一句舵机转动角度不够,不加转动角度又太大
TR2 = 0;
steering=~steering;

}
展开
 我来答
123_回头一笑
2011-10-15 · TA获得超过474个赞
知道答主
回答量:167
采纳率:0%
帮助的人:96.1万
展开全部
我以前用AT89S52定时器做了一个控制舵机的测试板,是自己来回转动的,我用数字示波器测过很准.如果程序还找得到的话给你发一个.
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式