hendriawan

Modul2-Percobaan 4- Basic Running LED dengan input

Mar 18th, 2019
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3. #define CW 0
  4. #define CCW 1
  5. int main (void) {
  6.     DDRA=0xFF;
  7.     DDRB &=~(1<<4);
  8.     PORTB |=(1<<4);
  9.     DDRH &=~(1<<4);
  10.     PORTH |=(1<<4);
  11.     PORTA=0xFF;
  12.     int arah=0;
  13.     while(1)
  14.     {
  15.         if (arah==CW) {
  16.             for(int i=0;i<=7;i++){
  17.                 PORTA &= ~(1<<i);
  18.                 _delay_ms(200);
  19.             }
  20.         } else if (arah==CCW){
  21.             for(int i=7;i>=0;i--){
  22.                 PORTA = ~(1<<i);
  23.                 _delay_ms(200);
  24.             }
  25.         }
  26.         if (!(PINB&(1<<4))) {
  27.             arah=CW;
  28.         } else if (!(PINH&(1<<4))) {
  29.             arah=CCW;
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment