add encoder
parent
9b4d68fd6f
commit
1c467ff192
@ -1,21 +1,52 @@
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
#include "avr-hd44780/lcd.h"
|
||||
|
||||
volatile uint8_t counter = 0;
|
||||
|
||||
void enc_init(){
|
||||
PORTC |= (1<<2) | (1 << 3);
|
||||
PCICR |= (1<<PCIE1);
|
||||
PCMSK1 |= (1<<PCINT10);
|
||||
}
|
||||
|
||||
int main(void){
|
||||
DDRC |= 1<<0;
|
||||
DDRC |= 1<<1;
|
||||
DDRD |= 1<<7;
|
||||
DDRC |= 1<<0;
|
||||
DDRC |= 1<<1;
|
||||
DDRD |= 1<<7;
|
||||
|
||||
PORTC ^= 1<<0;
|
||||
_delay_ms(1000);
|
||||
PORTC ^= 1<<1;
|
||||
|
||||
lcd_init();
|
||||
lcd_on();
|
||||
lcd_init();
|
||||
lcd_on();
|
||||
lcd_clear();
|
||||
lcd_puts("test");
|
||||
|
||||
enc_init();
|
||||
sei();
|
||||
|
||||
while(1){
|
||||
lcd_clear();
|
||||
lcd_puts("test");
|
||||
lcd_printf("%d", counter);
|
||||
_delay_ms(50);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while(1){
|
||||
PORTC ^= 1<<0;
|
||||
_delay_ms(1000);
|
||||
PORTC ^= 1<<1;
|
||||
}
|
||||
ISR(PCINT1_vect){
|
||||
if(PINC & (1<<2)){
|
||||
if(PINC & (1<<3))
|
||||
counter--;
|
||||
else if(!(PINC & (1<<3)))
|
||||
counter++;
|
||||
}else{
|
||||
if(PINC & (1<<3))
|
||||
counter++;
|
||||
else if(!(PINC & (1<<3)))
|
||||
counter--;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue