// **************************************************************************
// * *
// * ATtiny85 1Hz-Blinker mit timer 0 * *
// * *
// **************************************************************************
#define F_CPU 8000000L
int systick = 0;
int n = 0;
ISR(TIMER0_COMPA_vect) // 1 ms Timer ISR
{
static uint16_t count=0;
if ( ++count > 999 ){
systick = 1;
count =0;
}
}
void init_timer()
{
PORTB = 0xff;
DDRB = 0xff;
TCCR0A = (1<<CS01); // Prescaler 8
OCR0A = (F_CPU/1024)-1; // 1 ms at 1 MHz cpu clock
TIMSK |= 1<<OCIE0A; // Timer/Counter0 Output Compare Match A Interrupt Enable
sei(); // globale Interruptfreigabe
}
void setup(){
init_timer();
}
void loop(){
if ( systick ){ // do something every 1 second
PORTB ^= 1;
systick = 0;
}
}