NEC ELECTRONICS GLOBAL
nec electronics global
HOME
APPLICATIONS
PRODUCTS
TECHNOLOGY
SUPPORT
BUY ONLINE
NEWS & EVENTS
ABOUT US
header
GO
AdvancedParametric
SITE MAP CONTACT US

Cautions Regarding Bit Manipulation

Contents

    
FAQ-ID = bit-nnnn
0001: Cautions regarding bit manipulation
0002: The data output before setting the port mode is ignored.
0003: uPD75P0016 port manipulation
bit
-0001
Cautions regarding bit manipulation
Q1
What are the common cautions regarding bit manipulation?
A1
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.
(1) Read data in 4-/8-bit units (the read length depends on the CPU).
(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.
Is this information useful for you ?
back to top  

bit
-0002
The data output before setting the port mode is ignored.
Q1
In order to prevent abnormal output when the port mode is set (I/O setting) as shown below, I set the port mode after writing the data of each bit to the port latch, but I get an output other than the intended one.

P2.3 = 0;
P2.2 = 1;
P2.1 = 0;
PM2 = 0xF1;

The output is as intended when I set each bit after first setting PM.
Are the data settings made before PM is set ignored?
A1
The problem is that data is set to the port output latch in bit units.
In this case, a bit manipulation instruction is used, resulting in the port data being read, bit manipulation being performed, and the result being written back.

If the port is in the input mode at this time, external pins are read and P2.2 is cleared upon execution of P2.1 = 0.
Is this information useful for you ?
back to top  

bit
-0003
uPD75P0016 port manipulation
Q1
When PORT22 is set to clock output, the clock is sometimes output and sometimes not when power is applied (about 50% probability).
However, when an oscilloscope probe is connected, the operation probability increases to 95% or more, although there are still times when the clock is not output.
The portions of the software that initializes the uPD75P0016 are shown below.
        MOV    A, #0011B
        MOV    PCC, A
        SET1    MBE
        SEL    MB15
        MOV    A, #0001B
        MOV    CLOM, A
        MOV    A, #0H
        MOV    PORT2, A
        MOV    PORT3, A
        SET1    P2.3
        MOV    PORT4, A
        MOV    PORT5, A
        MOV    PORT6, A
        MOV    PORT7, A
        MOV    XA, #10000100B
        MOV    PMGB, XA
        MOV    XA, #0
        MOV    PMGC, XA
A1
Manipulation of the 3rd bit of port 2 using the Set instruction is affecting the clock output.

Handling method:
Manipulate using the MOV instruction and not the SET1 instruction.
For example :

        MOV    A,#4H
        MOV    PORT2, A
Is this information useful for you ?
back to top  









































 LEGAL  RSS Feeds       © 1995-2008  NEC Electronics Corporation