#define uchar unsigned char
#define uint unsigned int
#define GPIO_KEY P2
sbit PWM=P1^4;
sbit P10=P1^0;
sbit P12=P1^2;
uchar speed1[4]={"0000"};//设定转速
uchar speed2[3]={"000"};//占空比
uchar speed[]={"0000"};//当前转速
uchar KeyValue=0;
uint AA,count=0,flag;
float pid_p=0.003,pid_i=0.003,pid_d=0.002; //PID三个参数 初值
uint SpeedSet=3000,CurrentSpeed;//设定转速 当前转速
unsigned char pid_val_mid;//pid_val_mid脉冲宽度
unsigned int lastError=0;
long int sumError=0;//sum偏差和
void delay1(unsigned int i)
{
unsigned int j;
for(;i>0;i--)
for(j=0;j<333;j++)
{;}
}
/********************* 键盘扫描*************/
void KeyDown(void)
{
GPIO_KEY=