diff --git a/module00/ex01/Makefile b/module00/ex01/Makefile index 40e9cb4..56b54a5 100644 --- a/module00/ex01/Makefile +++ b/module00/ex01/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/ex01/main.c b/module00/ex01/main.c index fe04856..9fea211 100644 --- a/module00/ex01/main.c +++ b/module00/ex01/main.c @@ -1,4 +1,5 @@ #include +// #include #define SET(REGISTER, BIT) REGISTER |= 1 << BIT #define CLEAR(REGISTER, BIT) REGISTER &= ~(1 << BIT) @@ -12,19 +13,22 @@ int main() { - // DDRx : select direction of the pin + // registers : + // DDRx : (Data Direction Register) Controls whether each pin is an input or output // - 1 = output (pull-up off) // - 0 = input - // PORTx : - // if DDRx = 1 (output mode) : - // - 1 = HIGH (5V) - // - 0 = LOW (0V) - // if DDRx = 0 (input mode) : + // PORTx : (Port Data Register) + // if DDRx = 1 (output mode) : Controls the output state of a pin when it's configured as an output + // - 1 = HIGH (5V?) (VCC) + // - 0 = LOW (0V) (GND) + // if DDRx = 0 (input mode) : Controls the internal pull-up resistor when the pin is an input // - 1 = pull-up on - // - 0 = pull-up off - // PINx : - + // - 0 = pull-up off (pin floats) + // PINx : (Pin Input Register) Reads the current logical state of a pin + // Reflects the actual voltage on the pin + // Special feature: Writing 1 to PINxn toggles the corresponding PORTxn bit (regardless of DDRx) + // turns on led 1 SET(DDRB, D1); // make PB0 as OUTPUT (pullup is off) CLEAR(PORTB, D1); // make PB0 as HIGH (LED turns ON) @@ -37,5 +41,45 @@ int main() // CLEAR(DDRB, D4); // make PB4 as INPUT // CLEAR(PORTB, D4); // make PB4 pullup off + //////////////////////////////// + // TEST weird behavior of PIN register : + // in initial tests, using PIN register to toggle ON two leds only worked for the second one + // after some tests, this behavior is not anymore + // + // test 1 : only led 3 turns on + // SET(DDRB, D1); + // CLEAR(PORTB, D1); + // SET(PINB, D1); + // SET(DDRB, D3); + // CLEAR(PORTB, D3); + // SET(PINB, D3); + // + // test 2 : only led 3 turns on + // SET(DDRB, D1); + // CLEAR(PORTB, D1); + // SET(DDRB, D3); + // CLEAR(PORTB, D3); + // SET(PINB, D1); + // SET(PINB, D3); + // + // test 3 : both leds turns on + // SET(DDRB, D1); + // CLEAR(PORTB, D1); + // SET(DDRB, D3); + // CLEAR(PORTB, D3); + // PINB = (1 << D1) | (1 << D3); + // + // test 4 : both leds turns on + // SET(DDRB, D1); + // CLEAR(PORTB, D1); + // SET(DDRB, D3); + // CLEAR(PORTB, D3); + // SET(PINB, D1); + // _delay_us(500); + // SET(PINB, D3); + // + //////////////////////////////// + + return 0; } \ No newline at end of file