速等级个位 P2=0x08;delay(1);?P2=0x00;}voidkey()//按键判断{if(key_reset==0) { delay(5); if(key_reset==0) reset();}if(key_z==0) { delay(5); if(key_z==0) {flag=0;speed=10; while(key_z==0);}}if(key_f==0) { delay(5); if(key_f==0) { flag=1; speed=10; while(key_f==0);}}if(key_jia==0) { delay(5); if(key_jia==0) { speed++; if(speed==21) speed=20; while(key_jia==0);}}if(key_jian==0) { delay(5); if(key_jian==0) { speed--; if(speed<=0) speed=0; while(key_jian==0);}}}voiddispose()//控制电机旋转的快慢{if(speed==0)flag=2;elsemaichong=240-speed*20;}?voidzhuandong(void){uinti,j;?if(speed>0&&speed<=20){for(j=0;j<4;j++)//正反转执行{if(flag==0) P1=table1[j];?else P1=table2[j];?for(i=0;i<maichong;i++) display();}}}?voidmain(){reset();?display();?for(;;)?{key(); dispose(); if(flag==2) display();?else zhuandong();?}}6仿真与调试6.1仿真调试的操作步骤