There are three PORT manipulation registers for your Arduino UNO> using the Port manipulation register, you can read the pin status faster, read multiple pins together. Wokwi Embedded Systems simulator enables you to simulate several boards such as Raspberry Pi Pico, ESP32, and more.
There are three registers
DDR
- Use this to tell whether the Pin is an INPUT or OUTPUTPORT
- Port pin registers whether the pin is a HIGH or a LOWPIN
- Use this to read the state of the pins which are defined as inputs
Some more info
PORTD maps to Arduino digital pins 0 to 7
DDRD - The Port D Data Direction Register - read/write
PORTD - The Port D Data Register - read/write
PIND - The Port D Input Pins Register - read only
PORTB maps to Arduino digital pins 8 to 13 The two high bits (6 & 7) map to the crystal pins and are not usable
DDRB - The Port B Data Direction Register - read/write
PORTB - The Port B Data Register - read/write
PINB - The Port B Input Pins Register - read only
PORTC maps to Arduino analog pins 0 to 5. Pins 6 & 7 are only accessible on the Arduino Mini
DDRC - The Port C Data Direction Register - read/write
PORTC - The Port C Data Register - read/write
PINC - The Port C Input Pins Register - read only
Let use see how to put these learnings into a useful project!
Project example 1 - PINDPIN register Port D (PIND)
Connection diagram
TheCode
/**
Arduino Uno PIND register demo
https://wokwi.com/arduino/projects/314168546236039745
Copyright (C) 2021, Uri Shaked.
*/
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
lcd.println("PIND value:");
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
}
int value = -1;
void loop() {
if (PIND != value) {
lcd.setCursor(6, 1);
lcd.print(PIND);
lcd.print(" ");
value = PIND;
}
}
Project link
https://wokwi.com/arduino/projects/314168546236039745
Project example 2 - PORTDPORT register Port D (PIND)
Connection diagram
Project Link:
https://wokwi.com/arduino/projects/314410577104470592
The code
/**
Arduino Uno PIND register demo
https://wokwi.com/arduino/projects/314168546236039745
Copyright (C) 2021, Uri Shaked.
*/
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
lcd.println("PORTD");
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
int value = -1;
void loop() {
PORTD = B10101010; // sets Arduino pins 1 to 7 as outputs, pin 0 as input
delay(1000);
PORTD = B01010101; // sets Arduino pins 1 to 7 as outputs, pin 0 as input
delay(1000);
}
The below article answers the following questions
- How to draw and connect using wires
- How to add a part in the Wokwi Simulator
- How to change wire colours
- How to delete a part on Wokwi
- How to move, rotate parts on the Wokwi Simulator and more
https://www.hackster.io/Hack-star-Arduino/how-to-use-wokwi-arduino-simulator-what-is-wokwi-304e6b
Support/feedback/suggestions?you have many ways to ask for help, suggest a feature or share your feedback
- Open an issue on GitHub
- Visit Facebook group
- Hop on to Discord Server!
- leave a comment here 😅
Comments