[ATMEGA128] 인터럽트 타이머 장난(?)

/*
처음은 불이 꺼진상태
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

2008/09/16 17:44 2008/09/16 17:44
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/564

Trackback URL : http://rcan.net/trackback/564

Leave a comment
« Previous : 1 : ... 35 : 36 : 37 : 38 : 39 : 40 : 41 : 42 : 43 : ... 439 : Next »

블로그 이미지

- rCan

Calendar

«   2012/02   »
      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      

Notices

  1. About Me

Site Stats

Total hits:
113660
Today:
33
Yesterday:
58