«   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] LED 2개 동시에 켜기[깜빡이기] 본문

Univ/AVR atmega128

[AVR] LED 2개 동시에 켜기[깜빡이기]

ITGenerations 2017. 12. 10. 17:51

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


}


*/