ex00 works

This commit is contained in:
hugogogo
2025-03-05 16:04:22 +01:00
parent b6b530b219
commit 9c64952a8f

View File

@@ -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
}
}
}
}