module 01 ex01 ok
This commit is contained in:
@@ -55,21 +55,17 @@ int main() {
|
|||||||
// -> Table 16-4 : use bit WGM12 to set mode ctc
|
// -> Table 16-4 : use bit WGM12 to set mode ctc
|
||||||
// -> 16.11.2 : bit WGM12 is located in register TCCR1B
|
// -> 16.11.2 : bit WGM12 is located in register TCCR1B
|
||||||
|
|
||||||
|
TCCR1A |= (1 << COM1A0 ) ; // Enable timer 1 Compare Output channel A in toggle mode
|
||||||
|
// -> Table 14-3 : alternate functions for PORTB1 is OC1A (Timer/Counter1 Output Compare Match A Output)
|
||||||
|
// -> 14.3.1 : OC1A/PCINT1 – Port B, Bit 1
|
||||||
|
|
||||||
OCR1A = TIME_MS(500); // set CTC compare value
|
OCR1A = TIME_MS(500); // set CTC compare value
|
||||||
// -> Table 16-4 : the value to reset the timer is the Output Compare Registers OCR1A
|
// -> Table 16-4 : the value to reset the timer is the Output Compare Registers OCR1A
|
||||||
|
|
||||||
TCCR1B |= (PRESCALE_SET);
|
TCCR1B |= (PRESCALE_SET);
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
if (TIFR1 & (1 << OCF1A)) { // when comparison has occured, bit OCF1A is set
|
continue;
|
||||||
// -> 16.2.1 : "The compare match event will also set the Compare Match Flag (OCF1A/B) which can be used to generate an Output Compare interrupt request"
|
|
||||||
// -> 16.11.9 : bit OCF1A is in register TIFR1
|
|
||||||
|
|
||||||
TOGGLE_LED(D2); // toggle using PINx register
|
|
||||||
|
|
||||||
TIFR1 = (1 << OCF1A); // clear the CTC flag
|
|
||||||
// -> 16.11.9 : "OCF1A can be cleared by writing a logic one to its bit location"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user