Introduction
GPIO port-wide operations let you control many pins on a port at once, making it faster and easier to set or read multiple pins together.
GPIO_PORT = value; // Write value to all pins on the port
value = GPIO_PORT; // Read value from all pins on the portGPIO_PORT = 0xFF; // Set all pins on the port to HIGHuint8_t portValue = GPIO_PORT; // Read all pins on the port
GPIO_PORT &= ~0x0F; // Clear lower 4 pins on the port
GPIO_PORT |= 0xA0; // Set pins 5 and 7 to HIGH
#include <stdint.h> #include <stdio.h> // Simulate GPIO port register uint8_t GPIO_PORT = 0; int main() { // Set all pins high GPIO_PORT = 0xFF; printf("All pins set: 0x%02X\n", GPIO_PORT); // Clear pins 0-3 GPIO_PORT &= ~0x0F; printf("Lower 4 pins cleared: 0x%02X\n", GPIO_PORT); // Set pins 5 and 7 GPIO_PORT |= 0xA0; printf("Pins 5 and 7 set: 0x%02X\n", GPIO_PORT); // Read port value uint8_t portValue = GPIO_PORT; printf("Read port value: 0x%02X\n", portValue); return 0; }
PORTB in embedded C typically do in GPIO port-wide operations?DDRC = 0x00;
PORTC = 0xFF;
uint8_t val = PINC;
val assuming all pins on port C are externally connected to ground?DDRA = 0xFF;
PINA = 0xFF;
Pass the test and this pattern moves unknown