From 0f01eda65f8c9c1dce4142045073c87679acfe8d Mon Sep 17 00:00:00 2001 From: hugogogo Date: Wed, 5 Mar 2025 17:22:18 +0100 Subject: [PATCH] added comments on mod01 ex00 --- module01/ex00/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/module01/ex00/main.c b/module01/ex00/main.c index 3809963..ed512c0 100644 --- a/module01/ex00/main.c +++ b/module01/ex00/main.c @@ -25,7 +25,7 @@ #define TURN_OFF_LED(bit) CLEAR(PORTB, bit) #define TOGGLE_LED(led) TOGGLE_PIN(B, led) - +// ELEMENTS #define D1 0 #define D2 1 #define D3 2 @@ -33,17 +33,18 @@ #define SW1 2 #define SW2 4 +// TIME #define PRESCALE_VALUE 1024 #if (PRESCALE_VALUE == 1) - #define PRESCALE_SET (1 << CS10) + #define PRESCALE_SET (1 << CS10) #elif (PRESCALE_VALUE == 8) - #define PRESCALE_SET (1 << CS11) + #define PRESCALE_SET (1 << CS11) #elif (PRESCALE_VALUE == 64) - #define PRESCALE_SET (1 << CS10) | (1 << CS11) + #define PRESCALE_SET (1 << CS10) | (1 << CS11) #elif (PRESCALE_VALUE == 256) - #define PRESCALE_SET (1 << CS12) + #define PRESCALE_SET (1 << CS12) #elif (PRESCALE_VALUE == 1024) - #define PRESCALE_SET (1 << CS10) | (1 << CS12) + #define PRESCALE_SET (1 << CS10) | (1 << CS12) #endif #define TIME_MS(ms) (((F_CPU / PRESCALE_VALUE) * ms) / 1000) @@ -51,12 +52,14 @@ int main() { MODE_OUTPUT(B, D2); TURN_OFF_LED(D2); - TCCR1B |= (PRESCALE_SET); // set timer with prescale + TCCR1B |= (PRESCALE_SET); // set timer with prescale + // -> set timer with bits CS10-12, in register TCCR1B : 16.4 Timer/Counter Clock Sources + // -> prescale values : 16.11.2 TCCR1B – Timer/Counter1 Control Register B, table 16-5. Clock Select Bit Description while(1) { if ( TCNT1 >= TIME_MS(500)) { TOGGLE_LED(D2); - TCNT1 = 0; // reset timer value + TCNT1 = 0; // reset timer value } } }