Skip to content

Instantly share code, notes, and snippets.

@scottshuffler
Created February 16, 2016 20:11
Show Gist options
  • Save scottshuffler/bd09153f4b7f9938a8ce to your computer and use it in GitHub Desktop.
Save scottshuffler/bd09153f4b7f9938a8ce to your computer and use it in GitHub Desktop.
/*
* timer.c
*
* Created: 2/16/2016 2:55:03 PM
* Author : shuffleres
*/
#include <avr/io.h>
#include <avr/interrupt.h>
void init_timer_0();
volatile int counter = 500;
int main(void)
{
/* Replace with your application code */
DDRB = 0x80;
PORTB = 0x0;
init_timer_0();
while (1)
{
//
}
}
void init_timer_0() {
TCCR0A = 0X02;
OCR0A = 0XFA;
TIMSK0 = 0X02;
TCCR0B = 0x03;
sei();
}
ISR(TIMER0_COMPA_vect) {
counter--;
if (counter <= 0) {
counter = 500;
PORTB ^= 0X80;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment