标题:按键控制舵机PWM电路C语言版XTAL218XTAL119ALE30EA31PSEN29RST9P0.0/AD039P0.1/AD138P0.2/AD237P0.3/AD336P0.4/AD435P0.5/AD534P0.6/AD633P0.7/AD732P1.01P1.12P1.23P1.34P1.45P1.56P1.67P1.78P3.0/RXD10P3.1/TXD11P3.2/INT012P3.3/INT113P3.4/T014P3.7/RD17P3.6/WR16P3.5/T115P2.7/A1528P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427U1AT89C51+88.8+5VABRSTCLKCE/***********************************************舵机54°正反转***********************************************/#includereg52.h#defineucharunsignedchar#defineuintunsignedintucharperiod,rate;//舵机控制信号周期,20ms,和占空比调节sbitpwm=P0^0;//舵机输出线信号//延时函数用来正反转延时/**************************************************延时函数**************************************************/voiddelay(uchart){uinti;while(t--){for(i=0;i1000;i++);//40000}}/**************************************************定时器初始化子程序***************************************************/voidTimer1Init(){TMOD|=0x20;//使用模式1,16位定时器//00100000TH1=0x9c;//赋初值//10011100//65535-156=65379TL1=0x9c;//10011100//65535-156=65379ET1=1;//定时器中断打开EA=1;//总中断打开TR1=1;//定时器开关打开}/********************************************************主函数**********************************************************/voidmain(){Timer1Init();rate=15;//rate=5,0度;rate=10,45度;rate=15,90度;rate=20,135度;rate=25,180度;while(1){rate=12;delay(60);rate=18;delay(60);}}voidTimer1Isr(void)interrupt3{period++;if(period200)period=0;if(periodrate)pwm=1;elsepwm=0;}