Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define F_CPU 7372800UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- static uint8_t br[10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
- static uint8_t sec, msec;
- static uint8_t seg[4] = {_BV(4), _BV(5), _BV(6), _BV(7)};
- static uint8_t state = 0x00;
- ISR(TIMER1_COMPA_vect)
- {
- state ^= 0x80;
- }
- ISR(TIMER0_COMP_vect)
- {
- //za brojeve
- msec++;
- if(msec == 100)
- {
- msec = 0;
- sec++;
- if(sec == 60)
- {
- sec = 0;
- }
- }
- }
- int main(void)
- {
- DDRA = 0xff;
- PORTA = 0xff;
- DDRB = 0xf0;
- sec = 0;
- msec = 0;
- //timer 1
- TCCR1B = _BV(WGM12) | _BV(CS12);
- OCR1A = 14399; //za tockicu,imamo formulu s ctcom s 2 zato sto je pola sekunde upaljena,pola ugasena
- //timer 0
- TCCR0 = _BV(WGM01) | _BV(CS02) | _BV(CS00);
- OCR0 = 71; //bez 2 jer se racuna vrijeme i nema blinkanja nikakvog
- TIMSK = _BV(OCIE1A) | _BV(OCIE0);
- sei();
- while (1)
- {
- PORTB = seg[0];
- PORTA = br[sec/10];
- _delay_ms(1);
- PORTB = seg[1];
- PORTA = br[sec%10];
- PORTA ^= state;
- _delay_ms(1);
- PORTB = seg[2];
- PORTA = br[msec/10];
- _delay_ms(1);
- PORTB = seg[3];
- PORTA = br[msec%10];
- _delay_ms(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement