2021-10-21 19:55:33 +02:00
|
|
|
|
/*
|
|
|
|
|
* EmbeddedSystemProject.c
|
|
|
|
|
*
|
|
|
|
|
* Created: 21/10/2021 16:55:21
|
|
|
|
|
* Author : n0x
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Led.h"
|
|
|
|
|
#include "Taster.h"
|
2021-10-28 19:24:52 +02:00
|
|
|
|
#include "Timer.h"
|
2021-11-11 18:28:42 +01:00
|
|
|
|
#include "StopLight.h"
|
2021-10-28 19:24:52 +02:00
|
|
|
|
#include <avr/interrupt.h>
|
2021-10-21 19:55:33 +02:00
|
|
|
|
#define F_CPU 1000000
|
2021-11-11 01:33:55 +01:00
|
|
|
|
#include <util/delay.h>
|
2021-10-21 19:55:33 +02:00
|
|
|
|
|
2021-10-28 16:36:38 +02:00
|
|
|
|
/* function declarations */
|
2021-11-11 01:33:55 +01:00
|
|
|
|
void buttonTest (void);
|
2021-10-28 19:24:52 +02:00
|
|
|
|
void task1 (void);
|
2021-11-11 01:33:55 +01:00
|
|
|
|
void task2 (void);
|
2021-10-28 16:36:38 +02:00
|
|
|
|
|
2021-11-11 01:36:35 +01:00
|
|
|
|
|
2021-10-28 16:36:38 +02:00
|
|
|
|
/* global variables */
|
2021-10-28 19:24:52 +02:00
|
|
|
|
volatile int g_counter = 0;
|
2021-11-11 18:28:42 +01:00
|
|
|
|
uint8_t g_ledStatus = 0;
|
2021-11-11 01:33:55 +01:00
|
|
|
|
uint16_t g_startMS;
|
2021-10-28 16:36:38 +02:00
|
|
|
|
|
2021-11-11 18:28:42 +01:00
|
|
|
|
|
2021-10-28 16:36:38 +02:00
|
|
|
|
/* functions */
|
|
|
|
|
int
|
|
|
|
|
main (void)
|
2021-10-21 19:55:33 +02:00
|
|
|
|
{
|
2021-10-28 19:24:52 +02:00
|
|
|
|
sei();
|
|
|
|
|
|
|
|
|
|
/* Initialize the LEDs and Buttons */
|
2021-10-21 19:55:33 +02:00
|
|
|
|
Led_init();
|
|
|
|
|
Taster_init();
|
2021-10-28 19:24:52 +02:00
|
|
|
|
Timer_init();
|
2021-10-21 19:55:33 +02:00
|
|
|
|
|
2021-11-11 01:33:55 +01:00
|
|
|
|
g_startMS=Timer_getTick();
|
2021-11-05 09:00:41 +01:00
|
|
|
|
|
2021-11-11 01:33:55 +01:00
|
|
|
|
while (1)
|
2021-11-05 09:00:41 +01:00
|
|
|
|
{
|
2021-11-11 01:36:35 +01:00
|
|
|
|
//buttonTest();
|
2021-11-11 01:33:55 +01:00
|
|
|
|
//task1();
|
|
|
|
|
//task2();
|
2021-11-11 18:28:42 +01:00
|
|
|
|
//runStopLightTask1();
|
|
|
|
|
runStopLightTask2();
|
2021-11-11 01:33:55 +01:00
|
|
|
|
}
|
2021-10-28 16:36:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-11 01:33:55 +01:00
|
|
|
|
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();
|
2021-10-28 19:24:52 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Task 1 (2021-10-21) */
|
2021-10-28 16:36:38 +02:00
|
|
|
|
void
|
2021-11-11 01:33:55 +01:00
|
|
|
|
task1 (void)
|
|
|
|
|
{
|
|
|
|
|
_delay_ms(100);
|
2021-10-21 19:55:33 +02:00
|
|
|
|
|
2021-10-28 16:36:38 +02:00
|
|
|
|
/* Programmieren Sie ein Lauflicht. Nutzen Sie dazu die in <20>Led.h<> deklarierten
|
|
|
|
|
* Funktionen.
|
|
|
|
|
* 2.Schreiben Sie ein Programm mit folgenden Funktionen:
|
|
|
|
|
* Wenn Taste 1 gedr<EFBFBD>ckt wird, wird die Variable <EFBFBD>Counter<EFBFBD> inkrementiert.
|
|
|
|
|
* Wird Taste 2 gedr<EFBFBD>ckt wird, wird die Variable <EFBFBD>Counter<EFBFBD> dekrementiert.
|
|
|
|
|
* Variable <EFBFBD>Counter<EFBFBD> soll sich dabei zwischen 0 und 8 bewegen.
|
|
|
|
|
* Der Inhalt des Wertes soll mit Hilfe der LEDs angezeigt werden.
|
|
|
|
|
* 0 = keine LED an, 1 = LED1 an, 2 = LED1+LED2 an, usw.
|
|
|
|
|
* 8 = alle LEDs an.
|
|
|
|
|
*/
|
2021-10-21 19:55:33 +02:00
|
|
|
|
|
2021-10-28 19:24:52 +02:00
|
|
|
|
/* Check if counter needs to be incremented */
|
2021-10-28 16:36:38 +02:00
|
|
|
|
if (Taster1_get()) g_counter++;
|
2021-10-21 19:55:33 +02:00
|
|
|
|
|
2021-10-28 19:24:52 +02:00
|
|
|
|
/* Check if counter needs to be decremented */
|
2021-10-28 16:36:38 +02:00
|
|
|
|
if (Taster2_get()) g_counter--;
|
2021-10-21 19:55:33 +02:00
|
|
|
|
|
2021-10-28 19:24:52 +02:00
|
|
|
|
/* Keep counter within boundaries (0-8) */
|
2021-10-28 16:36:38 +02:00
|
|
|
|
g_counter = (g_counter + 9) % 9;
|
2021-10-21 19:55:33 +02:00
|
|
|
|
|
2021-10-28 19:24:52 +02:00
|
|
|
|
/* Set the LEDs according to the counter */
|
2021-10-28 16:36:38 +02:00
|
|
|
|
g_counter >= 1 ? Led1_On() : Led1_Off();
|
|
|
|
|
g_counter >= 2 ? Led2_On() : Led2_Off();
|
|
|
|
|
g_counter >= 3 ? Led3_On() : Led3_Off();
|
|
|
|
|
g_counter >= 4 ? Led4_On() : Led4_Off();
|
|
|
|
|
g_counter >= 5 ? Led5_On() : Led5_Off();
|
|
|
|
|
g_counter >= 6 ? Led6_On() : Led6_Off();
|
|
|
|
|
g_counter >= 7 ? Led7_On() : Led7_Off();
|
|
|
|
|
g_counter >= 8 ? Led8_On() : Led8_Off();
|
2021-11-11 01:33:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-11 18:28:42 +01:00
|
|
|
|
/* Task 2 (2021-10-28) */
|
2021-11-11 01:33:55 +01:00
|
|
|
|
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++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|