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