hendriawan

Modul2-Percobaan 3- Basic input

Mar 18th, 2019
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.33 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3. int main (void) {
  4.     DDRA=0xFF;
  5.     DDRB &=(1<<4);
  6.     PORTB |=(1<<4);
  7.     PORTA=0xFF;
  8.     while(1)
  9.     {
  10.         if (!(PINB&(1<<4))) {
  11.             for(int i=0;i<=7;i++){
  12.                 PORTA = ~(1<<i);
  13.                 _delay_ms(500);
  14.             }
  15.         } else {
  16.             for(int i=7;i>=0;i--){
  17.                 PORTA = ~(1<<i);
  18.                 _delay_ms(500);
  19.             }
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment