diff --git a/EmbeddedSystemsTHM/CLI.c b/EmbeddedSystemsTHM/CLI.c index 14ce601..ed8774f 100644 --- a/EmbeddedSystemsTHM/CLI.c +++ b/EmbeddedSystemsTHM/CLI.c @@ -281,6 +281,7 @@ static void cmd_led_on(const char* _data){ } } + //================================================================================================================================ // Funktion: cmd_led_off // Kann verwendet werden, um eine LED auszuschalten @@ -349,8 +350,6 @@ static void cmd_adc(const char* _data){ char lm35Data[50]; int loopInterval = 500; - int repeat = strcmp(_data, "R") == 0 ? 1 : 0; /* Check if repeat flag is set*/ - do { if(Timer_getTick() - g_startMS >= loopInterval){ @@ -372,14 +371,13 @@ static void cmd_adc(const char* _data){ print_string("----------"); print_string(NEXT_LINE); } - } while (repeat); // repeat if repeat-flag is given - - + } while (strcmp(_data, "R") == 0 ? 1 : 0); /* Check if repeat flag is set*/ } + //================================================================================================================================ // Funktion: cmd_rotary -// Wird verwendet um die Daten von Poti und LM35 zu lesen +// Wird verwendet um die Bewegung von Dregeber zu lesen // Parameter: _data: Zeichenkette mit Parametern des Befehls. // // Rückgabewert: keine diff --git a/EmbeddedSystemsTHM/adc.c b/EmbeddedSystemsTHM/adc.c index e3499d8..a0c6e34 100644 --- a/EmbeddedSystemsTHM/adc.c +++ b/EmbeddedSystemsTHM/adc.c @@ -7,42 +7,73 @@ #include "adc.h" +typedef struct ADC_t ADC_t; +struct ADC_t{ + /* ADC Data */ + uint16_t uiADC :16; + + /* ADCSRA */ + uint8_t uiADPS0 :1; + uint8_t uiADPS1 :1; + uint8_t uiADPS2 :1; + uint8_t uiADIE :1; + uint8_t uiADIF :1; + uint8_t uiADATE :1; + uint8_t uiADSC :1; + uint8_t uiADEN :1; + + /* ADCSRB */ + uint8_t uiADTS0 :1; + uint8_t uiADTS1 :1; + uint8_t uiADTS2 :1; + uint8_t nui2 :3; + uint8_t uiACME :1; + uint8_t nui1 :1; + + /* ADMUX */ + uint8_t uiMUX :5; + uint8_t uiADLAR :1; + uint8_t uiREFS0 :1; + uint8_t uiREFS1 :1; +}; + +#define myADC ((ADC_t*)(0x78)) + void adc_init(void) { - ADMUX = (1<uiADLAR = 0; + myADC->uiREFS0 = 0; /* Set ADLAR to 0 to not left adjust the presentation of the conversion result */ + myADC->uiREFS1 = 0; /* Set Voltage reference to 2.56V */ - ADCSRA = (1<uiADPS0 = 1; /* Set ADC Prescaler to 128 */ + myADC->uiADPS1 = 1; + myADC->uiADPS2 = 1; + myADC->uiADIE = 1; /* Enable the ADC interrupt */ + myADC->uiADATE = 0; /* Disable the ADC auto trigger */ + myADC->uiADEN = 1; /* Enable ADC */ } volatile int done = 1; /* ADC 1 */ -uint16_t +uint16_t adc_get_poti(void) { uint16_t adc; - ADCSRA &= ~(1<uiADIE = 0; /* Disable interrupt */ + + myADC->uiMUX = 1; /* Set ADMUX to access ADC channel 1 */ + + myADC->uiADSC = 1; /* Start the conversion */ done = 0; /* reset the done flag to false */ - while(done == 0); /* Wait till conversion completes */ - adc = ADC; + adc = myADC->uiADC; - ADCSRA |= (1<uiADIE = 1; /* Enable the interrupt again */ return adc; } @@ -53,18 +84,19 @@ uint16_t adc_get_LM35(void) { uint16_t adc; - ADCSRA &= ~(1<uiADIE = 0; /* Disable interrupt */ + + myADC->uiMUX = 0; /* Set ADMUX to access ADC channel 1 */ + + myADC->uiADSC = 1; /* Start the conversion */ + done = 0; /* reset the done flag to false */ - while(done == 0); /* Wait till conversion completes */ - adc = ADC; + adc = myADC->uiADC; - ADCSRA |= (1<uiADIE = 1; /* Enable the interrupt again */ return adc; } diff --git a/EmbeddedSystemsTHM/rotaryEncoder.c b/EmbeddedSystemsTHM/rotaryEncoder.c index bdef5fa..6e9645f 100644 --- a/EmbeddedSystemsTHM/rotaryEncoder.c +++ b/EmbeddedSystemsTHM/rotaryEncoder.c @@ -13,9 +13,9 @@ /* enums */ enum{ - S2, S3, S4, S5, S6, S7, + LEFT1, LEFT2, LEFT3, RIGHT1, RIGHT2, RIGHT3, INIT, WAIT - } RotaryState = INIT; /* Emus for the stoplight task (task 3) */ + } RotaryState = INIT; /* Enum for the rotary enc */ int16_t count; @@ -24,23 +24,12 @@ drehgeber_init(void) { DDRC &= ~(7<