Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. #define F_CPU 1000000L
  2. #include <avr/io.h>
  3. #include <util/delay.h>
  4.  
  5. #define diody_0 (1<<PA0)
  6. #define diody_1 (1<<PA1)
  7. #define diody_2 (1<<PA2)
  8. #define diody_3 (1<<PA3)
  9. #define diody_4 (1<<PA4)
  10. #define diody_5 (1<<PA5)
  11. #define diody_6 (1<<PA6)
  12. #define diody_7 (1<<PA7)
  13.  
  14. //tablica diod
  15. int diody[8] = {diody_0, diody_1, diody_2, diody_3,
  16.                 diody_4, diody_5, diody_6, diody_7};
  17.  
  18. int main(void)
  19. {
  20.     DDRA |= diody[0] | diody[1] | diody[2] | diody[3] |
  21.              diody[4] | diody[5] | diody[6] | diody[7];
  22.    
  23.     //czas pomiędzy "przeskakiwaniem" diod
  24.     int czas = 100;
  25.  
  26.     //przycisk SW_1
  27.     DDRB &= ~(1<<PB0);
  28.     PORTB |= (1<<PB0);
  29.  
  30.     //przycisk SW_2
  31.     DDRB &= ~(1<<PB1);
  32.     PORTB |= (1<<PB1);
  33.  
  34.     while(1)
  35.     {
  36.         //zmiana stanu diody (po wciśnięciu klawisza 1)
  37.         if(!((PINB)&(1<<PB0)))
  38.         {
  39.            
  40.             _delay_ms(50);
  41.             //zmiana stanu PIN PA7
  42.             PORTA ^= diody_7;
  43.             //czy przycisk został puszczony
  44.             while(!((PINB)&(1<<PB0)))
  45.             {
  46.                 _delay_ms(50);
  47.             }
  48.         }
  49.         //przycisk 2 - 2 diody
  50.         if(!((PINB)&(1<<PB1)))
  51.         {
  52.             //czterokrotne wykonanie pętli
  53.             for(int i=0; i<4; i++)
  54.             {
  55.                 //dioda pierwsza
  56.                 for(int j=0; j<7; j++)
  57.                 {
  58.                     PORTA |= diody[j];
  59.                     _delay_ms(czas);
  60.                 }
  61.                 //dioda druga
  62.                 for(int j=1; j<8; j++)
  63.                 {
  64.                     PORTA &= ~(diody[j]);
  65.                     _delay_ms(czas);
  66.                 }
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement