#include "pwm.h" unsigned char pwm_val_left =0;//变量定义 unsigned char push_val_left =0;// 左电机占空比N/20 unsigned char pwm_val_right =0; unsigned char push_val_right=0;// 右电机占空比N/20 unsigned char pwm_left=0; bit Right_moto_stop=1; bit Left_moto_stop =1; unsigned int time1=0; /************************************************************************/ //延时函数 void delay(unsigned int k) { unsigned int x,y; for(x=0;x=20) pwm_val_left=0; } else { Left_moto_pwm=0; } } /******************************************************************/ /* 右电机调速 */ void pwm_out_right_moto(void) { if(Right_moto_stop) { if(pwm_val_right<=push_val_right) { Right_moto_pwm=1; } else { Right_moto_pwm=0; } if(pwm_val_right>=20) pwm_val_right=0; } else { Right_moto_pwm=0; } } void timer1()interrupt 3 { TH1=0XFc; //1Ms定时 TL1=0X18; time1++; // pwm_val_left++; pwm_val_right++; // pwm_out_left_moto(); pwm_out_right_moto(); }