Set/Reset/ LatchBits

I have 32-bit MCU. The port uses 32 digital IO functionality.

I am looking for a sample code to Latch a particular bit/particular pin in PORTA Set/RESET function particular bit In port A.

Can someone guide me on how it can be done using AND/OR/XOR operation?

digitalRead() will capture the state of the pin when read

I assume you have some reason for not using the digitalRead() and digitalWrite() functions.

To set a bit first read the register (using the proper built-in) then OR the bit you want set with the value you read and then write the register back. To clear a bit AND in the complement of the bit you want to clear.

See

  Arduino direct port manipulation

with your favorite search engine.

byte thePort = PORTA;

then

 PORTA = bitSet(thePort, 3);

or

PORTA = bitClear(thePort, 3);

will turn on or off bit 3 of the port.

Which must be an output pin to be seen, obvsly I hope.

You could go out and learn how to do it as @oldcurmudgeon says, it is worth knowing that kind of bit operating don't rely on some fancy functions that do the same thing.

a7

Which 32 bit CPU?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.