码迷,mamicode.com
首页 > 其他好文 > 详细

脉冲电位器编程

时间:2020-04-07 20:57:21      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:bsp   enable   gpio   tst   type   技术   mod   typedef   structure   

技术图片技术图片
u8 BUFFER=0xFF,data,WZ1,WZ2;

void IO_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9 | GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IPU;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB,&GPIO_InitStructure);
}
 
int main( void )
    IO_Init();
    while(1)
    {
        WZ1=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_8);//脉冲电位器3脚,2脚接地
        WZ2=GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_9);//脉冲电位器1脚
        if ((BUFFER&0x02)!=(WZ2<<1) || (BUFFER&0x01)!=WZ1) //状态有变化时处理
        {
            BUFFER=(BUFFER<<2) | (WZ2<<1) | WZ1;//更新状态值
            if ((BUFFER==0x4B )&&(data>0)) data--; //逆时针旋转
            if ((BUFFER==0x87)&&(data<100)) data++;//顺时针旋转
        }
     }
}

脉冲电位器编程

标签:bsp   enable   gpio   tst   type   技术   mod   typedef   structure   

原文地址:https://www.cnblogs.com/yitx/p/12655517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!