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);
}