You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
765 B
C
53 lines
765 B
C
#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;
|
|
|
|
PORTC ^= 1<<0;
|
|
_delay_ms(1000);
|
|
PORTC ^= 1<<1;
|
|
|
|
lcd_init();
|
|
lcd_on();
|
|
lcd_clear();
|
|
lcd_puts("test");
|
|
|
|
enc_init();
|
|
sei();
|
|
|
|
while(1){
|
|
lcd_clear();
|
|
lcd_printf("%d", counter);
|
|
_delay_ms(50);
|
|
}
|
|
|
|
}
|
|
|
|
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--;
|
|
|
|
}
|
|
}
|