44 lines
919 B
C
44 lines
919 B
C
#define ENC_CLK 0b00000100
|
|
#define ENC_DAT 0b00001000
|
|
#define ENC_PIN PIND
|
|
//----------------------------------------------------------------------
|
|
int state;
|
|
int old_state = 0;
|
|
//----------------------------------------------------------------------
|
|
int encoder()
|
|
{
|
|
if ( !(ENC_PIN & ENC_CLK) )
|
|
{
|
|
if ( ENC_PIN & ENC_DAT)
|
|
{
|
|
state++;
|
|
}
|
|
if ( !(ENC_PIN & ENC_DAT) )
|
|
{
|
|
state--;
|
|
}
|
|
while(!(ENC_PIN & ENC_CLK))
|
|
{
|
|
|
|
}
|
|
}
|
|
return state;
|
|
}
|
|
//----------------------------------------------------------------------
|
|
void encoder_Initialization()
|
|
{
|
|
DDRD = 0b00000010;
|
|
PORTD = 0b00001110;
|
|
}
|
|
//----------------------------------------------------------------------
|
|
int get_encoder_value()
|
|
{
|
|
encoder();
|
|
if(old_state != state)
|
|
{
|
|
old_state = encoder();
|
|
}
|
|
return state;
|
|
}
|
|
//----------------------------------------------------------------------
|