From 9c64952a8f8b9a80484d6f68fd121becfe4d257b Mon Sep 17 00:00:00 2001 From: hugogogo Date: Wed, 5 Mar 2025 16:04:22 +0100 Subject: [PATCH] ex00 works --- module01/ex00/main.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/module01/ex00/main.c b/module01/ex00/main.c index 6336ca3..8fa7bad 100644 --- a/module01/ex00/main.c +++ b/module01/ex00/main.c @@ -5,17 +5,21 @@ // #define FIRST_LETTER(x) FIRST_LETTER_IMPL(x) // #define PORT_LETTER(PIN) FIRST_LETTER(PIN) +// global registers #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 +// actions on ports #define TEST_PIN(port, bit) TEST(PIN ## port, bit) -#define TOGGLE_PIN(port, bit) TEST(PIN ## port, bit) +#define TOGGLE_PIN(port, bit) SET(PIN ## port, bit) #define MODE_INPUT(port, bit) CLEAR(DDR ## port, bit) #define MODE_OUTPUT(port, bit) SET(DDR ## port, bit) #define IS_PIN_SET(port, bit) (TEST_PIN(port, bit)) == 0 #define IS_PIN_CLEAR(port, bit) (TEST_PIN(port, bit)) == 1 +#define TURN_ON(_PORT, BIT) SET(PORT ## _PORT, BIT) +#define TURN_OFF(_PORT, BIT) CLEAR(PORT ## _PORT, BIT) // LEDs #define TURN_ON_LED(bit) SET(PORTB, bit) @@ -30,28 +34,24 @@ #define SW1 2 #define SW2 4 -#define PRESCALE_VALUE 64 -#define TIME(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000) - -#define LED1 B0 +#define PRESCALE_VALUE 1024 +#define TIME(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000) int main() { MODE_OUTPUT(B, D2); TURN_OFF_LED(D2); - // TCCR1B |= (PRESCALE); // set timer with prescale - // TCCR1B |= ((1 << CS10 ) | (1 << CS11 ) ); // set timer with prescale - + TCCR1B |= ((1 << CS10 ) | (1 << CS12 ) ); // set timer with prescale while(1) { - // if ( TCNT1 >= TIME(500)) { - - // TOGGLE_LED(D2); - TOGGLE_PIN(B, D2); - _delay_ms(500); - - - // TCNT1 = 0; // reset timer value - // } + if ( TCNT1 >= TIME(500)) { + TOGGLE_LED(D2); + TCNT1 = 0; // reset timer value + } } -} \ No newline at end of file +} + + + + +