Mes Unit1
Mes Unit1
3. OV: the overflow flag This flag is set whenever the result of a signed number operation is
too large, causing the high-order bit to overflow into the sign bit. In general, the carry flag is
used to detect errors in unsigned arithmetic operations. The overflow flag is only used to detect
errors in signed arithmetic operations.
4. P: Parity flag: The parity flag reflects the number of 1s in the A (accumulator) register only.
If the A register contains an odd number of 1’s, then P=1, P=0 if A has an even number of 1’
Q.5. Draw the format of TCON SFR and explain each bit.
Timer Control or TCON Register in 8051 Microcontroller is used to start or stop the Timers.
It also contains bits to indicate if the Timers has overflowed. The TCON SFR also consists of
Interrupt related bits.
The following table gives the explanation of each bit in the TCON Register in 8051.
Q.6. Describe the function of following pins of 8051 microcontroller. (i)PSEN (ii)EA
(iii)ALE (iv)RESET
(i)PSEN 1.PSEN (program store enable). PSEN is the read strobe for external Program
Memory. In an 8031-based system in which an external ROM holds the program code, this pin
is connected to the OE pin of the ROM. PSEN is not activated for internal fetches.
(ii)EA 1. EA (external access).EA is pin number 31 in the DIP packages. It is an input pin and
must be connected to either Vcc or GND. It cannot be left unconnected. 2. The lowest 4K bytes
of Program Memory can be either in the on-chip ROM or in an external ROM. This selection
is made by connecting EA pin. 1. If the pin is connected to Vcc, then addresses 0000H through
0FFFH are directed to the internal ROM and addresses 1000H through FFFFH are directed to
external ROM. 2. If the pin is connected to Vss, then all address are directed to external ROM.
(iii)ALE ALE (Address latch enable). It is an output pin and is active high for latching the low
byte of address during accesses to external memory. The ALE pin is used for de-multiplexing
the address and data by connecting to the STB pin of the 74LS373 chip.
(iv)RESET Pin 9 is the Reset Input Pin. This is used for resetting the microcontroller to its
initial values. If the pin is set at logic 0, the chip runs normally. When the oscillator is running,
setting the pin at logic 1 for more than two machine cycles will reset the microcontroller.
Q.7. Draw the format of PCON register and explain function of each bit.
IDLE MODE
In the Idle mode, the internal clock signal is gated off to the CPU, but not to the Interrupt, Timer, and
Serial Port functions.
The CPU status is preserved in its entirety, the Stack Pointer, Program Counter, Program Status Word,
Accumulator, and all other registers maintain their data during Idle. The port pins hold the logical state
they had at the time idle mode was activated. ALE and PSEN hold at logic high levels.
There are two ways to terminate the idle mode.
i) Activation of any enabled interrupt will cause PCON.O to be cleared and idle mode is terminated.
ii) Hard ware reset: that is signal at RST pin clears IDEAL bit IN PCON register directly. At this time,
CPU resumes the program execution from where it left off.
POWER DOWN MODE
An instruction that sets PCON.1 causes that to be the last instruction executed before going into the
Power Down mode. In the Power Down mode, the on-chip oscillator is stopped. With the clock frozen,
all functions are stopped, but the on-chip RAM and Special Function Register are maintained held. The
port pins output the values held by their respective SFRS. ALE and PSEN are held low.
Termination from power down mode: an exit from this mode is hardware reset.
Reset defines all SFRs but doesn’t change on chip RAM.
A or Accumulator (ACC)
The Accumulator or Register A is the most important and most used 8051 Microcontroller SFRs. The
Register A is located at the address E0H in the SFR memory space. The Accumulator is used to hold
the data for almost all the ALU Operations.
The name “Accumulator” came from the fact this register is used to accumulate (or store) the result of
all Arithmetic and most of the Logical Operations.
B (Register B)
The B Register is used along with the ACC in Multiplication and Division operations. These
two operations are performed on data that are stored only in Registers A and B. During
Multiplication Operation, one of the operand (multiplier or multiplicand) is stores in B
Register and also the higher byte of the result.
In case of Division Operation, the B Register holds the divisor and also the remainder of the
result. It can also be used as a General Purpose Register for normal operations and is often
used as an Auxiliary Register by Programmers to store temporary results.Register B is
located at the address F0H of the SFR Address Space.
Pointer Registers
Data Pointer (DPTR – DPL and DPH)
The Data Pointer is a 16-bit Register and is physically the combination of DPL (Data Pointer
Low) and DPH (Data Pointer High) SFRs. The Data Pointer can be used as a single 16-bit
register (as DPTR) or two 8-bit registers (as DPL and DPH).
DPTR doesn’t have a physical Memory Address but the DPL (Lower Byte of DPTR) and
DPH (Higher Byte of DPTR) have separate addresses in the SFR Memory Space. DPL = 82H
and DPH = 83H.
The DPTR Register is used by the programmer addressing external memory (Program –
ROM or Data – RAM).
When writing a new data byte into the stack, the SP (Stack Pointer) is automatically
incremented by 1 and the new data is written at an address SP+1. When reading data from
stack, the data is retrieved from the Address in SP and after that the SP is decremented by 1
(SP-1).