欢迎来到天天文库
浏览记录
ID:33970234
大小:27.50 KB
页数:4页
时间:2019-03-02
《《舵机控制程序》word版》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、舵机控制程序8路舵机控制器芯片:AT89S52晶振:12MHz===================================================================================*/#include#defineuint8 unsignedchar#defineuint16unsignedintsbitkey1=P1^4;sbitkey2=P1^5;//PWM的输出端口sbitPWM_OUT0=P0^0;sbitPWM_OUT1=P0^1;sbit
2、PWM_OUT2=P0^2;sbitPWM_OUT3=P0^3;sbitPWM_OUT4=P0^4;sbitPWM_OUT5=P0^5;sbitPWM_OUT6=P0^6;sbitPWM_OUT7=P0^7;//PWM的数据值uint16PWM_Value[8]={1500,1000,1500,1000,1750,2000,2500,2000};uint8order1; //定时器扫描序列/*==============================================================
3、===================== 定时器T0的中断服务程序 一个循环20MS =8*2.5ms=====================================================================================*/voidtimer0(void)interrupt1using1{ switch(order1) { case1: PWM_OUT0=1; TH0=-PWM_Value[0]/256; TL0=-PWM
4、_Value[0]%256; break; case2: PWM_OUT0=0; TH0=-(2700-PWM_Value[0])/256; TL0=-(2700-PWM_Value[0])%256; break; case3: PWM_OUT1=1; TH0=-PWM_Value[1]/256; TL0=-PWM_Value[1]%256; break; case4: PWM_OUT1=0;
5、 TH0=-(2700-PWM_Value[1])/256; TL0=-(2700-PWM_Value[1])%256; break; case5: PWM_OUT2=1; TH0=-PWM_Value[2]/256; TL0=-PWM_Value[2]%256; break; case6: PWM_OUT2=0; TH0=-(2700-PWM_Value[2])/256; TL0=-(2700-P
6、WM_Value[2])%256; break; case7: PWM_OUT3=1; TH0=-PWM_Value[3]/256; TL0=-PWM_Value[3]%256; break; case8: PWM_OUT3=0; TH0=-(2700-PWM_Value[3])/256; TL0=-(2700-PWM_Value[3])%256; break; case9: PWM_OUT4=1;
7、 TH0=-PWM_Value[4]/256; TL0=-PWM_Value[4]%256; break; case10:PWM_OUT4=0; TH0=-(2700-PWM_Value[4])/256; TL0=-(2700-PWM_Value[4])%256; break; case11:PWM_OUT5=1; TH0=-PWM_Value[5]/256; TL0=-PWM_Value[
8、5]%256; break; case12:PWM_OUT5=0; TH0=-(2700-PWM_Value[5])/256; TL0=-(2700-PWM_Value[5])%256; break; case13:PWM_OUT6=1; TH0=-PWM_Value[6]/25
此文档下载收益归作者所有