#include #include #include "../common/bump.h" /* #define BUMP_PINS 0b11101101 void BumpInit(void) { // 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 P4->IN & BUMP_PINS; } */ #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) { 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); } }