void init_port();
void init_timer();
void setup() {
// Correctly call the initialization functions
init_port();
init_timer();
}
void init_port() {
// Set Pin D4 (bit 4 of Port D) as output
volatile char *portd_dir = (volatile char *)0x2A;
*portd_dir = 0x10; // Set bit 4 (Pin D4) as output
}
void init_timer() {
// Timer registers
volatile char *tccr1a = (volatile char *)0x80; // TCCR1A register
volatile char *tccr1b = (volatile char *)0x81; // TCCR1B register
volatile short *tcnt1 = (volatile short *)0x84; // TCNT1 (Timer1 counter)
volatile short *ocr1a = (volatile short *)0x88; // OCR1A (Output Compare Register A)
volatile char *timsk1 = (volatile char *)0x6F; // TIMSK1 (Timer Interrupt Mask)
// Configure Timer1
*tccr1a = 0x00; // Normal mode, no special output
*tccr1b = 0x0D; // Set CTC mode (Clear Timer on Compare Match) and 1024 prescaler
*tcnt1 = 0; // Initialize the counter to 0
*ocr1a = 15624; // Compare match value for Timer1 (higher for longer delay)
*timsk1 = 0x02; // Enable Timer1 compare match interrupt (OCIE1A)
}
// Interrupt Service Routine (ISR) for Timer1 Compare Match A
ISR(TIMER1_COMPA_vect) {
volatile char *portd_data = (volatile char *)0x2B;
*portd_data ^= 0x10; // Toggle Pin D4 (bit 4 of Port D)
}
void loop() {
// Empty loop, all actions handled in the ISR
}