Guest User

Expected ':', ',', ';', '}' or '__attribute__' before '=' to

a guest
Jan 9th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <stdint.h>
  3. #include <avr/interrupt.h>
  4. #include <math.h>
  5. #include <util/delay.h>
  6.  
  7.  
  8. struct
  9. {
  10.     const uint8_t fioletowy[3] = {255,0,255};
  11.     const uint8_t blekitny[3] = {0,255,255};
  12.     const uint8_t czerwony[3] = {255,0,0};
  13.     const uint8_t zielony[3] = {0,255,0};
  14.     const uint8_t niebieski[3] = {0,0,255};
  15.     const uint8_t pomaranczowy[3] = {255,128,0};
  16.     const uint8_t zolty[3] = {255,255,0};
  17.     const uint8_t bialy[3] = {255,255,255};
  18.     const uint8_t rozowy[3] = {255,100,255};
  19.     const uint8_t cyjanowy[3] = {0,255,225};
  20. } kolory;
  21.  
  22. void setPwm(uint8_t channel, uint8_t pwm)
  23. {
  24.     switch(channel)
  25.     {
  26.         case 1:
  27.         OCR1A = pwm;
  28.         break;
  29.  
  30.         case 2:
  31.         OCR1B = pwm;
  32.         break;
  33.  
  34.         case 3:
  35.         OCR2A = pwm;
  36.         break;
  37.     }
  38. }
  39.  
  40.  
  41. int main()
  42. {
  43.     PORTD &= ( (1<<PD1) & (1<<PD2) );
  44.     DDRD |= ( (1<<PD1) | (1<<PD2) );
  45.    
  46.     TCCR1A |= ( (1<<COM1A1) | (1<<COM1B1 | (1<<COM1B0) | (1<<COM1A0)) );
  47.     TCCR1A |= (1<<WGM10);
  48.     TCCR1B |= ( (1<<WGM12) | (1<<CS11) );
  49.  
  50.     TCCR2A |= ( (1<<COM2A1) | (1<<COM2B1) | (1<<COM2B0) | (1<<COM2A0) );
  51.     TCCR2A |= (1<<WGM20);
  52.     TCCR2B |= ( (1<<WGM21) | (1<<CS21) );
  53.    
  54.     DDRB |= ( 1<<PB1 | 1<<PB2 | 1<<PB3 );
  55.    
  56.     while(1)
  57.     {
  58.         setPwm(1, 0);
  59.         setPwm(2, 0);
  60.         setPwm(3, 0);
  61.         _delay_ms(500);
  62.        
  63.         setPwm(1, 128);
  64.         setPwm(2, 128);
  65.         setPwm(3, 128);
  66.         _delay_ms(500);
  67.        
  68.         setPwm(1, 255);
  69.         setPwm(2, 255);
  70.         setPwm(3, 255);
  71.         _delay_ms(500);
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment