View difference between Paste ID: HpPPRyP2 and BA5ZMiuC
SHOW: | | - or go back to the newest paste.
1
void startUP() {
2
	cli();	//Disable Interrupts
3
	sekunde = minute = sati = timerCounter = 0;
4
	
5
	TIMSK	|= (1<<OCIE0A) | (1<<TOIE0);		//Enable OCIE0A: Timer/Counter0 Output Compare Match A Interrupt Enable
6
	
7
	DDRB	= 0xFF;
8
	PORTB	= 0x00;
9
	DDRD	|= (1<<BUFFER0CLK) | (1<<BUFFER1CLK) | (1<<BUFFER2CLK) | (1<<BUFFER3CLK);	//Postavi pinove na kojima su baferi kao izlazne
10
	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)
11
	
12
	//Postavi sve sedmosegmentne displeje na neku pocetnu vrednost
13
	SetBufferValue(BUFFER0CLK, SSEG[10]);
14
	SetBufferValue(BUFFER1CLK, SSEG[5]);
15
	SetBufferValue(BUFFER2CLK, SSEG[1]);
16
	SetBufferValue(BUFFER3CLK, SSEG[2]);
17
	
18
	
19
	CLKPR = (1<<CLKPCE);	//Ukljuci prescale originalnog takta
20
	CLKPR |= (1<<CLKPS0); // Divide by 1
21
	
22
	
23
	TCCR0A	|= (1 << WGM01);				// Configure Timer 0 for CTC mode 
24
	TCCR0A	|= (1 << CS01) | (1 << CS00);	//Prescaling the timer
25-
	OCR0A	= 0xFA;							// Set CTC compare value to 0.5Hz AVR clock, with pre-scaler of 1024 
25+
	OCR0A	= 0xFA;							// Set CTC compare value
26
	TCNT0	= 0x00;							//Podesi brojac odakle da pocne da broji
27
	
28
	
29
	
30
	sei();	//Enable Interrupts
31
}
32
33
34
//Timer0 Interrupt funkcija
35
ISR(TIMER0_COMPA_vect) 
36
{
37
	//8MHz, MCU clock Prescale => 1, Timer Prescale => 128, Timer Interrupt every => 4ms
38
	//TODO:Finish Interrupt timer function
39
	timerCounter++;
40
	if(timerCounter >= 250)	{ 
41
		sekunde++; 
42
		timerCounter = 0;
43
		PORTD ^= (1<<SECPIN);
44
	}
45
	
46
	if(sekunde >= 60) {
47
		minute++; 
48
		sekunde = 0;
49
	}
50
	
51
	if(minute >= 60) {
52
		sati++;
53
		minute = 0;
54
	}
55
	
56
	if(sati >=24) {
57
		sati = 0;
58
	}
59
}