Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void startUP() {
- cli(); //Disable Interrupts
- sekunde = minute = sati = timerCounter = 0;
- TIMSK |= (1<<OCIE0A) | (1<<TOIE0); //Enable OCIE0A: Timer/Counter0 Output Compare Match A Interrupt Enable
- DDRB = 0xFF;
- PORTB = 0x00;
- DDRD |= (1<<BUFFER0CLK) | (1<<BUFFER1CLK) | (1<<BUFFER2CLK) | (1<<BUFFER3CLK); //Postavi pinove na kojima su baferi kao izlazne
- PORTD |= (1<<BUFFER0CLK) | (1<<BUFFER1CLK) | (1<<BUFFER2CLK) | (1<<BUFFER3CLK); //Stavi logicke 1 na CLK od bafera (podaci se upisuju kad dodje HIGH-to-LOW tranzicija)
- //Postavi sve sedmosegmentne displeje na neku pocetnu vrednost
- SetBufferValue(BUFFER0CLK, SSEG[10]);
- SetBufferValue(BUFFER1CLK, SSEG[5]);
- SetBufferValue(BUFFER2CLK, SSEG[1]);
- SetBufferValue(BUFFER3CLK, SSEG[2]);
- CLKPR = (1<<CLKPCE); //Ukljuci prescale originalnog takta
- CLKPR |= (1<<CLKPS0); // Divide by 1
- TCCR0A |= (1 << WGM01); // Configure Timer 0 for CTC mode
- TCCR0A |= (1 << CS01) | (1 << CS00); //Prescaling the timer
- OCR0A = 0xFA; // Set CTC compare value
- TCNT0 = 0x00; //Podesi brojac odakle da pocne da broji
- sei(); //Enable Interrupts
- }
- //Timer0 Interrupt funkcija
- ISR(TIMER0_COMPA_vect)
- {
- //8MHz, MCU clock Prescale => 1, Timer Prescale => 128, Timer Interrupt every => 4ms
- //TODO:Finish Interrupt timer function
- timerCounter++;
- if(timerCounter >= 250) {
- sekunde++;
- timerCounter = 0;
- PORTD ^= (1<<SECPIN);
- }
- if(sekunde >= 60) {
- minute++;
- sekunde = 0;
- }
- if(minute >= 60) {
- sati++;
- minute = 0;
- }
- if(sati >=24) {
- sati = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement