您的位置 首页 新能源

51单片机分时操控8路舵机程序

本程序中用到的头文件12c5aH下载:http:www51heicomf12c5arar分时控制舵机,采用的单片机是STC12c5a51增强型单片机,晶振110

本程序中用到的头文件 12c5a.H下载:http://www.51hei.com/f/12c5a.rar

//分时操控舵机,选用的单片机是STC12c5a 51增强型单片机,晶振11.0592MHZ
#include <12c5a.H>

void delay(uint16 time);
void Timer_init();
void Timer0(uint32 us);

uint16 xdata pwm[8]={1500,1500,1500,1500,1500,1500,1500,1500};

sbit pwm1=P0^0;
sbit pwm2=P0^1;
sbit pwm3=P0^2;
sbit pwm4=P0^3;
sbit pwm5=P0^4;
sbit pwm6=P0^5;
sbit pwm7=P0^6;
sbit pwm8=P0^7;

void main()
{
P0M1=0;
P0M0=0XFF;

Timer_init();
Timer0(100);
delay(100);
while(1)
{
;
}
}
void delay(uint16 time)
{
uint16 i;
uint16 j;
for(i=0;i<1000;i++)
for(j=0;j}
void Timer_init()
{
EA=1; //开总中止
AUXR|=0xC0; //T0,T1作业在1T
TMOD|= 0x11; //T0作业在方法1,16位
ET0 = 1; //开定时器0中止
}
void Timer0(uint32 us)
{
uint32 valu;
valu=us*11;
valu=valu;
valu=0xffff-valu;

TH0=valu>>8;
TL0=valu;
TR0 = 1;
}
void T0zd(void) interrupt 1
{
static uint8 i=1;
switch(i)
{
case 1:
{
pwm1=1;
Timer0(pwm[0]);
} break;
case 2:
{
pwm1=0;
Timer0(2500-pwm[0]);
} break;
case 3:
{
pwm2=1;
Timer0(pwm[1]);
} break;
case 4:
{
pwm2=0;
Timer0(2500-pwm[1]);
} break;
case 5:
{
pwm3=1;
Timer0(pwm[2]);
} break;
case 6:
{
pwm3=0;
Timer0(2500-pwm[2]);
} break;
case 7:
{
pwm4=1;
Timer0(pwm[3]);
} break;
case 8:
{
pwm4=0;
Timer0(2500-pwm[3]);
} break;
case 9:
{
pwm5=1;
Timer0(pwm[4]);
} break;
case 10:
{
pwm5=0;
Timer0(2500-pwm[4]);
} break;
case 11:
{
pwm6=1;
Timer0(pwm[5]);
} break;
case 12:
{
pwm6=0;
Timer0(2500-pwm[5]);
} break;

case 13:
{
pwm7=1;
Timer0(pwm[6]);
} break;
case 14:
{
pwm7=0;
Timer0(2500-pwm[6]);
} break;

case 15:
{
pwm8=1;
Timer0(pwm[7]);
} break;
case 16:
{
pwm8=0;
Timer0(2500-pwm[7]);
i=0;
} break;

default:break;

}

i++;
}

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

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

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

微信扫一扫关注我们

返回顶部