Unit 4
Unit 4
INTRODUCTION:
The 8051 is an 8-bit microcontroller with 8 bit data bus and 16-bit address bus.
The 16 bit address bus can address a 64K( 216) byte code memory space and a separate
64K byte of data memory space.
The 8051 has 4K on-chip read only code memory and 128 bytes of internal Random
AccessMemory(RAM)
Besides internal RAM, the 8051 has various Special Function Registers (SFR) such as
the Accumulator, the B register, and many other control registers.
34 8-bit general purpose registers in total.
The ALU performs one 8-bit operation at a time.
Two 16 bit /Counter timers
3 internal interrupts (one serial), 2 external interrupts.
Four 8-bit I/O ports
Some 8051 chips come with UART for serial communication and ADC for analog to
digital Conversion
Register
RS1 RS0 Address
bank
0 0 0 00H-07H
08H-
0 1 1
OFH
1 0 2 10H-17H
1 1 3 18H-1FH
Examples:
4. Register Indirect Addressing Mode
In this mode a register is used as a pointer to the data. If the data is inside the CPU, only
registers R0 and Rl are used for this purpose.
When R0 and Rl hold the addresses of RAM locations they must be preceded by the
"@" sign.
Examples:
MOV @ R1, A: Move content sof A into RAM location whose address is held by R1.
MOV B, @ R0: Move contents of RAM location whose address is held by R0into B.
INTERRUPTS
An interrupt is an internal or external event that interrupts the microcontroller to inform it
that a device needs its service. Whenever any device needs its service, the device notifies
the microcontroller by sending it as interrupt signal. Upon receiving an interrupt signal,
the microcontroller interrupts whatever it is doing and serves the device. The program
which is associated with the interrupt is called interrupt Service Routine (ISR). The
microcontroller can serve many devices based on the priority assigned to it.
Execution of an Interrupt
In order to use any interrupt, the following steps must be taken.
1. It finishes the instruction it is executing and saves the address of the next instruction
(PC) on the stack.
2. It also saves the current status of all the interrupts internally.
3. It jumps to a fixed location in memory called the interrupt vector or table that holds the
address of the Interrupt Service Routine (ISR).
4. The microcontroller gets the address of the ISR from the interrupt vector table and
jumps to it. It starts to execute the interrupt service subroutine until it reaches the last
instruction of the subroutine which is RET 1.
5. Upon executing RET 1 instruction, the microcontroller returns to the place where it
was interrupted. First it gets the program counter (PC) address from the stack by popping
the top two byes of the stack into the PC. Thenit startsto execute from that address.
Figure 8: IE Register
Figure 6: mode1
Mode2:Multiprocessor Mode
11-bits are transmitted through TXD or received through RXD.
it consists of one start bit(0),8 data bits, programmable 9thbit and a stop bit(1).
On transmission 9th data bit is 0/1, 8-bit is loaded into SBUF and copied from TB8 in
SCON register. On reception it goes into RB8 of SCON register of SFR.
Mode 3:
it is same as mode 2 except baud rate, since mode 3 supports variable baud rate and
calculated similar to mode1 using timer1.
Port 2 :
Port-2 has 8-pins (P2.0-P2.7)
Port-2 is used for higher external address byte or a normal input/output port.
The I/O operation is similar to Port-1. Port-2 latch remains stable when Port-2 pin are
used for
external memory access.
Here again due to internal pull-up there is limited current driving capability.
PORT 3:
Port-3 has 8 pin (P3.0-P3.7)
Port-3 pins have alternate functions.
Each pin of Port-3 can be individually programmed for I/O operation or for alternate
function.
The alternate function can be activated only if the corresponding latch has been written
to '1'.
To use the port as input port, '1' should be written
Alternate Functions of Port 3:
P3.0 and P3.1 are used for the RxD (Receive Data) and TxD (Transmit Data) serial
communications signals.
Bits P3.2 and P3.3 are meant for external interrupts.
Bits P3.4 and P3.5 are used for Timers 0 and 1 and P3.6 and P3.7 are used to provide
the write
and read signals of external memories connected in 8031 based systems
Memory Address Decoding
The processor can usually address a memory space that
is much larger than the memory space covered by an
individual memory chip.
Note that all three Enables (G2A, G2B, and G1) must be
active, e.g. low, low and high, respectively.
Each output of the decoder can be attached to an 2764
EPROM ( 8K X 8 ).
Memory Address Decoding
PLDs have been around since the mid-1970s but have only
recently appeared in memory systems (PALs have replaced
PROM address decoders).
Parity Checking:
o Parity checking is used to detect single bit errors in
the memory.
o The current trend is away from parity checking.
For EVEN parity, the 9th bit is set to yield an even number of 1's
in all 9 bits.
For ODD parity, the 9th bit is set to make this number odd.
0.
This circuit also checks EVEN or ODD parity for the 9-bit
number.
o In this case, the 9th input bit is connected to
Error Detection
This parity scheme can only detect a single bit error.
Block-Check Character ( BCC ) or Checksum.
o Can detect multiple bit errors.
checksum produces a 0.
o For example:
o This is not fool proof.
If 45 changes to 44 AND 04 changes to 05,
such as harddrives.
o Treats data as a stream of serial data n-bits long.
Error Detection
not corrected .
o Error correction will of course cost more in terms of
extra bits.
are powers of 2 .
Error Correction
Hamming Codes (cont).
o P1 is generated by computing the parity of X 3 ,
X 5 , X 7 , X 9 , X 11 , X 13 , X 15 .
o These numbers have a 1 in bit position 1 of the
subscript in binary.
Error Correction
Hamming Codes (cont).