static uint ServoControl = 0; 或 uint ServoControl = 0; // 定义一个全局量 保存串口中断函数中赋的值 0或1 
// 但是ServoControl 无法保留上次的值。 
比如:发送0xFF设为1,再发一个0x02 发现ServoControl是0 
void Com() interrupt 4      //串口中断 
{ 
        uint Pwmvalue=0; 
        if(RI) 
        { 
                RI=0;  
                Pwmvalue=SBUF; 
                if(Pwmvalue==0x00)  
                { 
                        ServoControl=0;         
                        P0=0x00; // 接LED灯测试用的 
                } 
                if(Pwmvalue==0xFF)  
                { 
                        ServoControl=1; 
                        P0=0xFF;                                 
                } 
                if(ServoControl==1) 
                { 
                        P1=0x00; 
                } 
                if(ServoControl==0) 
                { 
                        P1=0xFF; 
                } 
        }         
} |   
     
  
 |