1、#include#define uchar unsigned char #define uint unsigned intuchar percent=50; /电动机初始状态为停止状态uchar period=100;sbit red=P02;sbit green=P03;sbit yellow=P00;sbit blue=P01;uchar i=0,j=0;uchar time;uint disx4;sbit PWM=P05;sbit Add=P23;sbit Dec=P22;sbit qidong=P20;sbit ting=P21;void delay(uchar n) /t=n*2mS
2、 uchar i,j,k;for(i=0;i=1) if(!Add) /加速控制按键识别delay(10);if(!Add)if(percent=50)else if(percent0) /最小值为 0percent=0;while(!Dec);if(!ting)delay(10);if(!ting) percent=50;red=0;yellow=1;green=1;blue=1;i=0; void main() TMOD=0x01; /定时工作方式 1 TH0=(65536-100)/256; /定时中断一次TL0=(65536-100)%256;EA=1;ET0=1;TR0=1;while(1) keyscan(); void timer0() interrupt 1 TH0=(65536-100)/256; TL0=(65536-100)%256;time+;if(time=percent) PWM=0; else if(time=period) PWM=1;time=0;