2016년 4월 18일 월요일

sw1.c

// sw1.c
// switch input test
// PD(port D) : SW7,6,5,4 LED3,2,1,0

#include <avr/io.h>
#include <util/delay.h>

int main(void) {
unsigned char led;
DDRD = 0x0f; // 0000:input, 1111:output

while(1) {
led = PIND | 0x0f; // 1111 1111 : light off
if(led != 0xff) { // if switch pressed,
led >>= 4;
led |= 0xf0;
PORTD = led; // LED on concerning sw pressed,
}
else // if switch not pressed,
PORTD = 0xff; // led off

_delay_ms(100);
}

return(0);

}

댓글 없음:

댓글 쓰기