赞助论坛
  • 1943阅读
  • 0回复

刚写了段旋转编码器程序,求指正! [复制链接]

楼层直达
zzt175  
发帖
12
精华
0
金币
63
威望
0
贡献
0
好评
0
注册
2012-09-06
楼主    zzt175 发表于: 2014-07-29 17:43:52 
#if RotationKEY
BYTE Key_GetRotationKeypadStatus(void)
{
   static BYTE ReadRoKey=0,RotationKeyFlag;
   BYTE RotationKeyTemp;
   RotationKeyTemp=P4;    
   RotationKeyTemp=(RotationKeyTemp&0x18);
   if(RotationKeyTemp==0x00)
       {
       ReadRoKey=1;
       RotationKeyFlag=_LOW;
   }
   else if(RotationKeyTemp==0x18)
       {
       ReadRoKey=1;
       RotationKeyFlag=_HIGH;        
   }
   if(ReadRoKey)
       {
       if(RotationKeyFlag==_LOW)
           {
               if(RotationKeyTemp==0x10)
                   {
                   ReadRoKey=0;
                   return KEY_RIGHT;
               }
               else if(RotationKeyTemp==0x08)
                   {
                   ReadRoKey=0;
                   return KEY_LEFT;
               }
       }
       else if(RotationKeyFlag==_HIGH)
           {
               if(RotationKeyTemp==0x08)
                   {
                   ReadRoKey=0;
                   return KEY_RIGHT;
               }
               else if(RotationKeyTemp==0x10)
                   {
                   ReadRoKey=0;
                   return KEY_LEFT;
               }
       }        
   }
   return KEY_Idle;
}
#endif
本帖最近评分记录: 1 条评分