|
|
|
|
#include "pwm.h"
|
|
|
|
|
|
|
|
|
|
unsigned char pwm_val_left =0;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
unsigned char push_val_left =0;// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>ձ<EFBFBD>N/20
|
|
|
|
|
unsigned char pwm_val_right =0;
|
|
|
|
|
unsigned char push_val_right=0;// <EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD>ձ<EFBFBD>N/20
|
|
|
|
|
unsigned char pwm_left=0;
|
|
|
|
|
|
|
|
|
|
bit Right_moto_stop=1;
|
|
|
|
|
bit Left_moto_stop =1;
|
|
|
|
|
|
|
|
|
|
unsigned int time1=0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
//<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void delay(unsigned int k)
|
|
|
|
|
{
|
|
|
|
|
unsigned int x,y;
|
|
|
|
|
for(x=0;x<k;x++)
|
|
|
|
|
for(y=0;y<2000;y++);
|
|
|
|
|
}
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
//ǰ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>
|
|
|
|
|
void run(void)
|
|
|
|
|
{
|
|
|
|
|
push_val_left=3; //<EFBFBD>ٶȵ<EFBFBD><EFBFBD>ڱ<EFBFBD><EFBFBD><EFBFBD> 0-20<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD>20<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
push_val_right=pwm_left;
|
|
|
|
|
Left_moto_go ; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>
|
|
|
|
|
Right_moto_go ; //<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void backrun(void)
|
|
|
|
|
{
|
|
|
|
|
push_val_left=3; //<EFBFBD>ٶȵ<EFBFBD><EFBFBD>ڱ<EFBFBD><EFBFBD><EFBFBD> 0-20<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD>20<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
push_val_right=4;
|
|
|
|
|
Left_moto_back; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>
|
|
|
|
|
Right_moto_back; //<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<EFBFBD><EFBFBD>ת
|
|
|
|
|
void leftrun(void)
|
|
|
|
|
{
|
|
|
|
|
push_val_left=0;
|
|
|
|
|
push_val_right=4;
|
|
|
|
|
Right_moto_go ; //<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<EFBFBD><EFBFBD>ת
|
|
|
|
|
void rightrun(void)
|
|
|
|
|
{
|
|
|
|
|
push_val_right=0;
|
|
|
|
|
push_val_left=4;
|
|
|
|
|
Left_moto_go ; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void pwm_out_left_moto(void)
|
|
|
|
|
{
|
|
|
|
|
if(Left_moto_stop)
|
|
|
|
|
{
|
|
|
|
|
if(pwm_val_left<=push_val_left)
|
|
|
|
|
{
|
|
|
|
|
Left_moto_pwm=1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Left_moto_pwm=0;
|
|
|
|
|
}
|
|
|
|
|
if(pwm_val_left>=20)
|
|
|
|
|
pwm_val_left=0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Left_moto_pwm=0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
/* <EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
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<EFBFBD><EFBFBD>ʱ
|
|
|
|
|
TL1=0X18;
|
|
|
|
|
time1++;
|
|
|
|
|
// pwm_val_left++;
|
|
|
|
|
pwm_val_right++;
|
|
|
|
|
// pwm_out_left_moto();
|
|
|
|
|
pwm_out_right_moto();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|