#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#define LED1 PB7 // 8bit 타이머 카운터 사용할 led
#define LED2 PB6 // 16bit 타이머 카운터 사용할 led
volatile unsigned long timer0; //오버플로마다 1씩 증가될 변수
volatile unsigned long timer1;
ISR(TIMER0_OVF_vect)
{
timer0++; // 오버플로마다 1씩 증가
if(timer0 % 100 == 0){
PORTB ^= 1 << LED1; // PORTB의 LED 위치 비트를 반전시킴
}
}
ISR(TIMER1_OVF_vect)
{
timer1++; // 오버플로마다 1씩 증가
//if(timer1 % 100 == 0){
PORTB ^= 1 << LED2; // PORTB의 LED 위치 비트를 반전시킴
//}
}
int main(void)
{
DDRB |= (1 << LED1);
DDRB |= (1 << LED2); // LED 출력 핀으로 설정
TCCR0 |= (1 << CS02) | (1 << CS01); //256 분주 프리스케일러
TCCR1B |= (1 << CS12) | (1 << CS10) ; //1024 분주 프리스케일러 (65536*1024)/16mhz = 4.194304초
TIMSK |= (1 << TOIE0);
TIMSK |= (1 << TOIE1); //타이머/카운터 인터럽트 활성화
timer0 = 0;
timer1 =0;
sei();
while (1);
return 0;
}
'임베디드 > Atmega128' 카테고리의 다른 글
analog (0) | 2021.01.29 |
---|---|
atmega128 (timer/counter0 normal) + (timer/counter2 fast pwm) LED깜빡이기 (0) | 2021.01.29 |
인터럽트(Interrupt) 개요 (0) | 2021.01.24 |
ATmega128 인터럽트방식 p247 (pdf246) (0) | 2021.01.22 |
ATmega128 공통음극 캐소드 MT03911AR 7세그먼트 (0) | 2021.01.21 |