Advertisement
marichan022

URS_K02G02Z02

Dec 3rd, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #define F_CPU 7372800UL
  2.  
  3. #include <avr/io.h>
  4. #include <util/delay.h>
  5.  
  6. uint8_t state = 1;
  7.  
  8. void blink(uint8_t cnt) {
  9.     if (cnt <= 3) {
  10.         PORTA = PORTA & ~_BV(4+cnt) & ~_BV(3-cnt);
  11.     } else {
  12.         cnt %= 4;
  13.         PORTA = PORTA | _BV(cnt) | _BV(7-cnt);
  14.     }
  15. }
  16.  
  17. int main() {
  18.     DDRA = 0xff;
  19.     PORTA = 0xff;
  20.  
  21.     DDRB = _BV(0) | _BV(1);
  22.     PORTB = _BV(0) | _BV(1);
  23.  
  24.     uint8_t cnt = 0;
  25.  
  26.     while (1) {
  27.         if(bit_is_clear(PINB, 0)) {
  28.             state = -1;
  29.         } else if (bit_is_clear(PINB, 1)) {
  30.             state = 1;
  31.         }
  32.  
  33.         if(state == 1) {
  34.             blink(cnt);
  35.             cnt = (cnt+1) % 8;
  36.         }
  37.         _delay_ms(200);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement