Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. #define F_CPU 16000000UL
  2. #include <avr/io.h>
  3. #include <avr/interrupt.h>
  4. #include <avr/pgmspace.h>
  5. #include "lookup.dat"
  6.  
  7. volatile int zaehlerstand = 0;
  8.  
  9. void init (void)
  10. {
  11. DDRB |= (1<<DDB1) | (1<<DDB2) | (1<<DDB3);// RGB auf Output setzen
  12.  
  13. TCCR1A |= (1<<WGM10) | (1<<COM1A1) | (1<<COM1B1); // 8-bit Phase Correct PWM Modus Timer 1, CTC
  14. TCCR1B |= (1<<CS11); // Prescaler 8
  15.  
  16. TCCR2A |= (1<<WGM20) | (1<<COM2A1); //PWM Phase Correct Timer 2, CTC
  17. TCCR2B |= (1<<CS21);// Prescaler 8
  18.  
  19. TCCR0B |= (1<<CS02) | (1<<CS00); //Prescaler 1024
  20. TCNT0 = 134; //Startwert
  21.  
  22. TIMSK0 |= (1<<TOIE0); //Interrupt Lokal aktivieren
  23.  
  24. sei(); //Global Interrupt aktivieren
  25.  
  26. }
  27.  
  28. int main (void)
  29. {
  30. init ();
  31. while (1)
  32. {
  33. //Rot LED
  34. OCR1B = 0;
  35. OCR2A = 0;
  36. OCR1A = 0;
  37. zaehlerstand = 0;
  38. while (zaehlerstand <= 255)
  39. {
  40. OCR1A = pgm_read_byte_near(lookup +zaehlerstand);
  41. }
  42.  
  43. OCR1A = 0;
  44.  
  45. //Warten 2s
  46. zaehlerstand = 0;
  47. while (zaehlerstand <= 255)
  48. {
  49.  
  50. }
  51.  
  52. //Grün LED
  53. zaehlerstand = 0;
  54. while (zaehlerstand <= 255)
  55. {
  56. OCR1B = pgm_read_byte_near(lookup +zaehlerstand);
  57. }
  58.  
  59. OCR1B = 0;
  60.  
  61. //Warten 2s
  62. zaehlerstand = 0;
  63. while (zaehlerstand <= 255)
  64. {
  65.  
  66. }
  67.  
  68. //Blaue LED
  69. zaehlerstand = 0;
  70. while (zaehlerstand <= 255)
  71. {
  72. OCR2A = pgm_read_byte_near(lookup +zaehlerstand);
  73. }
  74.  
  75. OCR2A = 0;
  76.  
  77. //Warten 2s
  78. zaehlerstand = 0;
  79. while (zaehlerstand <= 255)
  80. {
  81.  
  82. }
  83.  
  84. //Alle zusammen
  85. zaehlerstand = 0;
  86. while (zaehlerstand <=255)
  87. {
  88. OCR1A = pgm_read_byte_near(lookup +zaehlerstand);
  89. OCR1B = pgm_read_byte_near(lookup +zaehlerstand);
  90. OCR2A = pgm_read_byte_near(lookup +zaehlerstand);
  91. }
  92. zaehlerstand = 0;
  93. while (zaehlerstand <=255)
  94. {
  95. OCR1A = pgm_read_byte_near(lookup + 255 -zaehlerstand);
  96. OCR1B = pgm_read_byte_near(lookup + 255 -zaehlerstand);
  97. OCR2A = pgm_read_byte_near(lookup + 255 -zaehlerstand);
  98. }
  99.  
  100. OCR1B = 0;
  101. OCR2A = 0;
  102. OCR1A = 0;
  103. //Warten 2s
  104. zaehlerstand = 0;
  105. while (zaehlerstand <= 255)
  106. {
  107.  
  108. }
  109. }
  110.  
  111.  
  112. }
  113.  
  114. ISR (TIMER0_OVF_vect)
  115. {
  116. TCNT0 = 134;
  117. zaehlerstand++;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement