
Arduino UNO schematic

GPIO 관련 Register

| 레지스터 및 어드레스 |
기능 |
리셋 되었을 때의 초기값 |
|---|---|---|
| DDR |
포트의 데이터 입출력 방향을 설정한다. 1:출력 0:입력
|
0000 0000 |
| PORT | DDR 레지스터에 의해서 방향이 출력으로 설정되어 있는 경우에 이 레지스터의 값이 핀에 나타난다. | 0000 0000 |
| PIN | DDR 레지스터에 의해서 방향이 입력으로 설정되어 있는 경우에 이 어드레스를 통해 핀의 논리를 읽을 수 있다. | 고 임피던스 |
blink.ino 다시쓰기
void setup()
{
DDRB = _BV(DDB5); // sets the digital pin 13(PB5) as output
// DDRB = B00100000;
}
void loop()
{
PORTB = 0; // sets the LED off
delay(1000); // waits for a second
PORTB = _BV(5); // sets the LED on
// PORTB = B00100000;
delay(1000); // waits for a second
}
digitalread.ino 다시쓰기
unsigned char val = 0; // variable to store the read value
void setup()
{
DDRB = _BV(DDB5); // sets the digital pin 13(PB5) as output
// DDRB = B00100000; // pin 11(PB3) as input
}
void loop()
{
val = PINB & _BV(3); // read the input pin
// val = PINB & B00001000;
PORTB = val << 2; // sets the LED to the button's value
}

