From cb52da4776685422ca5a5d1547cfd03add08be44 Mon Sep 17 00:00:00 2001 From: Hladu357 Date: Tue, 4 Mar 2025 17:04:28 +0200 Subject: [PATCH] tmp --- lab2/main.c | 43 ++++++++++++++++++++++++++++++++++++++++++- lab3/main.c | 30 +++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 8 deletions(-) diff --git a/lab2/main.c b/lab2/main.c index 273d0c2..a2e3e99 100644 --- a/lab2/main.c +++ b/lab2/main.c @@ -11,19 +11,60 @@ uint8_t bump_status; uint8_t bump_dump[DUMP_SIZE]; void DebugDump(uint8_t bump) { - static idx = 0; + static int idx = 0; idx = (idx + 1) % DUMP_SIZE; bump_dump[idx] = bump; } +#include "inc/msp432p401r.h" + +#define SW1 0x02 // on the left side of the LaunchPad board +#define SW2 0x10 // on the right side of the LaunchPad board +#define RED 0x01 +#define GREEN 0x02 +#define BLUE 0x04 +#define BUMP_PINS 0b11101101 + + +void initColorLED(void) { + P2->SEL0 &= ~0x07; + P2->SEL1 &= ~0x07; // 1) configure P2.2-P2.0 as GPIO + P2->DIR |= 0x07; // 2) make P2.2-P2.0 out + P2->DS |= 0x07; // 3) activate increased drive strength + P2->OUT &= ~0x07; // 4) all LEDs off +} + +void initInput(void) { + P1->SEL0 &= ~(SW1 | SW2); + P1->SEL1 &= ~(SW1 | SW2); // 1) configure P1.4 P1.1 P1.0 as GPIO + P1->DIR &= ~(SW1 | SW2); // 2) SW1 and SW2 input + P1->REN |= (SW1 | SW2); // 4) enable pull resistors on P1.4 and P1.1 +} + +void Port2Init(void) { + P2->SEL0 = 0x00; + P2->SEL1 = 0x00; // configure P2.2-P2.0 as GPIO + P2->DS = 0x07; // make P2.2-P2.0 high drive strength + P2->DIR = 0x07; // make P2.2-P2.0 out + P2->OUT = 0x00; // all LEDs off +} + int main(void) { ClockInit48MHz(); BumpInit(); + Port2Init(); + while (true) { // 10ms delay Delay1ms(10); bump_status = BumpRead(); + P2->OUT = 0; + + if (bump_status & 0x01) P2->OUT |= RED; + if (bump_status & 0x04) P2->OUT |= GREEN; + if (bump_status & 0x08) P2->OUT |= BLUE; + // debug dump DebugDump(bump_status); } diff --git a/lab3/main.c b/lab3/main.c index 14a1d18..fc4d649 100644 --- a/lab3/main.c +++ b/lab3/main.c @@ -9,8 +9,17 @@ #include "inc/msp432p401r.h" -void DebugDump(uint8_t bump, uint8_t line) { - // write this as part of Lab 10 +#define REDLED (*((volatile uint8_t *)(0x42098040))) + +#define DUMP_SIZE 256 + +uint8_t bump_status; +uint8_t bump_dump[DUMP_SIZE]; + +void DebugDump(uint8_t bump) { + static int idx = 0; + idx = (idx + 1) % DUMP_SIZE; + bump_dump[idx] = bump; } // **************SysTick_Init********************* @@ -30,15 +39,22 @@ void SysTickInit(uint32_t period, uint32_t priority) { } void SysTick_Handler(void) { // every 1ms - // write this as part of Lab 10 + // REDLED = 1; + // uint8_t bump = BumpRead(); + // REDLED = 0; + volatile int i = 0; + ++i; } int main(void) { - // write this as part of Lab 3 ClockInit48MHz(); BumpInit(); ReflectanceInit(); - SysTickInit(?, 1); // 1ms SysTickInit - CPU_cpsie(); // Enable interrupts - while (true) {} + SysTickInit(480000, 1); // 1ms SysTickInit + CPU_cpsie(); // Enable interrupts + + while (true) { + REDLED = 1; + REDLED = 0; + } }