[AVR] LED 2개 동시에 켜기[깜빡이기]
// source 19
// 타이머 2를 추가해서 동시에 LED 2개 깜빡이기
// PA0, PA1에 연결
// PA -> + -> LED -> - -> GND 연결
#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 &= ~(0x01);
}
}
}
ISR(TIMER2_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 |= 0x02;
}
else
{
led = 1;
PORTA &= ~(0x02);
}
}
}
int main()
{
DDRA=0xFF;
PORTA=0xFF;
TCCR0 = (1<<WGM01)|(0<<WGM00)|(0<<COM01)|(0<<COM00)|(1<<CS02)|(1<<CS01)|(1<<CS00);
TCCR2 = (1<<WGM21)|(0<<WGM20)|(0<<COM21)|(0<<COM20)|(1<<CS22)|(0<<CS21)|(1<<CS20);
// OCR0 시정수
// (1/16M) * 분주비(1024) * OCR0 = 10ms --> OCR0 = 156.25 = 약156
TCNT0 = 0x00;
OCR0 = 0x9C;//156
TCNT2 = 0x00;
OCR2 = 0x9C;//156
TIMSK = (1<<OCIE0)|(1<<OCIE2); // Output Compare Interrupt Enable 0
sei();
while(1);
}
*/