Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.51 KB | None | 0 0
  1. #define F_CPU 1000000L
  2.  
  3. #include <avr/io.h>
  4. #include <util/delay.h>
  5.  
  6. #define LED0 (1<<0)
  7. #define LED1 (1<<PA1)
  8. #define LED2 (1<<PA2)
  9. #define LED3 (1<<PA3)
  10. #define LED4 (1<<PA4)
  11. #define LED5 (1<<PA5)
  12. #define LED6 (1<<PA6)
  13. #define LED7 (1<<PA7)
  14.  
  15.  
  16. int main(void){
  17.     DDRA |= LED0 | LED1 | LED2 | LED3 | LED4 | LED5 | LED6 | LED7;
  18.    
  19.     uint8_t phase = 0;
  20.     uint8_t dir = 0;
  21.     while(1){
  22.        
  23.         switch(phase){
  24.             case 0:{
  25.                 PORTA |= LED0 | LED1;
  26.                 PORTA &= ~(LED2 | LED3);   
  27.                 if(dir==0) {phase += 1; _delay_ms(1000);}
  28.                 else {dir = 0;}
  29.                 break;
  30.             }
  31.             case 1:{
  32.                 PORTA |= LED2 | LED3;
  33.                 PORTA &= ~(LED0 | LED1);
  34.                 PORTA &= ~(LED4 | LED5);
  35.                 if(dir==0) {phase += 1; _delay_ms(1000);}
  36.                 else {phase -= 1; _delay_ms(1000);}
  37.                 break;
  38.             }
  39.             case 2:{
  40.                 PORTA |= LED4 | LED5;
  41.                 PORTA &= ~(LED6 | LED7);
  42.                 PORTA &= ~(LED2 | LED3);
  43.                 if(dir==0) {phase += 1; _delay_ms(1000);}
  44.                 else {phase -= 1; _delay_ms(1000);}
  45.                 break;
  46.             }
  47.             case 3:{
  48.                 PORTA |= LED6 | LED7;
  49.                 PORTA &= ~(LED4 | LED5);
  50.                 if(dir==0) {dir = 1;}
  51.                 else {phase -= 1; _delay_ms(1000);}
  52.                 break;
  53.             }
  54.        
  55.        
  56.         }
  57.        
  58.        
  59.         //PORTA |= LED0 | LED1 | LED2 | LED3 | LED4 | LED5 | LED6 | LED7;
  60. //
  61. //      _delay_ms(1000);
  62. //
  63. //      PORTA &= ~(LED0 | LED1 | LED2 | LED3 | LED4 | LED5 | LED6 | LED7);
  64. //
  65. //      _delay_ms(1000);
  66.  
  67.        
  68.         //if(!(PINA&LED0)){
  69.         //  _delay_ms(50);
  70.         //  if((PINA&LED0)){
  71.         //      PORTA |= LED0;
  72.         //      _delay_ms(80);
  73.         //      PORTA &= ~LED0;
  74.         //      _delay_ms(80);
  75.         //  }
  76.         //}
  77.     }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement