Univ/AVR atmega128
[AVR] LED 전원 제어 타이머 0 CTC모드
ITGenerations
2017. 12. 10. 17:41
// source 16
// LED 전원 제어 타이머 0 CTC모드
// PA0에 연결, on off
/*
#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) //50 * 10 = 500ms
{
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 시정수
// (1/16M) * 분주비(1024) * OCR0 = 10ms --> OCR0 = 156.25 = 약156
OCR0 = 0x9C;//156
TIMSK = (1<<OCIE0); // Output Compare Interrupt Enable 0
sei();
while(1);
}
*/