From 1a86e789841b2afd3f6dd4340399d91e7832cc7f Mon Sep 17 00:00:00 2001 From: hugogogo Date: Tue, 4 Mar 2025 13:26:57 +0100 Subject: [PATCH] added macro modes input and output --- module00/ex02/Makefile | 2 +- module00/ex02/main.c | 30 ++++++------------------------ 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/module00/ex02/Makefile b/module00/ex02/Makefile index 40e9cb4..56b54a5 100644 --- a/module00/ex02/Makefile +++ b/module00/ex02/Makefile @@ -19,7 +19,7 @@ hex: $(TARGET).hex # https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html $(TARGET).bin: $(TARGET).c - $(CC) -mmcu=$(AVRGCC_MCU_TYPE) -D F_CPU=$(F_CPU) $(TARGET).c -o $(TARGET).bin + $(CC) -mmcu=$(AVRGCC_MCU_TYPE) -D F_CPU=$(F_CPU) $(TARGET).c -Os -o $(TARGET).bin # https://linux.die.net/man/1/avr-objcopy diff --git a/module00/ex02/main.c b/module00/ex02/main.c index fe04856..a036784 100644 --- a/module00/ex02/main.c +++ b/module00/ex02/main.c @@ -1,10 +1,14 @@ #include +#include #define SET(REGISTER, BIT) REGISTER |= 1 << BIT #define CLEAR(REGISTER, BIT) REGISTER &= ~(1 << BIT) #define TEST(REGISTER, BIT) REGISTER & 1 << BIT #define TOGGLE(REGISTER, BIT) REGISTER ^= 1 << BIT +#define MODE_INPUT(BIT) CLEAR(DDRB, BIT) +#define MODE_OUTPUT(BIT) SET(DDRB, BIT) + #define D1 0 #define D2 1 #define D3 2 @@ -12,30 +16,8 @@ int main() { - // DDRx : select direction of the pin - // - 1 = output (pull-up off) - // - 0 = input - // PORTx : - // if DDRx = 1 (output mode) : - // - 1 = HIGH (5V) - // - 0 = LOW (0V) - // if DDRx = 0 (input mode) : - // - 1 = pull-up on - // - 0 = pull-up off - // PINx : - - - SET(DDRB, D1); // make PB0 as OUTPUT (pullup is off) - CLEAR(PORTB, D1); // make PB0 as HIGH (LED turns ON) - - // SET(DDRB, D2); // make PB1 as OUTPUT (pullup is off) - // CLEAR(PORTB, D2); // make PB1 as LOW (LED turns OFF) - - // CLEAR(DDRB, D3); // make PB2 as INPUT - // SET(PORTB, D3); // make PB2 pullup on - - // CLEAR(DDRB, D4); // make PB4 as INPUT - // CLEAR(PORTB, D4); // make PB4 pullup off + MODE_OUTPUT(D1); + SET(PORTB, D1); return 0; } \ No newline at end of file