/*
처음은 불이 꺼진상태
PORTF=0xFF;
인터럽트4가 들어오면 불이 다 켜지게
인터럽트7이 들어오면 500ms LED반전
*/
#include<avr/io.h>
#include<avr/interrupt.h>
#include<avr/signal.h>
#define OVERFLOW 256
#define CPU_CLOCK 16000000
#define TICKS_PER_SEC 1000
#define Prescaler 64
volatile unsigned int tic_time;
void init_int(void);
void init_timerCounter(void);
int main(void){
init_timerCounter();
init_int();
sei(); // set enable interrupt
for(;;){
if(tic_time==500){
tic_time=0; // tic_time 초기화
PORTF=~PORTF; //200ms PORTF 상태 반전
}
}
return 1;
}
void init_int(){
cbi(DDRE,4);
cbi(DDRE,5);
cbi(DDRE,7);
EIFR=0x00;
EICRB=0x8A;
EIMSK=0xB0;
}
void init_timerCounter(){
// 초기화 작업
DDRF=0xFF; // DDRF 방향 설정
PORTF=0xFF; // PORTF LED 초기화
TIFR=0x00;
TCCR0=0x04; // Prescaler 설정
TCNT0= OVERFLOW - (CPU_CLOCK / TICKS_PER_SEC / Prescaler); // 오버플로우에 사용될 초기값
// TIMSK=0x01; // 오버플로우 인터럽트 허용
TIMSK=0x00; // 임시적으로 인터럽트 불가
}
SIGNAL(SIG_INTERRUPT4){
PORTF=0x00;
}
SIGNAL(SIG_INTERRUPT5){
TIMSK=0x00;
PORTF=0xFF;
}
SIGNAL(SIG_INTERRUPT7){
TIMSK=0x01; // 오버플로우 인터럽트 허용
}
SIGNAL(SIG_OVERFLOW0){
tic_time++; // 1000ms마다 생기는 오버 플로우를 카운팅함.
TCNT0 = OVERFLOW - (CPU_CLOCK / TICKS_PER_SEC / Prescaler); // 오버 플로우 한후에 TCNT0값을 초기화 시켜줌.
}
Posted by rCan
정보통신기기(01장).ppt

