Skip to content

Instantly share code, notes, and snippets.

@monpetit
Created June 7, 2016 09:24
Show Gist options
  • Select an option

  • Save monpetit/86407bc622343e22ab7e4909aa51e22a to your computer and use it in GitHub Desktop.

Select an option

Save monpetit/86407bc622343e22ab7e4909aa51e22a to your computer and use it in GitHub Desktop.
void setup_timer1(void)
{
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 62.500 kHz
// Mode: CTC top=OCR1A
// OC1A output: Disconnected
// OC1B output: Disconnected
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer Period: 1 s
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: On
// Compare B Match Interrupt: Off
TCCR1A = (0 << COM1A1) | (0 << COM1A0) | (0 << COM1B1) | (0 << COM1B0) | (0 << WGM11) | (0 << WGM10);
TCCR1B = (0 << ICNC1) | (0 << ICES1) | (0 << WGM13) | (1 << WGM12) | (1 << CS12) | (0 << CS11) | (0 << CS10);
TCNT1H = 0x00;
TCNT1L = 0x00;
ICR1H = 0x00;
ICR1L = 0x00;
OCR1AH = 0xF4;
OCR1AL = 0x23;
OCR1BH = 0x00;
OCR1BL = 0x00;
// Timer/Counter 1 Interrupt(s) initialization
TIMSK1 = (0 << ICIE1) | (0 << OCIE1B) | (1 << OCIE1A) | (0 << TOIE1);
// Global enable interrupts
sei();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment