From d48aedf507998f108e2c4deb52af4653e0807606 Mon Sep 17 00:00:00 2001 From: _N0x Date: Thu, 21 Oct 2021 19:55:33 +0200 Subject: [PATCH] inital commit with excersise from 2021-10-21 --- .gitignore | 151 ++++++++++++++++++ EmbeddedSystemsTHM.atsln | 22 +++ .../EmbeddedSystemsTHM.componentinfo.xml | 86 ++++++++++ EmbeddedSystemsTHM/EmbeddedSystemsTHM.cproj | 143 +++++++++++++++++ EmbeddedSystemsTHM/Led.c | 62 +++++++ EmbeddedSystemsTHM/Led.h | 37 +++++ EmbeddedSystemsTHM/Taster.c | 22 +++ EmbeddedSystemsTHM/Taster.h | 21 +++ EmbeddedSystemsTHM/main.c | 58 +++++++ 9 files changed, 602 insertions(+) create mode 100644 .gitignore create mode 100644 EmbeddedSystemsTHM.atsln create mode 100644 EmbeddedSystemsTHM/EmbeddedSystemsTHM.componentinfo.xml create mode 100644 EmbeddedSystemsTHM/EmbeddedSystemsTHM.cproj create mode 100644 EmbeddedSystemsTHM/Led.c create mode 100644 EmbeddedSystemsTHM/Led.h create mode 100644 EmbeddedSystemsTHM/Taster.c create mode 100644 EmbeddedSystemsTHM/Taster.h create mode 100644 EmbeddedSystemsTHM/main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..385038b --- /dev/null +++ b/.gitignore @@ -0,0 +1,151 @@ +## Ignore Atmel/Visual Studio temporary files, build results, and + +## files generated by popular Visual Studio add-ons. + + + +# User-specific files + +*.suo + +*.user + +*.userosscache + +*.sln.docstates + + + +# Build results + +[Dd]ebug/ + +[Dd]ebugPublic/ + +[Rr]elease/ + +[Rr]eleases/ + +[Xx]64/ + +[Xx]86/ + +[Bb]uild/ + +bld/ + +[Bb]in/ + +[Oo]bj/ + + + +# Atmel/Visual Studio cache/options directory + +.vs/ + + + +*_i.c + +*_p.c + +*_i.h + +*.ilk + +*.meta + +*.obj + +*.pch + +*.pdb + +*.pgc + +*.pgd + +*.rsp + +*.sbr + +*.tlb + +*.tli + +*.tlh + +*.tmp + +*.tmp_proj + +*.log + +*.vspscc + +*.vssscc + +.builds + +*.pidb + +*.svclog + +*.scc + + + +# Visual C++ cache files + +ipch/ + +*.aps + +*.ncb + +*.opendb + +*.opensdf + +*.sdf + +*.cachefile + +*.VC.db + + + +# Visual Studio profiler + +*.psess + +*.vsp + +*.vspx + +*.sap + + + +# Visual Studio cache files + +# files ending in .cache can be ignored + +*.[Cc]ache + +# but keep track of directories ending in .cache + +!*.[Cc]ache/ + + + +# Visual Studio 6 build log + +*.plg + + + +# Visual Studio 6 workspace options file + +*.opt \ No newline at end of file diff --git a/EmbeddedSystemsTHM.atsln b/EmbeddedSystemsTHM.atsln new file mode 100644 index 0000000..03a168e --- /dev/null +++ b/EmbeddedSystemsTHM.atsln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Atmel Studio Solution File, Format Version 11.00 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "EmbeddedSystemsTHM", "EmbeddedSystemsTHM\EmbeddedSystemsTHM.cproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR + {DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/EmbeddedSystemsTHM/EmbeddedSystemsTHM.componentinfo.xml b/EmbeddedSystemsTHM/EmbeddedSystemsTHM.componentinfo.xml new file mode 100644 index 0000000..1b89aef --- /dev/null +++ b/EmbeddedSystemsTHM/EmbeddedSystemsTHM.componentinfo.xml @@ -0,0 +1,86 @@ + + + + + + + Device + Startup + + + Atmel + 1.6.0 + C:/Program Files (x86)\Atmel\Studio\7.0\Packs + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include\ + + include + C + + + include/ + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\include\avr\iom1284p.h + + header + C + sBNrZHKciubwnkFlY7UYbg== + + include/avr/iom1284p.h + + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\templates\main.c + template + source + C Exe + Ftfh3cO7UGdUPIQC2OseWw== + + templates/main.c + Main file (.c) + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\templates\main.cpp + template + source + C Exe + mkKaE95TOoATsuBGv6jmxg== + + templates/main.cpp + Main file (.cpp) + + + + C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega1284p + + libraryPrefix + GCC + + + gcc/dev/atmega1284p + + + + + ATmega_DFP + C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.6.364/Atmel.ATmega_DFP.pdsc + 1.6.364 + true + ATmega1284P + + + + Resolved + Fixed + true + + + \ No newline at end of file diff --git a/EmbeddedSystemsTHM/EmbeddedSystemsTHM.cproj b/EmbeddedSystemsTHM/EmbeddedSystemsTHM.cproj new file mode 100644 index 0000000..315c59b --- /dev/null +++ b/EmbeddedSystemsTHM/EmbeddedSystemsTHM.cproj @@ -0,0 +1,143 @@ + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.C + dce6c7e3-ee26-4d79-826b-08594b9ad897 + ATmega1284P + none + Executable + C + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + EmbeddedSystemsTHM + EmbeddedSystemsTHM + EmbeddedSystemsTHM + Native + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 0 + 0 + + com.atmel.avrdbg.tool.simulator + + 0x1E9705 + + + + + + com.atmel.avrdbg.tool.simulator + + + Simulator + + + + + + -mmcu=atmega1284p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega1284p" + True + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\ + + + Optimize for size (-Os) + True + True + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\ + + + + + + + + + -mmcu=atmega1284p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\gcc\dev\atmega1284p" + True + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\ + + + Optimize debugging experience (-Og) + True + True + Default (-g2) + True + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.6.364\include\ + + + Default (-Wa,-g) + + + + + + compile + + + compile + + + compile + + + compile + + + compile + + + + \ No newline at end of file diff --git a/EmbeddedSystemsTHM/Led.c b/EmbeddedSystemsTHM/Led.c new file mode 100644 index 0000000..30004b9 --- /dev/null +++ b/EmbeddedSystemsTHM/Led.c @@ -0,0 +1,62 @@ +#include + +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 +} + +void Led1_On(void){ + 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 +} + +void Led2_On(void){ + PORTB |= (1<<6); +} +void Led2_Off(void){ + PORTB &= ~(1<<6); +} + +void Led3_On(void){ + PORTB |= (1<<5); +} +void Led3_Off(void){ + PORTB &= ~(1<<5); +} + +void Led4_On(void){ + PORTB |= (1<<4); +} +void Led4_Off(void){ + PORTB &= ~(1<<4); +} + +void Led5_On(void){ + PORTB |= (1<<3); +} +void Led5_Off(void){ + PORTB &= ~(1<<3); +} + +void Led6_On(void){ + PORTB |= (1<<2); +} +void Led6_Off(void){ + PORTB &= ~(1<<2); +} + +void Led7_On(void){ + PORTB |= (1<<1); +} +void Led7_Off(void){ + PORTB &= ~(1<<1); +} + +void Led8_On(void){ + PORTB |= (1<<0); +} +void Led8_Off(void){ + PORTB &= ~(1<<0); +} \ No newline at end of file diff --git a/EmbeddedSystemsTHM/Led.h b/EmbeddedSystemsTHM/Led.h new file mode 100644 index 0000000..072924e --- /dev/null +++ b/EmbeddedSystemsTHM/Led.h @@ -0,0 +1,37 @@ +#ifndef LED_H_ +#define LED_H_ +#include + +/* +Initialisiert die Hardware für die Led +*/ +void Led_init(void); + +/* +Funktionen schalten entsprechende LEDs ein oder aus. +*/ +void Led1_On(void); +void Led1_Off(void); + +void Led2_On(void); +void Led2_Off(void); + +void Led3_On(void); +void Led3_Off(void); + +void Led4_On(void); +void Led4_Off(void); + +void Led5_On(void); +void Led5_Off(void); + +void Led6_On(void); +void Led6_Off(void); + +void Led7_On(void); +void Led7_Off(void); + +void Led8_On(void); +void Led8_Off(void); + +#endif /* LED_H_ */ \ No newline at end of file diff --git a/EmbeddedSystemsTHM/Taster.c b/EmbeddedSystemsTHM/Taster.c new file mode 100644 index 0000000..3216454 --- /dev/null +++ b/EmbeddedSystemsTHM/Taster.c @@ -0,0 +1,22 @@ +#include + +void Taster_init(void){ + DDRD &= ~(7<<5); // Set bit 5-7 of Data Direction Register D as input + DDRC &= ~(1<<2); // Set bit 2 of Data Direction Register B as input + + PORTD &= ~(7<<5); // Initialize bit 5-7 of PORTD as low + PORTC &= ~(1<<2); // Initialize bit 2 of PORTC as low +} + +uint8_t Taster1_get(void){ + return PORTD&(1<<7); +} +uint8_t Taster2_get(void){ + return PORTD&(1<<6); +} +uint8_t Taster3_get(void){ + return PORTD&(1<<5); +} +uint8_t Taster4_get(void){ + return PORTC&(1<<2); +} \ No newline at end of file diff --git a/EmbeddedSystemsTHM/Taster.h b/EmbeddedSystemsTHM/Taster.h new file mode 100644 index 0000000..208a5bb --- /dev/null +++ b/EmbeddedSystemsTHM/Taster.h @@ -0,0 +1,21 @@ +#ifndef TASTER_H_ +#define TASTER_H_ + +#include + +/* +Initialisiert die Hardware für die Taster +*/ +void Taster_init(void); + +/* +Gibt den aktuellen Status der Tasten aus. +Rückgabewert 0 = Taster nicht gedr�ckt, 1 = Taster gedr�ckt. +*/ +uint8_t Taster1_get(void); +uint8_t Taster2_get(void); +uint8_t Taster3_get(void); +uint8_t Taster4_get(void); + + +#endif /* TASTER_H_ */ \ No newline at end of file diff --git a/EmbeddedSystemsTHM/main.c b/EmbeddedSystemsTHM/main.c new file mode 100644 index 0000000..753abe2 --- /dev/null +++ b/EmbeddedSystemsTHM/main.c @@ -0,0 +1,58 @@ +/* + * EmbeddedSystemProject.c + * + * Created: 21/10/2021 16:55:21 + * Author : n0x + */ + +#include "Led.h" +#include "Taster.h" +#include +#ifdef F_CPU +#define F_CPU 1000000 +#endif + +int main(void) +{ + // Initialize the LEDs and Buttons + Led_init(); + Taster_init(); + + + int counter = 0; + + while (1) + { + _delay_ms(50); + + /* 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()) counter++; + + // Check if counter needs to be decremented + if (Taster2_get()) counter--; + + // Keep counter within boundaries (0-8) + counter = (counter + 9) % 9; + + // Set the LEDs according to the counter + counter >= 1 ? Led1_On() : Led1_Off(); + counter >= 2 ? Led2_On() : Led2_Off(); + counter >= 3 ? Led3_On() : Led3_Off(); + counter >= 4 ? Led4_On() : Led4_Off(); + counter >= 5 ? Led5_On() : Led5_Off(); + counter >= 6 ? Led6_On() : Led6_Off(); + counter >= 7 ? Led7_On() : Led7_Off(); + counter >= 8 ? Led8_On() : Led8_Off(); + } +}