zoukankan      html  css  js  c++  java
  • EC11编码器硬件电路及程序

    EC11编码器 两个引脚那一端为普通的按键,也就是圆柄按下去的那个按键,当做普通按键使用即可

    右边三个引脚中间的为GND,两边为两路脉冲信号

    外围电路见图

    程序设计思路,检测其中一路的下降沿,触发中断,然后读另外一个IO口的高低电平,从而确定转动方向

    电路图为网上截图,只用其中一半即可

    单片机为MSP430F169

     1 #include <msp430x16x.h>
     2 
     3 int count=50;
     4 int main(void)
     5 {
     6 
     7   WDTCTL = WDTPW + WDTHOLD;                 // 关闭看门狗定时器
     8   
     9   P1IE |=  BIT1;                            // P1.1 中断使能
    10   P1IES |= BIT1;                            // P1.1 下降沿触发
    11   P1IFG &= ~BIT1;                           // P1.1 中断标志位清零
    12   _EINT();                 //全局中断使能
    13                                         
    14   while(1);
    15 }
    16 
    17 // Port 1 interrupt service routine
    18 #pragma vector=PORT1_VECTOR
    19 __interrupt void Port_1(void)
    20 {
    21   for(int i=0;i<1000;i++);          //延时消抖
    22   if((P1IN&BIT2)==0)
    23       count++;                
    24   else if((P1IN&BIT2)==0x04)
    25       count--;
    26   P1IFG &= ~BIT1;                 // P1.1 中断标志位清零
    27 }
    View Code
  • 相关阅读:
    Codeforces 385C
    Codeforces 496C
    HDU 6114 Chess
    Codeforces 839B
    Codeforces 483B
    Codeforces 352B
    Codeforces 768B
    Codeforces 38B
    Codeforces 735B
    Codeforces 534B
  • 原文地址:https://www.cnblogs.com/duanjinjie/p/9392460.html
Copyright © 2011-2022 走看看