[ATMEGA128] 흐음

/*
타이머2에서 클럭이 들어와서 인터럽트 발생시에.
타이머0에서 300ms마다 불이
*/

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

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

volatile unsigned int tic_time;
volatile unsigned int STATE_FLAG;
volatile unsigned int cnt;

SIGNAL(SIG_OVERFLOW2){
        STATE_FLAG=1;
}
SIGNAL(SIG_OUTPUT_COMPARE0){
        tic_time++;
}


int main(void){

        init_port();
        init_timer0();
        init_timer2();

        sei();
        for(;;){
                if(STATE_FLAG==1){
                        if(tic_time>=300){
                                tic_time=0;
                                if(cnt>8) cnt=0;
                                PORTF=~(0xFF&(1<<cnt));
                                cnt++;
                        }
                }
        }
        return 0;
}

void init_port(){
        DDRF=0xFF;
        PORTF=0xFF;
        cbi(DDRD,7);
}
void init_timer0(){
        TIFR=0x00;
        TCCR0=0x0C;  // 00001100
        TCNT0=0;
        OCR0=249;
}
void init_timer2(){
        TIFR=0x00;
        TCCR2=0x06;
        TCNT2=253;
        TIMSK=0x42;
}

Posted by rCan

2008/10/01 17:13 2008/10/01 17:13
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/573

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

Leave a comment
« Previous : 1 : ... 28 : 29 : 30 : 31 : 32 : 33 : 34 : 35 : 36 : ... 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