I am new to programming with the Arduino Due, and I have been tasked with updating some code from a previous project. I wish to set the first eight bits of port C to output and then write 0x04 to those corresponding bits. I have seen similar posts to this, but I haven't seen any answers that write data to a certain number of bits on a port.
I have written:
DDRC = b11111111
PORTC = 0x04
I am confident that the first line achieves what I want (setting the first eight bits of port C to output). I believe the statement in the second step writes 0x04 to all of the bits that are in port c, but I wish to only write 0x04 to the first eight bits of port C. Any suggestions as to how to do this?
Here's an Arduino Due example writing to the first 4 bits of PORTD:
void setup() {
PIOD->PIO_OWER = 0xFFFFFFFF; // Enable writes to whole of PortD's 32-bit, Output Data Status (ODSR) register: (B11111111111111111111111111111111)
PIOD->PIO_OER = 0x0000000F; // Set the lowest 4-bits of PortD to outputs: (B00000000000000000000000000001111)
}
void loop() {
PIOD->PIO_ODSR = PIO_ODSR_P0; // Set the output on P0 (digital pin 25) high, other outputs low: (B00000000000000000000000000000001)
PIOD->PIO_ODSR = PIO_ODSR_P1; // Set the output on P1 (digital pin 26) high, other outputs low: (B00000000000000000000000000000010)
PIOD->PIO_ODSR = PIO_ODSR_P2; // Set the output on P2 (digital pin 27) high, other outputs low: (B00000000000000000000000000000100)
PIOD->PIO_ODSR = PIO_ODSR_P3; // Set the output on P3 (digital pin 28) high, other outputs low: (B00000000000000000000000000001000)
}