«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

ITGenerations

[avr] 타이머 본문

Univ/AVR atmega128

[avr] 타이머

ITGenerations 2017. 12. 8. 23:58

/source 14


#include <avr/io.h>

#include <avr/interrupt.h>


ISR(TIMER0_COMP_vect)

{

static int led=0;

static char n_enter=0;

n_enter++;

if(n_enter==50)

{

n_enter=0;

if(led)

{

led=0;

PORTA=0x01;

}


else

{

led=1;

PORTA=0x00;

}

}

}



int main()

{

DDRA=0xFF;

DDRB=0xFF;

PORTA=0xFF;


TCCR0=(1<<WGM01)|(0<<WGM00)|(1<<COM00)|(1<<CS02)|(1<<CS01)|(1<<CS00);

OCR0=0x9c;

TIMSK = (1<<OCIE0);

sei();

while(1);


}