独立按键点亮LED

#include<reg52.h>
sbit key_left=P1^0;
sbit led4=P1^4;
void main(void)
{
  unsigned char KeyStep=0;
  unsigned short int KeyDelay=0;
  while(1)
  {
   switch(KeyStep)
   {
    case 0:
        if(!key_left)
        {
          KeyDelay=0;
          KeyStep=1;
          }
    break;
    case 1:
        if(KeyDelay++>1000)
        {
        KeyStep=2;
        }
    break;
    case 2:
        if(!key_left)
        {
          led4=~led4;
          KeyStep=3;
          }
          else
          {
           KeyStep=0;
           }
    break;
    
    case 3:
         if(key_left) 
         {
         KeyStep=0;
         }
    break;
    default:
    break;
    }
  }
}

 

posted @ 2015-03-22 22:37  zhaoyang16  阅读(180)  评论(0编辑  收藏  举报