# simple avr using a rotory encoder

**URL:** <https://community.sparkfun.com/t/simple-avr-using-a-rotory-encoder/10502>\
**Category:** MicroMod\
**Tags:** avr-atmel\
**Created:** [March 19, 2009, 4:33pm UTC](https://community.sparkfun.com/t/simple-avr-using-a-rotory-encoder/10502 "2009-03-19T16:33:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xntp](https://avatars.discourse-cdn.com/v4/letter/x/4bbf92/32.png) [@xntp](https://community.sparkfun.com/u/xntp)\
**Post date:** [March 19, 2009, 4:33pm UTC](https://community.sparkfun.com/t/simple-avr-using-a-rotory-encoder/10502/1 "2009-03-19T16:33:38Z")

</div>

```auto
#include<90s2313.h>

#define enc_a PIND.3
#define enc_b PIND.4

bit a, b;

void main(void)
{

  signed char d;

  PORTB=0xFF;
  DDRB=0xFF;

  PORTD=0x18;
  DDRD=0x07;

  while (1)
    {
      if(a != enc_a || b != enc_b)
        {
          if(enc_a ^ b)
            d++;
          else
            d--;
          a = enc_a;
          b = enc_b;
        }

    }
}

```

```auto

```
