Advertisement
backlog

Untitled

Nov 1st, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #define F_CPU 8000000UL
  2. #include <avr/io.h>
  3. #include <util/delay.h>
  4.  
  5. #define R1 3
  6. #define Y1 4
  7. #define G1 5
  8.  
  9. #define R2 6
  10. #define Y2 7
  11. #define G2 8
  12.  
  13. #define R3 9
  14. #define Y3 10
  15. #define G3 11
  16.  
  17. #define R4 12
  18. #define Y4 13
  19. #define G4 2
  20.  
  21. void setup(){
  22.   for(int i =2; i <= 13; i++)
  23.     pinMode(i, OUTPUT);
  24.  
  25.   DDRB = 0xff;
  26.   DDRD = 0xff;
  27.   DDRC = 0x00;
  28.  
  29.   PORTB = 0x00;
  30.   PORTD = 0x00;
  31. }
  32.  
  33. void loop()
  34. {
  35.  
  36.     if((PINC&0x01) == 0x01)
  37.     {
  38.     PORTB |= (1<<G1);
  39.     PORTB |= (1<<Y2);
  40.     PORTD |= (1<<R3);
  41.     PORTD |= (1<<R4);
  42.    
  43.     }
  44.     else if((PINC&0x02) == 0x02)
  45.     {
  46.     PORTB |= (1<<R1);
  47.     PORTB |= (1<<G2);
  48.     PORTD |= (1<<Y3);
  49.     PORTD |= (1<<R4);
  50.    
  51.     }
  52.    
  53.     else if((PINC&0x04) == 0x04)
  54.     {
  55.     PORTB |= (1<<R1);
  56.     PORTB |= (1<<R2);
  57.     PORTD |= (1<<G3);
  58.     PORTD |= (1<<Y4);
  59.    
  60.     }
  61.    
  62.     else if((PINC&0x08) == 0x08)
  63.     {
  64.     PORTB |= (1<<Y1);
  65.     PORTB |= (1<<R2);
  66.     PORTD |= (1<<R3);
  67.     PORTD |= (1<<G4);
  68.    
  69.     }
  70.    
  71.     else
  72.     {
  73.       PORTB = 0x00;
  74.     PORTD = 0x00;
  75.      
  76.     PORTB |= (1<<G1);
  77.     PORTB |= (1<<Y2);
  78.     PORTD |= (1<<R3);
  79.     PORTD |= (1<<R4);
  80.     _delay_ms(7000);
  81.    
  82.     PORTB = 0x00;
  83.     PORTD = 0x00;
  84.    
  85.     PORTB |= (1<<R1);
  86.     PORTB |= (1<<G2);
  87.     PORTD |= (1<<Y3);
  88.     PORTD |= (1<<R4);
  89.     _delay_ms(7000);
  90.    
  91.     PORTB = 0x00;
  92.     PORTD = 0x00;
  93.    
  94.     PORTB |= (1<<R1);
  95.     PORTB |= (1<<R2);
  96.     PORTD |= (1<<G3);
  97.     PORTD |= (1<<Y4);
  98.     _delay_ms(7000);
  99.    
  100.     PORTB = 0x00;
  101.     PORTD = 0x00;
  102.     PORTB |= (1<<Y1);
  103.     PORTB |= (1<<R2);
  104.     PORTD |= (1<<R3);
  105.     PORTD |= (1<<G4);
  106.     _delay_ms(7000);
  107.     PORTB = 0x00;
  108.     PORTD = 0x00;
  109.     }  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement