[ATMEGA128] 시험관련


/*
시계 FND 0부터 59초
60초가 되면 LED1개 켜지기
OVERFLOW0 사용
08.12.10 수정
*/
#include<avr/io.h>
#include<avr/interrupt.h>
#include<avr/signal.h>


volatile unsigned int TIC_TIME;
volatile unsigned int TIME;
volatile unsigned int min;
volatile unsigned int sec;

void init_port(void){
        DDRC=0xFF;
        DDRD=0xFF;

        PORTC=0xFF;
        PORTD=0x00;
}
void init_timer0(void){
        TCCR0=0x04;
        TCNT0=6;
        TIMSK=TIMSK|(1<<TOIE0);
}
void init_timer(void){
        TIFR=0x00;
        init_timer0();
}
void init(void){
        init_port();
        init_timer();
}

SIGNAL(SIG_OVERFLOW0){
        TCNT0=6;
        TIC_TIME++;
}

int main(void){

        init();
        sei();
        while(1){
                if(TIC_TIME>1000){
                        TIC_TIME=0;
                        TIME++;
                        if(TIME==540){
                                PORTC=0xFF;
                                TIME=0;
                        }
                }
                min=TIME/60;
                sec=TIME%60;


                PORTC=0xFF<<min;
                PORTD=(sec/10)<<4||(sec%10);
        }

        return 0;
}

Posted by rCan

2008/12/09 16:39 2008/12/09 16:39
Response
No Trackback , No Comment
RSS :
http://rcan.net/rss/response/584

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

Leave a comment
« Previous : 1 : 2 : 3 : 4 : 5 : 6 : ... 19 : Next »

블로그 이미지

- rCan

Calendar

«   2010/09   »
      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 30    

Notices

  1. About Me

Recent Posts

Site Stats

Total hits:
89710
Today:
20
Yesterday:
42