您的位置 首页 IC

51单片机按键直接操控舵机旋转

#includereg52.h>#includemath.h>typedefunsignedcharuchar;typedefunsignedintuint;sbitKEY1=P3^4;s

#include

#include typedef unsigned char uchar;typedef unsigned int uint;sbit  KEY1=P3^4;sbit  KEY2=P3^5;sbit  KEY3=P3^6;sbit  KEY4=P3^7;void Delay(unsigned int s);uchar flag_0;uchar flag_1;void Delay(unsigned int s){unsigned int i;for(i=0; iinterrupt 1 {       if(flag_0==1)	PWM_Value[0]+=1;if(flag_0==2)	PWM_Value[0]-=1;if(flag_1==1)	PWM_Value[1]+=1;if(flag_1==2)	PWM_Value[1]-=1;if(PWM_Value[0]>=2500)PWM_Value[0]=2500;if(PWM_Value[1]>=2500)PWM_Value[1]=2500;if(PWM_Value[0]<=500)PWM_Value[0]=500;if(PWM_Value[1]<=500)PWM_Value[1]=500;switch(order){case 1:PWM_OUT0=1;TH0=(65536-PWM_Value[0])>>8; TL0=(uchar)(65536-PWM_Value[0]);break;                          case 2:PWM_OUT0=0;TH0=(65536-(5000-PWM_Value[0]))>>8;    TL0=(uchar)(65536-(5000-PWM_Value[0]));break;                          case 3:PWM_OUT1=1;TH0=(65536-PWM_Value[1])>>8; TL0=(uchar)(65536-PWM_Value[1]);break;                          case 4:PWM_OUT1=0;TH0=(65536-(5000-PWM_Value[1]))>>8;    TL0=(uchar)(65536-(5000-PWM_Value[1]));break;                              case 5:TH0=60536>>8;   TL0=(uchar)60536;break;case 6:TH0=60536>>8;   TL0=(uchar)60536;order=0;break;default: order=0; break;}order++;}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/bandaoti/265405.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部