fork download
  1. static uint16_t second_ticks = 1.0 * 32768.0; // you know it's a whole number
  2. static uint16_t third_second_ticks = 0.3 * second_ticks; // it was rounded
  3.  
  4. static uint16_t seconds_time;
  5. static uint8_t counter = 0;
  6.  
  7. int main(void)
  8. {
  9. sei(); //Enable interrupts
  10. ASSR |= (1<<5);// enable bit 5 "ASSR". enables external 32kHZ crystal
  11. u8g_Delay(250); //let external 32KHz crystal stabilize
  12. TCCR2B &=~ (1 << WGM22); //Normal counting mode (overflow whenever at max value)
  13.  
  14. // You start by arranging the ISR to fire third_second_ticks from now.
  15. seconds_time = TCNT2;
  16. OCR2A = seconds_time + third_second_ticks;
  17.  
  18. TIMSK2 |= (1 << OCIE2A); //enable interrupts on OCR2A
  19.  
  20. }
  21.  
  22. ISR(TIMER2_COMPA_vect)
  23. {
  24. counter++;
  25. if (counter == 3) {
  26. seconds_time += second_ticks;
  27. OCR2A = seconds_time + third_second_ticks;
  28. counter = 0;
  29.  
  30. lockseconds++;
  31. PORTA ^= (1 << 0); // Toggle the LED
  32. } else {
  33. OCR2A += third_second_ticks;
  34. counter++;
  35. }
  36. }
  37.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:1: error: unknown type name ‘uint16_t’
 static uint16_t second_ticks = 1.0 * 32768.0; // you know it's a whole number
 ^
prog.c:2:1: error: unknown type name ‘uint16_t’
 static uint16_t third_second_ticks = 0.3 * second_ticks; // it was rounded
 ^
prog.c:2:1: error: initializer element is not constant
prog.c:4:1: error: unknown type name ‘uint16_t’
 static uint16_t seconds_time;
 ^
prog.c:5:1: error: unknown type name ‘uint8_t’
 static uint8_t counter = 0;
 ^
prog.c: In function ‘main’:
prog.c:9:1: warning: implicit declaration of function ‘sei’ [-Wimplicit-function-declaration]
 sei(); //Enable interrupts
 ^
prog.c:10:1: error: ‘ASSR’ undeclared (first use in this function)
 ASSR |= (1<<5);// enable bit 5 "ASSR". enables external 32kHZ crystal
 ^
prog.c:10:1: note: each undeclared identifier is reported only once for each function it appears in
prog.c:11:1: warning: implicit declaration of function ‘u8g_Delay’ [-Wimplicit-function-declaration]
 u8g_Delay(250); //let external 32KHz crystal stabilize
 ^
prog.c:12:1: error: ‘TCCR2B’ undeclared (first use in this function)
 TCCR2B &=~ (1 << WGM22); //Normal counting mode (overflow whenever at max value)
 ^
prog.c:12:18: error: ‘WGM22’ undeclared (first use in this function)
 TCCR2B &=~ (1 << WGM22); //Normal counting mode (overflow whenever at max value)
                  ^
prog.c:15:16: error: ‘TCNT2’ undeclared (first use in this function)
 seconds_time = TCNT2;
                ^
prog.c:16:1: error: ‘OCR2A’ undeclared (first use in this function)
 OCR2A = seconds_time + third_second_ticks;
 ^
prog.c:18:1: error: ‘TIMSK2’ undeclared (first use in this function)
 TIMSK2 |= (1 << OCIE2A); //enable interrupts on OCR2A
 ^
prog.c:18:17: error: ‘OCIE2A’ undeclared (first use in this function)
 TIMSK2 |= (1 << OCIE2A); //enable interrupts on OCR2A
                 ^
prog.c: At top level:
prog.c:22:1: warning: return type defaults to ‘int’ [-Wreturn-type]
 ISR(TIMER2_COMPA_vect)
 ^
prog.c: In function ‘ISR’:
prog.c:27:3: error: ‘OCR2A’ undeclared (first use in this function)
   OCR2A = seconds_time + third_second_ticks;
   ^
prog.c:30:3: error: ‘lockseconds’ undeclared (first use in this function)
   lockseconds++;
   ^
prog.c:31:9: error: ‘PORTA’ undeclared (first use in this function)
         PORTA ^= (1 << 0); // Toggle the LED
         ^
prog.c: In function ‘main’:
prog.c:20:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
prog.c: In function ‘ISR’:
prog.c:36:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty