From 05973dcd2b92d59d097c7578530929a7571e645a Mon Sep 17 00:00:00 2001 From: Hladu357 Date: Sun, 2 Mar 2025 12:50:23 +0200 Subject: [PATCH] lab2 --- common/bump.c | 11 +++++++++-- lab2/main.c | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/common/bump.c b/common/bump.c index dc93bed..000a613 100644 --- a/common/bump.c +++ b/common/bump.c @@ -2,11 +2,18 @@ #include "inc/msp432p401r.h" +#define BUMP_PINS 0b11101101 + void BumpInit(void) { - // write this as part of Lab 2 + // Port 4 pins 0, 2, 3, 5, 6, 7 + // and enables internal resistors + P4->SEL0 &= ~BUMP_PINS; + P4->SEL1 &= ~BUMP_PINS; // 1) configure P4.0 P4.2 P4.3 P4.5 P4.6 P4.7 as gpio + P4->DIR &= ~BUMP_PINS; // 2) configure as input + P4->REN |= BUMP_PINS; // 3) enable pull resisors } uint8_t BumpRead(void) { // write this as part of Lab 2 - return 0; // replace this line + return P4->IN & BUMP_PINS; } \ No newline at end of file diff --git a/lab2/main.c b/lab2/main.c index 1f7c37c..273d0c2 100644 --- a/lab2/main.c +++ b/lab2/main.c @@ -5,17 +5,26 @@ #include "../common/delay.h" #include "../common/clock.h" +#define DUMP_SIZE 256 + +uint8_t bump_status; +uint8_t bump_dump[DUMP_SIZE]; + void DebugDump(uint8_t bump) { - // write this as part of Lab 2 + static idx = 0; + idx = (idx + 1) % DUMP_SIZE; + bump_dump[idx] = bump; } int main(void) { - // write this as part of Lab 2 ClockInit48MHz(); + BumpInit(); while (true) { - // write this as part of Lab 2 // 10ms delay + Delay1ms(10); + bump_status = BumpRead(); // debug dump + DebugDump(bump_status); } }