[ATMEGA128] 시험

/*
INT0
timer0 500ms
평상시
LED_OFF 0xFF - PORTF

INT0 입력이 들어오면 500ms후에 불이 켜지게
하나씩 증가시켜서 불이 켜지도록 8개까지 켜지고 종료
*/

#include<avr/io.h>
#include<avr/interrupt.h>
#include<avr/signal.h>

#define CPU_CLOCK 16000000
#define TICKS_PER_SEC 1000
#define Prescaler 64
#define OVERFLOW 256

volatile unsigned int tic_time;
volatile unsigned STATE_FLAG;

void init_port(void);
void init_timer0(void);

int main(void){

        init_port();
        init_timer0();

        sei();
        while(1){
                if(tic_time>=500&&STATE_FLAG==1){
                        tic_time=0;
                        PORTF=(PORTF<<1);
                }
        }
        return 0;
}

void init_port(void){
        DDRF=0xFF;
        PORTF=0xFF;
        cbi(DDRD,INT0);

        EIFR=0x00;
        EICRA=0x03;
        EIMSK=0x01;
}
void init_timer0(void){
        TIFR=0x00;
        TCNT0=0x00;
        TCCR0=0x0C;
        OCR0=CPU_CLOCK/TICKS_PER_SEC/Prescaler;
        TIMSK=0x02;
}
SIGNAL(SIG_INTERRUPT0){
        tic_time=0;
        STATE_FLAG=1;
}

SIGNAL(SIG_OUTPUT_COMPARE0){
        tic_time++;
}

Posted by rCan

2008/10/14 18:04 2008/10/14 18:04
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/579

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

Leave a comment
« Previous : 1 : ... 22 : 23 : 24 : 25 : 26 : 27 : 28 : 29 : 30 : ... 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:
113575
Today:
6
Yesterday:
43