Hello,my code in below.A program that simply lights a led 4 seconds after the program is running.interrupt frequency 1000 Hz:
But why doesn't it work?
My mcu: Attiny84A
#define F_CPU 8000000UL #include <avr/io.h> #include <avr/interrupt.h> #include <stdlib.h> #include <stdio.h> volatile unsigned int counter = 0; ISR(TIMER0_COMPA_vect){ //interrupt commands for TIMER 0 here counter++; } void timerprogram_init() { // TIMER 0 for interrupt frequency 1000 Hz: cli(); // stop interrupts TCCR0A = 0; // set entire TCCR0A register to 0 TCCR0B = 0; // same for TCCR0B TCNT0 = 0; // initialize counter value to 0 // set compare match register for 1000 Hz increments OCR0A = 124; // = 8000000 / (64 * 1000) - 1 (must be <256) // turn on CTC mode TCCR0B |= (1 << WGM01); // Set CS02, CS01 and CS00 bits for 64 prescaler TCCR0B |= (0 << CS02) | (1 << CS01) | (1 << CS00); // enable timer compare interrupt TIMSK0 |= (1 << OCIE0A); sei(); // allow interrupts } int main(void) { /* Replace with your application code */ timerprogram_init(); DDRA|=(1<<7); PORTA &=~ (1<<7); while (1) { if(counter>4000) PORTA |= (1<<7); } }