《舵机控制程序1.doc》由会员分享,可在线阅读,更多相关《舵机控制程序1.doc(4页珍藏版)》请在三一办公上搜索。
1、舵机控制程序8路舵机控制器 芯片:AT89S52晶振:12MHz=*/i nclude#define uint8 unsigned char#define uint16 unsigned intsbit key1=P14;sbit key2=P15;/PWM的输出端口sbit PWM_OUT0=P00;sbit PWM_OUT1=P01;sbit PWM_OUT2=P02;sbit PWM_OUT3=P03;sbit PWM_OUT4=P04;sbit PWM_OUT5=P05;sbit PWM_OUT6=P06;sbit PWM_OUT7=P07;/PWM的数据值uint16 PWM_Val
2、ue8=1500,1000,1500,1000,1750,2000,2500,2000;uint8 order1; /定时器扫描序列/*= 定时器T0的中断服务程序 一个循环20MS = 8*2.5ms=*/void timer0(void) interrupt 1 using 1switch(order1)case 1: PWM_OUT0=1; TH0=-PWM_Value0/256; TL0=-PWM_Value0%256; break;case 2: PWM_OUT0=0; TH0=-(2700-PWM_Value0)/256; TL0=-(2700-PWM_Value0)%256; b
3、reak;case 3: PWM_OUT1=1; TH0=-PWM_Value1/256; TL0=-PWM_Value1%256; break;case 4: PWM_OUT1=0; TH0=-(2700-PWM_Value1)/256; TL0=-(2700-PWM_Value1)%256; break;case 5: PWM_OUT2=1; TH0=-PWM_Value2/256; TL0=-PWM_Value2%256; break;case 6: PWM_OUT2=0 ; TH0=-(2700-PWM_Value2)/256; TL0=-(2700-PWM_Value2)%256;
4、break;case 7: PWM_OUT3=1; TH0=-PWM_Value3/256; TL0=-PWM_Value3%256; break;case 8: PWM_OUT3=0; TH0=-(2700-PWM_Value3)/256; TL0=-(2700-PWM_Value3)%256; break;case 9: PWM_OUT4=1; TH0=-PWM_Value4/256; TL0=-PWM_Value4%256; break;case 10: PWM_OUT4=0; TH0=-(2700-PWM_Value4)/256; TL0=-(2700-PWM_Value4)%256;
5、 break;case 11: PWM_OUT5=1; TH0=-PWM_Value5/256; TL0=-PWM_Value5%256; break;case 12: PWM_OUT5=0; TH0=-(2700-PWM_Value5)/256; TL0=-(2700-PWM_Value5)%256; break;case 13: PWM_OUT6=1; TH0=-PWM_Value6/256; TL0=-PWM_Value6%256; break;case 14: PWM_OUT6=0; TH0=-(2700-PWM_Value6)/256; TL0=-(2700-PWM_Value6)%
6、256; break;case 15: PWM_OUT7=1; TH0=-PWM_Value7/256; TL0=-PWM_Value7%256; break;case 16: PWM_OUT7=0; order1=0; TH0=-(2700-PWM_Value7)/256; TL0=-(2700-PWM_Value7)%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_Value0500) PWM_Value0-; delay();