#include <avr/io.h>
void TimerInit();
unsigned char periode;
/*
prescaller 8 , Xtal 16MHz
tick = 8/16Mhz= 0.5 us
delay=counter*tick
delay=counter*0.5us
counter=delayus/0.5us
untuk sampling rate 8 khz maka Tsampling= 1/8Khz= 125us
counter = 125/0.5us = 250
nilai TCNT0= -250 -> karena counter up
*/
int main(void) {
DDRB |= _BV(PB7);
TimerInit();
while (1) {
if (TIFR0&(1<<TOV0)) {
TCNT0= (unsigned char)-250;
//clear flag
TIFR0|=(1<<TOV0);
PORTB ^= (1 << PB7);
}
}
}
void TimerInit(void) {
TCNT0 = (unsigned char) -250; // reset counter
TCCR0B = (1 << CS01) ; //prescaller 8
}