SHARE
TWEET

Untitled

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