/*
Filename: Normal_Mode_0 - EX1
Author:
Date:
Description: PURPOSE – get PORTA pin 7 to toggle every 10ms
NORMAL MODE Timer used is timer/counter0.
Mode of operation used for counter: Mode 0 (Normal);
No prescaler used
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
//#define TOGGLECYCLES 31250
#define TOGGLECYCLES 10
volatile unsigned int overflowCounter = 0;
int main(void)
{
Serial.begin(9600);
cli(); // Disable All Interrupts
DDRA = 0x80; // Port B output
PORTA = 0x00;
TCCR0A = 0x00; // Mode 0
TCCR0B = 0x03; // 64 prescale.
TIMSK0 = TIMSK0 | (1 << TOIE0); // Enables overflow interrupt
TIFR0 = TIFR0 | (1 << TOV0); // Set the overflow flag
sei(); // Enable All Interrupts
while(1)
{
;
}
}
ISR(TIMER0_OVF_vect)
{
if(overflowCounter == TOGGLECYCLES)
{
PORTA = PORTA ^ 0b10000000;
overflowCounter = 0;
}
overflowCounter++;
TIMSK0 = TIMSK0 | (1 << TOIE0); // Re-arm interrupt
}