Advertisement
Aditor

Untitled

Nov 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.45 KB | None | 0 0
  1. #define F_CPU 1000000L
  2. #include <avr/io.h>
  3. #include <util/delay.h>
  4.  
  5.  
  6. #define SW (1<<PB0)
  7. #define PWM1 (1<<PB1)
  8. #define PWM2 (1<<PB2)
  9. #define PWM3 (1<<PB3)
  10. #define A (1<<PB4)
  11. #define B (1<<PB5)
  12.  
  13. /* STAN NISKI */
  14.  
  15. #define PWM1L (0<<PB1)
  16. #define PWM2L (0<<PB2)
  17. #define PWM3L (0<<PB3)
  18.  
  19. /* http://eduinf.waw.pl/inf/prg/009_kurs_avr_old/0026.php */
  20. int ilosc; /* ZMIENNA LICZNIKA */
  21.  
  22. int main(void) {
  23.  
  24.  
  25.  
  26.     /* PINY */
  27.  
  28.     DDRB = PWM1 | PWM1L | A | B; // Wyjscie pin 1,
  29.     PORTB = SW;  // Wyjścia podciągniete 1 pod VCC = SW
  30.     PINB = SW; // Wejscie pin 0.
  31.  
  32.     /* TIMERY */
  33.  
  34.     TCCR0A = (1 << COM0B1) | (1 << COM0B0) | (1 << WGM01) | (1 << WGM00);
  35.     TCCR0B = (1 << CS00);
  36.     /* rejestr zegara ustawiony na częstotliwośc taktowania */
  37.     OCR0B = (255); /* Maksymalna jasność diody D1 */
  38.  
  39.  
  40.  
  41.     while(1)
  42.     {
  43.  
  44.         if (!(PINB & SW)) /*Jesli pin 0 wcisniety*/
  45.         {
  46.  
  47.             int ilosc;++ /* DODAJ +1 DO LICZNIKA */
  48.  
  49.             _delay_ms(80); /* DRGANIE STYKÓW */
  50.  
  51.             while (!(PINB & SW)) {
  52.            
  53.  
  54.             _delay_ms(80); /* DRGANIE STYKÓW */
  55.                
  56.         }
  57. }
  58.  
  59.         switch (ilosc) {
  60.  
  61.             case 5:
  62.             /*Jesiilosc jest maks (5) zeruj ją. */
  63.  
  64.             int ilosc = 0;
  65.  
  66.             break;
  67.  
  68.             case 1:
  69.             /* instrukcje, jeśli ilosc = 1 */
  70.  
  71.             /* MIGANIE DIODAMI */
  72.  
  73.             while (ilosc == 1) {
  74.  
  75.                 /* STANY ZERO NA 4,5 PINIE MUX PRZEŁĄCZA NA Y/X0 */
  76.  
  77.                 PORTB = (PWM1);
  78.                 _delay_ms(1000);
  79.                 PORTB = (PWM1L);
  80.             }
  81.  
  82.             break;
  83.  
  84.             case 2:
  85.             /* instrukcje, jeśli ilosc = 2 */
  86.  
  87.             /* ZAPALENIE DIODY  ORAZ STAN WYSOKI NA WEJSCIU A MUX (PB4)  */
  88.  
  89.             PORTB = (A); /* MUX WYJSCIE Y1*/
  90.  
  91.             while (ilosc == 2) {
  92.  
  93.                 PORTB = (PWM1);
  94.  
  95.             }
  96.  
  97.             break;
  98.  
  99.             case 3:
  100.  
  101.             PORTB = (B); /* MUX WYJSCIE Y2 */
  102.  
  103.             while (ilosc == 3) {
  104.  
  105.                 PORTB = (PWM1);
  106.                 _delay_ms(1000);
  107.                 PORTB = (PWM1L);
  108.                 _delay_ms(1000);
  109.                 PORTB = (PWM1);
  110.                 _delay_ms(1000);
  111.                 PORTB = (PWM1L);
  112.                 _delay_ms(5000);
  113.                 PORTB = (PWM1);
  114.                 _delay_ms(1000);
  115.                 PORTB = (PWM1L);
  116.                 _delay_ms(1000);
  117.                 PORTB = (PWM1);
  118.                 _delay_ms(1000);
  119.                 PORTB = (PWM1L);
  120.  
  121.             }
  122.            
  123.             break;
  124.  
  125.             case 4:
  126.             /* instrukcje, jeśli ilosc = 4 */
  127.  
  128.             /* zmiana kolorów diod */
  129.  
  130.             PORTB = (A); /* MUX */
  131.  
  132.             while (ilosc == 4) {
  133.  
  134.                 PORTB = (PWM1);
  135.                 _delay_ms(1000);
  136.                 PORTB = (PWM1L);
  137.                 PORTB = (PWM2);
  138.                 _delay_ms(1000);
  139.                 PORTB = (PWM2L);
  140.                 PORTB = (PWM3);
  141.                 _delay_ms(1000);
  142.                 PORTB = (PWM3L);
  143.             }
  144.  
  145.             default :
  146.             _delay_ms(10);
  147.            
  148.             break;
  149.         }
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement