(原创)STC12C5A60S2 51单片机舵机控制器 不用PWM!
本帖最后由 一只小学生 于 2021-6-14 14:13 编辑舵机一个周期是20ms
一个周期中有0.5~2.5ms高电平
所以我们可以控制高电平的时间来控制舵机
程序用keil编译
hex文件在“ABC”里 用STC-isp烧写进51单片机
#include <STC12C5A60S2.h>
/*******************************************************************************************************************************************************
编写人:一只小学生
舵机控制器:舵机接P0.0 按键1接P2.0 按键2接P2.1 12M晶振
*******************************************************************************************************************************************************/
sbit dj=P0^0;
void Dela (unsigned int a){ //0.1ms延迟函数
unsigned int i;
while( --a != 0){
for(i = 0; i < 60; i++);
}
}
void Delay (unsigned int ad){ //1ms延迟函数
unsigned int i;
while( --ad != 0){
for(i = 0; i < 600; i++);
}
}
void DJ(unsigned int q){ //舵机函数(需配合0.1ms延迟函数)
dj = 1;
Dela (q);
dj = 0;
Dela (200-q);
}
void main (void){
unsigned int a = 15;
P2M0 = 0xff;
P2M1 = 0xff;
while(1){
DJ (a);
if (P2 ^ 1 == 1){
Delay (20);
if (P2 ^ 1 == 1){
if (a !=5){
if(a != 25){
a--;
}
}
}
}
if (P2 ^ 0 == 1){
Delay (20);
if (P2 ^ 0 == 1){
if (a != 5){
if(a != 25){
a++;
}
}
}
}
if (a == 5){
a++;
}
if (a == 25){
a--;
}
}
}
呀!板块放错了 下周末再来(周三周四升学考){:5_138:} 您好我想问一下STC12C5A60S2程序烧录不了咋办
我是用USB-TTL的一个下载器连接单片机
但用stc-isp下载程序的时候一直在找单片机 ZJHER 发表于 2021-6-14 19:54
您好我想问一下STC12C5A60S2程序烧录不了咋办
我是用USB-TTL的一个下载器连接单片机
但用stc-isp下载程序的 ...
1.tx rx插的对不对
2.单片机是不是上回下载的时候没有使用内部晶振 如果是那么接一个外部晶振
3.把P1.0P1.1接地 单片机tx接USB-TTL的rx
单片机rx接USB-TTL的tx
页:
[1]