Timer AVR ATMEGA32

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

/* * GccApplication1.

c * * Created: 18/02/2013 11:06:38 PM * Author: Aitzaz */

int ocr=0; int check=0; #include<avr/io.h> #include<util/delay.h> #include<avr/interrupt.h> void t0_init(void);

int main() { initialize_timer(); sei(); // timer initialize // enable global interrupts

while(1) { } }

void initialize_timer() {

TCCR0=(1<<WGM01)|(1<<WGM00)|(1<<COM01)|(1<<CS01)|(1<<CS00); DDRB|=(1<<PB3); TIMSK|=(1<<OCIE0); } // select as output pin //enable output compare interrupt

ISR(TIMER0_COMP_vect) { if(ocr<255&&check==0)

// interrupt routine , called every time timer matches the stored count

{ OCR0=ocr; ocr=ocr+1; if(ocr==255) { check=1; } } if (check==1) { OCR0=ocr; ocr--; if(ocr==0) { check=0; } }

You might also like