Skip to content

Instantly share code, notes, and snippets.

@eamanu
Created January 25, 2017 10:15
Show Gist options
  • Save eamanu/d37ed68b5ae4e4db1c262f715f26252d to your computer and use it in GitHub Desktop.
Save eamanu/d37ed68b5ae4e4db1c262f715f26252d to your computer and use it in GitHub Desktop.
/*
* main.c
*
* Created on: Jan 4, 2017
* Author: eamanu
*/
#include <avr/io.h>
#include <avr/interrupt.h>
/**
* To send data to USB
*/
#include "stduart.h" //lib to print/read data from USB
#include "uart.h" // lib to UART comm
volatile uint8_t count; //global variable
void configTimer ( void ); // config the Timer
int main ( void ){
/*init uart*/
uart_init();
/*configure timer*/
configTimer ( );
/*intizialize interrupt*/
sei ( );
prints ( "start counter ");
while( 1){ // infinite loop
}
return 0;
}
void configTimer ( void ){
// Prescaler = FCPU/1024
TCCR0B |=(1<<CS02)|(1<<CS00);
//Enable Overflow Interrupt Enable
TIMSK0|=(1<<TOIE0);
//Initialize Counter
TCNT0=0;
//Initialize Counter
count=0;
}
ISR(TIMER0_OVF_vect)
{
//This is the interrupt service routine for TIMER0 OVERFLOW Interrupt.
//CPU automatically call this when TIMER0 overflows.
//Increment our variable
count++;
printi ( count );
endl;
if(count==61)
{
//PORTC=~PORTC; //Invert the Value of PORTC
prints ("count == 61. Now count is 0 ");
endl;
count=0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment