《舵机控制程序》word版
《舵机控制程序》word版本文简介:舵机控制程序8路舵机控制器芯片:AT89S52晶振:12MHz===================================================================================*/#include#defineuint8unsignedchar#d
《舵机控制程序》word版本文内容:
舵机控制程序
8路舵机控制器
芯片:AT89S52
晶振:12MHz
===================================================================================*/
#i
nclude
#define
uint8
unsigned
char
#define
uint16
unsigned
int
***it
key1=P1^4;
***it
key2=P1^5;
//PWM的输出端口
***it
PWM_OUT0=P0^0;
***it
PWM_OUT1=P0^1;
***it
PWM_OUT2=P0^2;
***it
PWM_OUT3=P0^3;
***it
PWM_OUT4=P0^4;
***it
PWM_OUT5=P0^5;
***it
PWM_OUT6=P0^6;
***it
PWM_OUT7=P0^7;
//PWM的数据值
uint16
PWM_Value[8]={1500,1000,1500,1000,1750,2000,2500,2000};
uint8
order1;
//定时器扫描序列
/*===================================================================================
定时器T0的中断服务程序
一个循环20MS
=
8*2.5ms
=====================================================================================*/
void
timer0(void)
interrupt
1
using
1
{
switch(order1)
{
case
1:
PWM_OUT0=1;
TH0=-PWM_Value[0]/256;
TL0=-PWM_Value[0]%256;
break;
case
2:
PWM_OUT0=0;
TH0=-(2700-PWM_Value[0])/256;
TL0=-(2700-PWM_Value[0])%256;
break;
case
3:
PWM_OUT1=1;
TH0=-PWM_Value[1]/256;
TL0=-PWM_Value[1]%256;
break;
case
4:
PWM_OUT1=0;
TH0=-(2700-PWM_Value[1])/256;
TL0=-(2700-PWM_Value[1])%256;
break;
case
5:
PWM_OUT2=1;
TH0=-PWM_Value[2]/256;
TL0=-PWM_Value[2]%256;
break;
case
6:
PWM_OUT2=0
;
TH0=-(2700-PWM_Value[2])/256;
TL0=-(2700-PWM_Value[2])%256;
break;
case
7:
PWM_OUT3=1;
TH0=-PWM_Value[3]/256;
TL0=-PWM_Value[3]%256;
break;
case
8:
PWM_OUT3=0;
TH0=-(2700-PWM_Value[3])/256;
TL0=-(2700-PWM_Value[3])%256;
break;
case
9:
PWM_OUT4=1;
TH0=-PWM_Value[4]/256;
TL0=-PWM_Value[4]%256;
break;
case
10:
PWM_OUT4=0;
TH0=-(2700-PWM_Value[4])/256;
TL0=-(2700-PWM_Value[4])%256;
break;
case
11:
PWM_OUT5=1;
TH0=-PWM_Value[5]/256;
TL0=-PWM_Value[5]%256;
break;
case
12:
PWM_OUT5=0;
TH0=-(2700-PWM_Value[5])/256;
TL0=-(2700-PWM_Value[5])%256;
break;
case
13:
PWM_OUT6=1;
TH0=-PWM_Value[6]/256;
TL0=-PWM_Value[6]%256;
break;
case
14:
PWM_OUT6=0;
TH0=-(2700-PWM_Value[6])/256;
TL0=-(2700-PWM_Value[6])%256;
break;
case
15:
PWM_OUT7=1;
TH0=-PWM_Value[7]/256;
TL0=-PWM_Value[7]%256;
break;
case
16:
PWM_OUT7=0;
order1=0;
TH0=-(2700-PWM_Value[7])/256;
TL0=-(2700-PWM_Value[7])%256;
order1=0;
break;
default
:
order1=0;
}
order1++;
}
/*===================================================================================
初始化中断
=====================================================================================*/
void
InitPWM(void)
{
order1=1;
TMOD
|=0x11;
TH0=-1500/256;
TL0=-1500%256;
EA=1;
EX0=0;
ET0=1;
TR0=1;PT0=1;PX0=0;
}
void
delay(void)
{
uint16
i=100;
while(i--);
}
void
main(void)
{
InitPWM();
while(1)
{
if(key1==0)
{
if(PWM_Value[0]500)
PWM_Value[0]--;
}
delay();
}
}
上一篇:虚数和复数的区别
下一篇:罗马阳光地板的优缺点
