diff --git a/src/include/pins.h b/src/include/pins.h new file mode 100644 index 0000000..5194449 --- /dev/null +++ b/src/include/pins.h @@ -0,0 +1,5 @@ +#include + +void togglePin(volatile uint8_t *port, unsigned int pin); +void unsetPin(volatile uint8_t *port, unsigned int pin); +void setPin(volatile uint8_t *port, unsigned int pin); \ No newline at end of file diff --git a/src/pins.c b/src/pins.c new file mode 100644 index 0000000..69cae33 --- /dev/null +++ b/src/pins.c @@ -0,0 +1,28 @@ +#include + +#include "pins.h" + +void setPin(volatile uint8_t *port, unsigned int pin) +{ + *port |= (1 << pin); + printf("Port %d, Pin %d set\n\r", port, pin); +} + +void unsetPin(volatile uint8_t *port, unsigned int pin) +{ + *port &= ~(1 << pin); + printf("Port %d, Pin %d unset\n\r", port, pin); +} + +void togglePin(volatile uint8_t *port, unsigned int pin) +{ + *port ^= (1 << pin); + printf("Port %d, Pin %d toggled to ", port, pin); + + if ((*port & (1 << pin)) > 0) + printf("on"); + else + printf("off"); + + printf("\n\r"); +} \ No newline at end of file