Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include
- void timer0_init()
- {
- //Toggle 0C0A on compare match
- TCCR0A |= (1 << COM0A0);
- //No prescaler, CTC mode
- TCCR0B |= (1 << WGM01)|(1 << CS00);
- //Initialize counter
- TCNT0 = 0;
- //Compare register value set to 199 for 40kHz
- OCR0A = 199;
- }
- int main(void)
- {
- //PD0 output
- DDRD = 0b00000001;
- timer0_init();
- while(1)
- {
- //switch PD0 high when compare match
- if (OCF0A == 1)
- {
- //PD0 HIgh
- PORTD = 0b00000001;
- }
- //Disable interupt when match occur
- TIFR0 = OCF0A;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement