diff --git a/EmbeddedSystemsTHM/Led.c b/EmbeddedSystemsTHM/Led.c index 2dd0f82..fcddad5 100644 --- a/EmbeddedSystemsTHM/Led.c +++ b/EmbeddedSystemsTHM/Led.c @@ -2,17 +2,17 @@ void Led_init (void){ - DDRB = 0xFF; // Set all bits in the B Data-Direction Register to output - PORTB = 0x00; // Set all bits in the PORT B Register to low to turn all LEDs off + DDRB = 0xFF; /* Set all bits in the B Data-Direction Register to output */ + PORTB = 0x00; /* Set all bits in the PORT B Register to low to turn all LEDs off */ } void Led1_On (void){ - PORTB |= (1<<7); // Set the bit for LED_1 to hight to turn it on + PORTB |= (1<<7); /* Set the bit for LED_1 to hight to turn it on */ } void Led1_Off (void){ - PORTB &= ~(1<<7); // Set the bit for LED_1 to low to turn it off + PORTB &= ~(1<<7); /* Set the bit for LED_1 to low to turn it off */ } void diff --git a/EmbeddedSystemsTHM/Taster.c b/EmbeddedSystemsTHM/Taster.c index 772c30b..2b217c5 100644 --- a/EmbeddedSystemsTHM/Taster.c +++ b/EmbeddedSystemsTHM/Taster.c @@ -2,11 +2,20 @@ void Taster_init (void){ - DDRD &= ~(0b111<<5); // Set bit 5-7 of Data Direction Register D as input - DDRC &= ~(1<<2); // Set bit 2 of Data Direction Register C as input + DDRD &= ~(0b111<<5); /* Set bit 5-7 of Data Direction Register D as input */ + DDRC &= ~(1<<2); /* Set bit 2 of Data Direction Register C as input */ - PORTD |= (0b111<<5); // Initialize bit 5-7 of PORTD as for pull up resistor - PORTC |= (1<<2); // Initialize bit 2 of PORTC as for pull up resistor + PORTD |= (0b111<<5); /* Initialize bit 5-7 of PORTD as for pull up resistor */ + PORTC |= (1< #include -#ifdef F_CPU #define F_CPU 1000000 -#endif +#include /* function declarations */ +void buttonTest (void); void task1 (void); -void tast2 (void); +void task2 (void); +void task3 (void); /* global variables */ volatile int g_counter = 0; -int ledStatus = 0; -uint16_t startMS; +int g_ledStatus = 0; +uint16_t g_startMS; /* functions */ int @@ -33,44 +33,32 @@ main (void) Led_init(); Taster_init(); Timer_init(); - - /* Run Task 1 + g_startMS=Timer_getTick(); + while (1) { - task1(); - }//*/ - - - /* Run Task 2 */ - startMS=Timer_getTick(); - while (1) - { - task2(); - }//*/ + buttonTest(); + //task1(); + //task2(); + //task3(); + } } - -/* Task 2 (2021-10-28) */ -void -task2 () { - if(Timer_getTick()-startMS >= 1000) { /* Wait 1000ms before switching LED1 */ - startMS=Timer_getTick(); - - if(ledStatus % 2 == 0){ - Led1_On(); - } else { - Led1_Off(); - } - ledStatus++; - } +void +buttonTest (void) +{ + Taster1_get() ? Led1_On() : Led1_Off(); + Taster2_get() ? Led2_On() : Led2_Off(); + Taster3_get() ? Led3_On() : Led3_Off(); + Taster4_get() ? Led4_On() : Led4_Off(); } - /* Task 1 (2021-10-21) */ void -task1 () { - _delay_ms(50); +task1 (void) +{ + _delay_ms(100); /* Programmieren Sie ein Lauflicht. Nutzen Sie dazu die in „Led.h“ deklarierten * Funktionen. @@ -101,4 +89,26 @@ task1 () { g_counter >= 6 ? Led6_On() : Led6_Off(); g_counter >= 7 ? Led7_On() : Led7_Off(); g_counter >= 8 ? Led8_On() : Led8_Off(); +} + +/* Task 2 (2021-10-28) */ +void +task2 (void) +{ + if(Timer_getTick() - g_startMS >= 1000) { /* Wait 1000ms before switching LED1 */ + g_startMS=Timer_getTick(); + + if(g_ledStatus % 2 == 0){ + Led1_On(); + } else { + Led1_Off(); + } + g_ledStatus++; + } +} + +void +task3 (void) +{ + // beep boop } \ No newline at end of file