#include <reg52.h>
#include <..\CONFIG\QXA51.h>
unsigned char pwm_left_val = 210;//左电机占空比值 取值范围0-170,0最快
unsigned char pwm_right_val = 210;//右电机占空比值取值范围0-170 ,0最快
unsigned char pwm_t;//周期
/*小车前进*/
void forward()
{
left_motor_go; //左电机前进
right_motor_go; //右电机前进
}
//定时器0中断
void timer0() interrupt 1
{
pwm_t++;
if(pwm_t == 255)
pwm_t = EN1 = EN2 = 0;
if(pwm_left_val == pwm_t)
EN1 = 1;
if(pwm_right_val == pwm_t)
EN2 = 1;
}
void main()
{
TMOD |= 0x02;//8位自动重装模块
TH0 = 220;
TL0 = 220;//11.0592M晶振下占空比最大比值是256,输出100HZ
TR0 = 1;//启动定时器0
ET0 = 1;//允许定时器0中断
EA = 1;//总中断允许
while(1)
{
forward();//前进
}
}
|