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 play;
- static uint8_t state = 0x00;
- ISR(TIMER1_COMPA_vect)
- {
- if(play == 1) {
- state ^= 0x80;
- }
- }
- ISR(TIMER0_COMP_vect)
- {
- //za brojeve
- if(play == 1){
- msec++;
- if(msec == 100)
- {
- msec = 0;
- sec++;
- if(sec == 60)
- {
- sec = 0;
- }
- }
- }
- }
- void debounce()
- {
- _delay_ms(400);
- }
- int main(void)
- {
- DDRA = 0xff;
- PORTA = 0xff;
- PORTB = _BV(0) | _BV(1); //moramo dignuti pull-up zbog key-eva
- DDRB = 0xf0;
- sec = 0;
- msec = 0;
- play = 1;
- //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);
- PORTB |= 0x0f; //zato sto gore mijenjamo PORTB,pa PINB kod key-a ne zna u kojem stanju je PORTB trenutno(izgubio je stanje 0x0f of gore)
- //ovo za key-eve mora biti u while-u
- if(bit_is_clear(PINB,0)) {
- play ^= 1;
- }
- if(bit_is_clear(PINB,1)) {
- sec = 0;
- msec = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement