//P1.0~P1.7分别对应小车1N1~1N8。
#include //头文件
#define uint unsigned int //宏定义
#define uchar unsigned char
#define left_moto_go {P1_0=1,P1_1=0,P1_2=1,P1_3=0;} //小车方位定义,左边两个电机正转(前进)
#define left_moto_back {P1_0=0,P1_1=1,P1_2=0,P1_3=1;}∥左后退
#define left_moto_stop {P1_0=0,P1_1=0,P1_2=0,P1_3=0;}∥左停止
#define right_moto_go {P1_4=1,P1_5=0,P1_6=1,P1_7=0;}
#define right_moto_back {P1_4=0,P1_5=1,P1_6=0,P1_7=1;}
#define right_moto_stop {P1_4=0,P1_5=0,P1_6=0,P1_7=0;}
#define left_moto_pwm P1_1 //pwm信号端定义
#define left_moto_pwm1 P1_3
#define right_moto_pwm P1_5
#define right_moto_pwm1 P1_7
sbit key0=P3^2; //四位按键位声明
sbit key1=P3^3;
sbit key2=P3^4;
sbit key3=P3^5;
uchar T0RH,T0RL; // 定时器配置
//uchar time; // pwm周期变量
uchar keybuf; // 按键
uchar code tab[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90}; //共阳数码管显示数字0~9
uchar code dis[]={0XF7,0XFB,0XFD,0XFE}; //数码管位选
uchar disbuf[4]={0}; //数码管中间变量
uchar pwm_val_left=0; // 占空比有关变量
uchar push_val_left=0; // 左电机占空比 N/10