fork(1) download
  1. #include <avr/io.h> // this contains all the IO port definitions
  2. #include <avr/interrupt.h>
  3. #include <avr/signal.h>
  4. #include <avr/pgmspace.h>
  5. #include <util/delay.h>
  6.  
  7. void delay_ms( uint16_t milliseconds)
  8. {
  9. for( ; milliseconds > 0; milliseconds--)
  10. {
  11. _delay_ms( 1);
  12. }
  13. }
  14.  
  15. #define TIMER1_PRESCALE_1 1
  16. #define TIMER1_PRESCALE_8 2
  17. #define TIMER1_PRESCALE_64 3
  18. #define TIMER1_PRESCALE_256 4
  19. #define TIMER1_PRESCALE_1024 5
  20.  
  21.  
  22. // We use these macros because binary constants arent always supported. ugh.
  23. #define HEX__(n) 0x##n##UL
  24. #define B8__(x) ((x&0x0000000FLU)?1:0) \
  25.   +((x&0x000000F0LU)?2:0) \
  26.   +((x&0x00000F00LU)?4:0) \
  27.   +((x&0x0000F000LU)?8:0) \
  28.   +((x&0x000F0000LU)?16:0) \
  29.   +((x&0x00F00000LU)?32:0) \
  30.   +((x&0x0F000000LU)?64:0) \
  31.   +((x&0xF0000000LU)?128:0)
  32. #define B8(d) ((unsigned char)B8__(HEX__(d)))
  33.  
  34.  
  35. // store all the image data in program memory (ROM)
  36. // instead of RAM (the default)
  37. const uint8_t large_image[] PROGMEM = {
  38. B8(00000000),
  39. B8(01110000),
  40. B8(10101000),
  41. B8(10101000),
  42. B8(10101000),
  43. B8(10110000),
  44. B8(00000000),
  45. B8(00000000),
  46. B8(10001000),
  47. B8(11011000),
  48. B8(00100000),
  49. B8(11011000),
  50. B8(10001000),
  51. B8(00000000),
  52. B8(00000000),
  53. B8(10001000),
  54. B8(10001000),
  55. B8(11111010),
  56. B8(10000000),
  57. B8(10000000),
  58. B8(00000000),
  59. B8(00001000),
  60. B8(01111100),
  61. B8(10001000),
  62. B8(10001000),
  63. B8(10001000),
  64. B8(01000000),
  65. B8(00000000),
  66. B8(00000000),
  67. };
  68.  
  69. // special pointer for reading from ROM memory
  70. PGM_P largeimage_p PROGMEM = large_image;
  71.  
  72. #define NUM_ELEM(x) (sizeof (x) / sizeof (*(x)))
  73. int imagesize = NUM_ELEM(large_image);
  74.  
  75.  
  76.  
  77. // this function is called when timer1 compare matches OCR1A
  78. uint8_t j = 0;
  79. SIGNAL( SIG_TIMER1_COMPA ) {
  80. if (j >= imagesize)
  81. j = 0;
  82.  
  83. // read the image data from ROM
  84. PORTB = pgm_read_byte(largeimage_p + j);
  85.  
  86. j++;
  87. }
  88.  
  89. int main(void) {
  90.  
  91. DDRB = 0xFF; // set all 8 pins on port B to outputs
  92.  
  93. /*
  94.   the frequency of the interrupt overflow is determined by the
  95.   prescaler and overflow value.
  96.   freq = clock_frequency / ( 2 * prescaler * overflow_val)
  97.   where prescaler can be 1, 8, 64, 256, or 1024
  98.   clock_freq is 8MHz
  99.   and overflow_val is 16bit
  100.  
  101.   the overflow value is placed in OCR1A, the prescale is set in TCCR1B
  102.   so for example:
  103.   A good POV frequency is around 400Hz
  104.   desired freq = 400Hz
  105.   clock freq = 8MHz
  106.   8MHz / (400Hz * 2) = 10000
  107.   since 10000 is less than 655536 (largest 16 bit number)
  108.   OCR1A = 10000 and the prescale is 1
  109.   */
  110.  
  111. TCCR1B = (1 << WGM12) | TIMER1_PRESCALE_1;
  112. OCR1A = (uint16_t)10000;
  113.  
  114. TIMSK |= 1 << OCIE1A; // Output Compare Interrupt Enable (timer 1, OCR1A)
  115.  
  116. sei(); // Set Enable Interrupts
  117.  
  118. while (1);
  119. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:70: fatal error: avr/io.h: No such file or directory
compilation terminated.
stdout
Standard output is empty