资源简介

三路舵机51程序,按键控制角度加减,可180度

资源截图

代码片段和文件信息

 /*
 机械手 三路舵机程序
 脉冲脚要接10K上拉电阻!!!
*/
#include “STC12C5A.H“

#define H (65536-50)/256;//50us溢出
#define L (65536-50)%256;

unsigned int  Count=0;
unsigned int  PWM1PWM2PWM3;

sbit Pulse1 = P0^0;
sbit Pulse2 = P0^1;
sbit Pulse2 = P0^2;

sbit K1  = P2^0;
sbit K2  = P2^1;
sbit K3  = P2^2;
sbit K4  = P2^3;
sbit K5  = P2^4;
sbit K6  = P2^5;
sbit K7  = P2^6;
sbit K8  = P2^7;
void delay(void)   //10ms误差 -0.053530092593us
{
    unsigned char ab;
    for(b=1;b>0;b--)
        for(a=52;a>0;a--);
}
  

void Init_timer0(void)
{
TMOD|=0x01;
TH0=H;
TL0=L;
EA=1;
ET0=1;
TR0=1;
}

void timer0(void ) interrupt 1 using 1
{
TH0=H;
TL0=L;

if(Count++>=400)//PWM计数周期。400x50us=20ms。10<=PWM<=50。
Count=0;

if(Count Pulse1=1;
else
Pulse1=0;

if(Count Pulse2=1;
else
Pulse2=0;

if(Count Pulse3=1;
else
Pulse3=0;
}

void main(void)

  Init_timer0();
   PWM1=10;
   PWM2=10;
PWM3=10;
while(1)
{
if(Key1==0)//1路角度加
{
delay();
if(Key1==0)
{
while(!Key1);                                                                                                                                                                                                                                                                                                                                                                                                    
PWM1=PWM1+1;
if(PWM1>50)
PWM1=50;
}
}

if(Key2==0)//1路角度减
{
delay();
if(Key2==0)
{
while(!Key2);                                                                                                                                                                                                                                                                                                                                                                                                    
PWM1=PWM1-1;
if(PWM1<10)
PWM1=10;
}
}


if(Key3==0)//2路角度加
{
delay();
if(Key3==0)
{  
while(!Key3);                                                                                                                                                                                                                                                                                                                                                                                                   
PWM2=PWM2+1;
if(PWM2>50)
PWM2=50;
}
}

if(Key4==0)//2路角度减
{
delay();
if(Key4==0)
{  
while(!Key4);                                                                                                                                                                                                                                                                                                         

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4288  2017-04-12 14:21  三路舵机程序(按键控制角度)\main.c

     目录          0  2017-04-12 14:21  三路舵机程序(按键控制角度)

----------- ---------  ---------- -----  ----

                 4288                    2


评论

共有 条评论