summaryrefslogtreecommitdiffstats
path: root/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung
diff options
context:
space:
mode:
Diffstat (limited to 'Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung')
-rw-r--r--Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe1.c21
-rw-r--r--Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe2.c22
-rw-r--r--Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe3.c31
-rw-r--r--Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/defines.h16
4 files changed, 90 insertions, 0 deletions
diff --git a/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe1.c b/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe1.c
new file mode 100644
index 0000000..355bb20
--- /dev/null
+++ b/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe1.c
@@ -0,0 +1,21 @@
+#include "defines.h"
+
+int main(void)
+{
+ *PMC_PCER = 0x4000; // Power Enable für Parallel I/O Controller B
+ *PIOB_PER = 0x100; // Pin 8: Enabled (Initialisiert) (Lämpchen)
+ *PIOB_OER = 0x100; // Pin 8: Pin als Ausgabe verwenden
+ // Lämpchen ist initialisiert und auf Output gesetzt.
+
+ int i;
+
+ while (1)
+ {
+ *PIOB_SODR = 0x100; // Pin 8: Lampe an
+ for (i=0; i<125000; i++); // Pause
+ *PIOB_CODR = 0x100; // Pin 8: Lampe aus
+ for (i=0; i<125000; i++); // Pause
+ }
+ return 0;
+}
+
diff --git a/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe2.c b/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe2.c
new file mode 100644
index 0000000..000f51a
--- /dev/null
+++ b/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe2.c
@@ -0,0 +1,22 @@
+#include "defines.h"
+
+int main(void)
+{
+ *PMC_PCER = 0x4000; // Power Enable für Parallel I/O Controller B
+ *PIOB_PER = 0x118; // Pin 8: Enabled (Initialisiert) (Lämpchen)
+ // *PIOB_PER = 0x100; *PIOB_PER = 0x8; *PIOB_PER = 0x10
+ *PIOB_OER = 0x100; // Pin 8: Pin als Ausgabe verwenden
+
+ // Schalter werden nicht auf Input geschaltete, da dies Default Zustand ist
+ // Lämpchen ist initialisiert und auf Output gesetzt.
+
+ while (1)
+ {
+ if (!(*PIOB_PDSR & 0X8))
+ *PIOB_SODR = 0x100; // Pin 8: Lampe an
+ if (!(*PIOB_PDSR & 0x10))
+ *PIOB_CODR = 0x100; // Pin 8: Lampe aus
+ }
+ return 0;
+}
+
diff --git a/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe3.c b/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe3.c
new file mode 100644
index 0000000..21ed738
--- /dev/null
+++ b/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/Termin2Aufgabe3.c
@@ -0,0 +1,31 @@
+#include "defines.h"
+
+int main(void)
+{
+ *PMC_PCER = 0x4000; // Power Enable für Parallel I/O Controller B
+ *PIOB_PER = 0x318; // Pin 8,9,3,4: Enabled (Initialisiert) (Lämpchen1,2,Schalter1,2)
+ // *PIOB_PER = 0x100; *PIOB_PER = 0x200; *PIOB_PER = 0x8; *PIOB_PER = 0x10
+ *PIOB_OER = 0x300; // Pin 8,9: Pin als Ausgabe verwenden (Lampe 1,2)
+
+ // Schalter werden nicht auf Input geschaltete, da dies Default Zustand ist
+ // Lämpchen ist initialisiert und auf Output gesetzt.
+
+ int i;
+
+ while (1)
+ {
+ *PIOB_SODR = 0x100; // Pin 8: Lampe 1 an
+ for (i=0; i<125000; i++); // Pause
+ *PIOB_CODR = 0x100; // Pin 8: Lampe 1 aus
+ for (i=0; i<125000; i++); // Pause
+
+ // PDSR wird erst geprüft nachdem Lampe 1 aus ist
+
+ if (!(*PIOB_PDSR & 0X8))
+ *PIOB_SODR = 0x200; // Pin 8: Lampe 2 an
+ if (!(*PIOB_PDSR & 0x10))
+ *PIOB_CODR = 0x200; // Pin 8: Lampe 2 aus
+ }
+ return 0;
+}
+
diff --git a/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/defines.h b/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/defines.h
new file mode 100644
index 0000000..b325848
--- /dev/null
+++ b/Bachelor/Mikroprozessorsysteme2/mi2/Termin2/Loesung/defines.h
@@ -0,0 +1,16 @@
+// Power Management Controller (Atmel Docu S. 139)
+#define PMC_PCER ((volatile unsigned int*) 0xFFFF4010) // Peripheral Clock Enable Register
+#define PCER_PIOA 0x2000 // PIOA: PIOA Clock. Enable
+#define PCER_PIOB 0x4000 // PIOB: PIOB Clock. Enable
+#define PMC_PCDR ((volatile unsigned int*) 0xFFFF4014) // Peripheral Clock Disable Register
+
+
+/*****************************************************************************/
+// Parallel I/O Controller B (Atmel Docu S. 59)
+#define PIOB_PER ((volatile unsigned int*) 0xFFFF0000) // Enable Register (Atmel Docu S. 60)
+#define PIOB_PDR ((volatile unsigned int*) 0xFFFF0004) // Disable Register (Atmel Docu S. 60)
+#define PIOB_SODR ((volatile unsigned int*) 0xFFFF0030) // Set Output Data Register (Atmel Docu S. 66)
+#define PIOB_CODR ((volatile unsigned int*) 0xFFFF0034) // Clear Output Data Register (Atmel Docu S. 66)
+#define PIOB_OER ((volatile unsigned int*) 0xFFFF0010) // Output Enable Register (Atmel Docu S. 62)
+#define PIOB_ODR ((volatile unsigned int*) 0xFFFF0014) // Output Disable Register (Atmel Docu S.62)
+#define PIOB_PDSR ((volatile unsigned int*) 0xFFFF003C) // Pin Data Status Register (Atmel Docu S.67)