add encoder

This commit is contained in:
agsler
2024-01-13 00:37:07 +01:00
parent 9b4d68fd6f
commit 1c467ff192

View File

@@ -1,21 +1,52 @@
#include <avr/io.h> #include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h> #include <util/delay.h>
#include "avr-hd44780/lcd.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){ int main(void){
DDRC |= 1<<0; DDRC |= 1<<0;
DDRC |= 1<<1; DDRC |= 1<<1;
DDRD |= 1<<7; DDRD |= 1<<7;
lcd_init(); PORTC ^= 1<<0;
lcd_on(); _delay_ms(1000);
PORTC ^= 1<<1;
lcd_init();
lcd_on();
lcd_clear();
lcd_puts("test");
enc_init();
sei();
while(1){
lcd_clear(); 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--;
}
}