Added separate Task file for introduction tasks, added basic UART functionality
parent
db16d89b80
commit
4f5b174bb1
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Tasks.c
|
||||||
|
*
|
||||||
|
* Created: 17/11/2021 16:58:20
|
||||||
|
* Author: n0x
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Led.h"
|
||||||
|
#include "Timer.h"
|
||||||
|
#include "Taster.h"
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
int g_counter = 0;
|
||||||
|
uint8_t g_ledStatus = 0;
|
||||||
|
uint16_t g_startMS;
|
||||||
|
|
||||||
|
void
|
||||||
|
initTasks (void){
|
||||||
|
g_startMS=Timer_getTick();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Task 1 (2021-10-21) */
|
||||||
|
void
|
||||||
|
runningLight (void)
|
||||||
|
{
|
||||||
|
_delay_ms(100);
|
||||||
|
|
||||||
|
/* Programmieren Sie ein Lauflicht. Nutzen Sie dazu die in „Led.h“ deklarierten
|
||||||
|
* Funktionen.
|
||||||
|
* 2.Schreiben Sie ein Programm mit folgenden Funktionen:
|
||||||
|
* Wenn Taste 1 gedrückt wird, wird die Variable „Counter“ inkrementiert.
|
||||||
|
* Wird Taste 2 gedrückt wird, wird die Variable „Counter“ dekrementiert.
|
||||||
|
* Variable „Counter“ 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Check if counter needs to be incremented */
|
||||||
|
if (Taster1_get()) g_counter++;
|
||||||
|
|
||||||
|
/* Check if counter needs to be decremented */
|
||||||
|
if (Taster2_get()) g_counter--;
|
||||||
|
|
||||||
|
/* Keep counter within boundaries (0-8) */
|
||||||
|
g_counter = (g_counter + 9) % 9;
|
||||||
|
|
||||||
|
/* Set the LEDs according to the counter */
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Task 2 (2021-10-28) */
|
||||||
|
void
|
||||||
|
blinkLedWithTimer (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++;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Tasks.h
|
||||||
|
*
|
||||||
|
* Created: 17/11/2021 16:58:04
|
||||||
|
* Author: n0x
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef TASKS_H_
|
||||||
|
#define TASKS_H_
|
||||||
|
|
||||||
|
void initTasks(void);
|
||||||
|
void blinkLedWithTimer(void);
|
||||||
|
void runningLight(void);
|
||||||
|
|
||||||
|
#endif /* TASKS_H_ */
|
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* UART.c
|
||||||
|
*
|
||||||
|
* Created: 18/11/2021 17:13:25
|
||||||
|
* Author: n0x
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "UART.h"
|
||||||
|
|
||||||
|
volatile int enabled = 1;
|
||||||
|
|
||||||
|
/* Schreiben Sie eine Funktion, welche die UART Schnittstelle für das Senden von
|
||||||
|
Daten mit
|
||||||
|
9600Baud,
|
||||||
|
8 Bit,
|
||||||
|
keine Parität und
|
||||||
|
1 Stopbit
|
||||||
|
initialisiert. */
|
||||||
|
void
|
||||||
|
uart_init(void)
|
||||||
|
{
|
||||||
|
/* set BAUD rate to 9600 */
|
||||||
|
UBRR0 = 103;
|
||||||
|
|
||||||
|
/* Async UART */
|
||||||
|
UCSR0C |= (0<<UMSEL00)|(0<<UMSEL01);
|
||||||
|
|
||||||
|
/* Disable Parity */
|
||||||
|
UCSR0C |= (0<<UPM00)|(0<<UPM01);
|
||||||
|
|
||||||
|
/* 8 Bit */
|
||||||
|
UCSR0C |= (1<<UCSZ00)|(1<<UCSZ01);
|
||||||
|
|
||||||
|
/* 1 Stopbit */
|
||||||
|
UCSR0C |= (0<<USBS0);
|
||||||
|
|
||||||
|
/* enable send */
|
||||||
|
UCSR0B = (1<<TXEN0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Schreiben Sie eine Funktion, welche einen String übergeben bekommt, und diesen
|
||||||
|
auf der UART Schnittstelle ausgibt. */
|
||||||
|
void
|
||||||
|
uart_send (char* string){
|
||||||
|
|
||||||
|
int len = strlen(string);
|
||||||
|
|
||||||
|
for(int i = 0; i < len; i++){
|
||||||
|
while (!( UCSR0A & (1<<UDRE0)) );
|
||||||
|
UDR0 = string[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Schreiben Sie eine Funktion, welche die UART Schnittstelle für das Senden von Daten mit
|
||||||
|
9600Baud,
|
||||||
|
8 Bit,
|
||||||
|
keine Parität und
|
||||||
|
1 Stoppbit
|
||||||
|
initialisiert. Nutzen Sie dabei ein Uart-Interrupt. */
|
||||||
|
void
|
||||||
|
uart_init_isr(void)
|
||||||
|
{
|
||||||
|
/* set BAUD rate to 9600 */
|
||||||
|
UBRR0 = 103;
|
||||||
|
|
||||||
|
/* Async UART */
|
||||||
|
UCSR0C |= (0<<UMSEL00)|(0<<UMSEL01);
|
||||||
|
|
||||||
|
/* Disable Parity */
|
||||||
|
UCSR0C |= (0<<UPM00)|(0<<UPM01);
|
||||||
|
|
||||||
|
/* 8 Bit */
|
||||||
|
UCSR0C |= (1<<UCSZ00)|(1<<UCSZ01);
|
||||||
|
|
||||||
|
/* 1 Stopbit */
|
||||||
|
UCSR0C |= (0<<USBS0);
|
||||||
|
|
||||||
|
/* enable send */
|
||||||
|
UCSR0B |= (1<<TXEN0);
|
||||||
|
|
||||||
|
/* enable interrupt */
|
||||||
|
UCSR0B |= (1<<UDRIE0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Schreiben Sie eine Funktion, welche einen String übergeben bekommt, und diesen
|
||||||
|
auf der UART Schnittstelle ausgibt. (Interrupts) */
|
||||||
|
void
|
||||||
|
uart_send_isr(char* string)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
while( i < strlen(string)){
|
||||||
|
if(enabled){
|
||||||
|
UDR0 = string[i];
|
||||||
|
i++;
|
||||||
|
enabled = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(USART0_UDRE_vect){
|
||||||
|
enabled = 1;
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* UART.h
|
||||||
|
*
|
||||||
|
* Created: 18/11/2021 17:13:16
|
||||||
|
* Author: n0x
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef UART_H_
|
||||||
|
#define UART_H_
|
||||||
|
|
||||||
|
void uart_init(void);
|
||||||
|
void uart_send(char* string);
|
||||||
|
|
||||||
|
|
||||||
|
void uart_init_isr(void);
|
||||||
|
void uart_send_isr(char* string);
|
||||||
|
|
||||||
|
int checkIfBlocked(void);
|
||||||
|
|
||||||
|
#endif /* UART_H_ */
|
Loading…
Reference in New Issue