/*
prescaller 8 , Xtal 16MHz
tick = 8/16Mhz= 0.5 us
delay=counter*tick
delay=counter*1/2us
untuk sampling rate 8 khz maka Tsampling= 1/8Khz= 125us
counter = 125/0.5us = 250
*/
#include <avr/io.h>
void TimerInit();
unsigned char periode;
int main(void) {
DDRB |= _BV(PB7);
TimerInit();
while (1) {
if(TIFR0 & (1<<OCF0A)){
PORTB ^= (1 << PB7);
TIFR0 |= (1 << OCF0A);
}
}
}
void TimerInit(void) {
TCCR0B = (1 << CS01) ; //prescaller 8
TCCR1B |= _BV(WGM13) | _BV(WGM12); //mode Timer CTC
ICR1 = 250;
}