fork(2) download
  1. #include <avr/interrupt.h>
  2. #include <avr/io.h>
  3. #include <avr/sleep.h>
  4. #include <util/delay.h>
  5.  
  6. #include <stddef.h>
  7. #include <stdint.h>
  8.  
  9. static volatile uint8_t count = 0xffu;
  10. static volatile size_t overflows = 0;
  11.  
  12. enum {
  13. PRESCALER = 256u,
  14. TCNT1_START = 65536lu - F_CPU / PRESCALER,
  15. TCNT1_MAX = 65536lu - TCNT1_START,
  16. CLOCKS_PER_SECOND = F_CPU / PRESCALER / TCNT1_MAX
  17. };
  18.  
  19. ISR(INT0_vect) {
  20. PORTB = --count;
  21. }
  22.  
  23. ISR(INT1_vect) {
  24. TCCR1B ^= _BV(CS12);
  25. TCNT1H = TCNT1_START >> 8u;
  26. TCNT1L = TCNT1_START << 8u;
  27. }
  28.  
  29. ISR(TIMER1_OVF_vect) {
  30. if (++overflows >= CLOCKS_PER_SECOND) {
  31. PORTB = --count;
  32. overflows = 0;
  33. }
  34. TCNT1H = TCNT1_START >> 8u;
  35. TCNT1L = TCNT1_START << 8u;
  36. }
  37.  
  38. int main(void) {
  39. DDRB = 0xffu;
  40. PORTB = 0xffu;
  41. GICR |= _BV(INT0) | _BV(INT1);
  42. MCUCR |= _BV(ISC00) | _BV(ISC01) | _BV(ISC10) | _BV(ISC11);
  43. TIMSK |= _BV(TOIE1);
  44. TCCR1B |= _BV(CS12);
  45. TCNT1H = TCNT1_START >> 8u;
  46. TCNT1L = TCNT1_START << 8u;
  47. sei();
  48. set_sleep_mode(SLEEP_MODE_IDLE);
  49. for (;;) {
  50. sleep_mode();
  51. }
  52. }
  53.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty