The following are common cautions applicable from the 4-bit 75X Series to the 32-bit V850 Series.
- Bit manipulation instructions
- Bit manipulation to port
Microcontroller bit manipulation is not realized with dedicated hardware, but via read-modify-write.
The operation is as follows.
(2) Set/reset the target bits of the read data.
(3) Write back the bit-processed data in 4-/8-bit units.
During normal program processing, there is no particular need to be aware of anything, but when bit-manipulating hardware such as ports, caution is required.
With the exception of some devices, in order to enable bit manipulation for ports, the circuit configuration is such that the output latch data is read when using the port as an output, and the external pin status is read when using the port as an input.
For example, let us assume that we have an 8-bit I/O port P20 to P27.
This port is always accessed in 8-bit units.
When bit-manipulating this port, 8 bits of data are read.
At this time, the output latch data is read in the case of a bit specified as output, and the pin status is read in the case of a bit specified as input.
Data can therefore be read in combinations whereby each bit is read from a different location.
The target bits in this data are manipulated and the result is written back in 8 bits to the output latch.
In other words, the external pin status is written to the output latch of ports specified as input ports.
Therefore, caution is required regarding ports that are specified as input.
As shown in the following question examples, bit manipulation of ports that have not been specified as output may have an unexpected effect on bits other than the target bits, so caution is required.