Compare commits
2 Commits
c151a7bb67
...
f48f18ac64
| Author | SHA1 | Date | |
|---|---|---|---|
| f48f18ac64 | |||
| 3dafc11535 |
Binary file not shown.
BIN
code/inc/i2c
BIN
code/inc/i2c
Binary file not shown.
Binary file not shown.
BIN
code/inc/pinout
BIN
code/inc/pinout
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
code/inc/uart
BIN
code/inc/uart
Binary file not shown.
Binary file not shown.
69
code/src/encoder.c
Normal file
69
code/src/encoder.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#define ENC_PORT PORTD
|
||||
#define ENC_DDR DDRD
|
||||
#define ENC_A PIND&(1<<2)
|
||||
#define ENC_B PIND&(1<<4)
|
||||
#define ENC_CCW 0
|
||||
#define ENC_CW 1
|
||||
|
||||
void encoder_action(uint8_t dir);
|
||||
|
||||
volatile uint8_t encoder_direction;
|
||||
|
||||
ISR(INT0_vect)
|
||||
{
|
||||
if (ENC_B)
|
||||
{
|
||||
if (ENC_A)
|
||||
{
|
||||
encoder_direction = ENC_CCW;
|
||||
encoder_action(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder_direction = ENC_CW;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ENC_A)
|
||||
{
|
||||
encoder_direction = ENC_CW;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder_direction = ENC_CCW;
|
||||
encoder_action(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ISR (PCINT3_vect){
|
||||
if (ENC_B)
|
||||
{
|
||||
if (ENC_A)
|
||||
{
|
||||
encoder_direction = ENC_CW;
|
||||
encoder_action(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder_direction = ENC_CCW;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ENC_A)
|
||||
{
|
||||
encoder_direction = ENC_CCW;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder_direction = ENC_CW;
|
||||
encoder_action(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,20 @@ int8_t parse_nmea_gps(char input_string[RX_INPUT_BUFFER_SIZE], uint8_t output_bu
|
||||
return -1;
|
||||
}
|
||||
|
||||
void encoder_action(uint8_t dir){
|
||||
if (dir) {
|
||||
if(get_menu_active())
|
||||
menu_up_down(1);
|
||||
else
|
||||
OCR2A++;
|
||||
} else {
|
||||
if(get_menu_active())
|
||||
menu_up_down(-1);
|
||||
else
|
||||
OCR2A--;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void){
|
||||
setup();
|
||||
printf("Moin\n\r");
|
||||
@@ -134,14 +148,18 @@ void setup(){
|
||||
//--------------------------
|
||||
//External Interrupt Mask Register
|
||||
|
||||
EIMSK |= (1 << INT0) | //Aktiviere Interrupt INT0
|
||||
(1 << INT1); //Aktiviere Interrupt INT1
|
||||
EIMSK |= (1 << INT0) //Aktiviere Interrupt INT0
|
||||
| (1 << INT1); //Aktiviere Interrupt INT1
|
||||
|
||||
//External Interrupt Control Register A
|
||||
EICRA |= (0 << ISC10) | //Interrupt bei jedem Pegelwechsel auf INT1
|
||||
(1 << ISC11) |
|
||||
(1 << ISC00) | //Interrupt bei jedem Pegelwechsel auf INT0
|
||||
(1 << ISC01);
|
||||
EICRA |= (0 << ISC10) //Interrupt bei jedem Pegelwechsel auf INT1
|
||||
| (1 << ISC11)
|
||||
| (1 << ISC00) //Interrupt bei jedem Pegelwechsel auf INT0
|
||||
| (0 << ISC01);
|
||||
|
||||
// PCINT for ENCODER_B
|
||||
PCICR |= (1 << PCIE3);
|
||||
PCMSK3 |= (1 << PCINT28);
|
||||
|
||||
//--------------------------
|
||||
// Timer + Zeitinterrupts
|
||||
@@ -168,24 +186,8 @@ void setup(){
|
||||
|
||||
}
|
||||
|
||||
//Encoder rotate
|
||||
ISR(INT0_vect) {
|
||||
if (PIND & ENCODER_B) {
|
||||
if(get_menu_active())
|
||||
menu_up_down(1);
|
||||
else
|
||||
OCR2A++;
|
||||
} else {
|
||||
if(get_menu_active())
|
||||
menu_up_down(-1);
|
||||
else
|
||||
OCR2A--;
|
||||
}
|
||||
}
|
||||
|
||||
//Encoder Button
|
||||
ISR(INT1_vect) {
|
||||
printf("button\n\r");
|
||||
enter_menu();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,6 @@ int8_t menu_val_timezone;
|
||||
uint8_t menu_val_format_ee EEMEM;
|
||||
uint8_t menu_val_format;
|
||||
|
||||
//void debug_menu(){
|
||||
// printf("state: %d\r\n", state);
|
||||
// printf("selected: %d\r\n", selected);
|
||||
// printf("timezone: %d\r\n", menu_val_timezone);
|
||||
// printf("\r\n");
|
||||
//}
|
||||
|
||||
uint8_t get_menu_active(){
|
||||
if(state != OFF)
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user