Sie sind auf Seite 1von 17

8051 Microcontroller :

 8-bit microcontroller

Block Diagram of 8051 µC Pin configuration of 8051 µC


Features of 8051 µC:
8-bit CPU with register A and B.

16-bit Program Counter (PC) and Data Pointer(DPTR).

8-bit Program Status Word (PSW).

8-bit Stack Pointer (SP)

Internal ROM of 4K.

Internal RAM 128 bytes.

4 ports having in total of 32 input/output lines

Two 16-bit Timer and Counter : T0 and T1.

Serial Data Communication.

Two external and three Internal Interrupt Sources.

Oscillator & Clock Circuits.


Memory Organization:
 128 byte RAM

4 bank (Bank 0, Bank 1, Bank 2, Bank 3)


 each have 8 register named R0-R7
 R register is 8- bit means 1 byte or one
location
 Bank 0- from 00 address to 07 address
R0 register in Bank 0 , byte address is 00
 R7 register in Bank 0 , byte address is 07
Bank 1- from 08 address to 0Faddress
Bank 2- from 10 address to17 address
Bank 3- from 18 address to 1F address

Next 16 location or byte from 20 to 2F are


bit addressable means each bit in byte is
access.

Remaining 80 location or byte are used for


general purpose register.
Program Status Word (PSW) Register

Parity bit:If a number stored in the accumulator is even then this bit will be
automatically set (1), otherwise it will be cleared (0). It is mainly used during
data transmit and receive via serial

Bit 1: This bit is reserve for future use.

OV- Overflow bit: Overflow occurs set to 1 Otherwise, it will be cleared (0).

 When the result of an arithmetical operation is larger than 255 then overflow
occurs.
In 8-bit signed number operations, OV is set if either of following condition
occurs:
1> There is a carry from D6 bit to D7 bit but no carry out of D7 bit.
2> There is a carry from D7 out but no carry from D6 bit to D7 bit.
RS0, RS1 :Register bank select bits.

RS1 RS0 Bank selected


0 0 Bank0
0 1 Bank1
1 0 Bank2
1 1 Bank3

F0: Flag 0. This is a general-purpose bit available for use.

AC : Auxiliary Carry Flag is used for BCD operations only. If there is a carry from
D3 to D4 during ADD or SUBB operation, this bit is set; otherwise it is cleared.

CY: Carry Flag is the (ninth) auxiliary bit used for all arithmetical operations and
shift instructions. This flag is set when there is a carry out of D7 bit. This flag bit is
affected after 8-bit addition or subtraction.

The Value of register PSW after reset is 00H.


Counters and Timers:

The 8051 microcontroller has two 16-bit timers/counters called T0 and T1.

As their names suggest, timer counts internal clock pulse i.e. machine cycle to
provide delay .
Counter counts external clock pulse i.e to count external events.

Besides, they can be used for generating clock pulses to be used in serial
communication, so called Baud Rate.

Each timer consists of two 8-bit registers – THX and TLX representing a low
and a high byte of one 16-digit binary number.
TMOD Register (Timer Mode)

 Lower nibble is for To timer and higher nibble is for T1 timer.


GATE bit: enables and disables Timer TX
When GATE=0 ,Timer start and stop is controlled by software using timer
control bit TR0 and TR1.
When GATE=1 Timer start and stop is controlled by hardware using
external signal at pin 12(INT0) and pin 13 (INT1).

C/T: as timer or counter


If set to 1 - Timer counts pulses brought to the T1 pin (P3.5). Simply it works
as counter.
If reset (0) - Timer counts pulses from internal oscillator.
TM1,TM0: These two bits select the operational mode of the Timer .

TM1 TM0 Mode Description


0 0 Mode0 13- bit
0 1 Mode 1 16- bit
1 0 Mode 2 8-bit auto reload
1 1 Mode 3 spilt mode
Timer Control (TCON) Register

TFx: bit is automatically set on the Timer TX overflow.


TRX: bit enables the Timer TX.
If bit is 1 - Timer TX is enabled.
If bit is 0 - Timer TX is disabled.
IEX: External Interrupt flag bit:
This bit is set to 1 when a high to low level edge signal is received on EXT
INT pins. And start execution of Interrupt Service Routine (ISR). After complete
execution ISR, this bit is cleared automatically and indicate interrupt is finished.
EXT INT 1 : port 3 pin 3.3(13)
EXT INT 0 : port 3 pin 3.2(12)
ITX: External Interrupt control bit:
There are two activation level external Interrupt as level triggered and edge
triggered. This bit determines mode of activation.
When ITX is 0 then external INTX is level triggered.
When ITX is 1 then external INTX is edge triggered means for high to
low transition.
UART (Universal Asynchronous Receiver and Transmitter):

serial port.

It is a full-duplex port, thus being able to transmit and receive data
simultaneously and at different baud rates

In serial data communication, baud rate is important factor. The baud rate is
reciprocal of the time to send 1-bit. Baud rate need not be equal to no. of bits per
seconds, because each byte is preceded by a start bit and followed by stop bit. The
date byte is always transmitted with LSB first

Serial communication uses a 8-bit special function register SBUF to hold data. To
transmit serial data via Txd line, it must be placed in SBUF and is nothing but
writing to the SBUF register. While to receive data via Rxd line, SBUF hold the
received byte and is nothing but reading the same register
Serial Port Control (SCON) Register:

SM0 - Serial port mode bit 0 is used for serial port mode selection.
SM1 - Serial port mode bit 1.
SM2 - Serial port mode 2 bit, also known as multiprocessor communication enable bit.
When set, it enables multiprocessor communication in mode 2 and 3, and eventually
mode 1. It should be cleared in mode 0.
REN – Receive Enable bit. This bit enables serial reception when set. When cleared,
serial reception is disabled.
TB8 - Transmitter bit 8. Since all registers are 8-bit wide, this bit solves the problem of
transmitting the 9th bit in modes 2 and 3. It is set to transmit a logic 1 in the 9th bit.
RB8 - Receiver bit 8 or the 9th bit received in modes 2 and 3. Cleared by hardware if
9th bit received is a logic 0. Set by hardware if 9th bit received is a logic 1.
TI - Transmit Interrupt flag is automatically set at the moment the last bit of one byte
is sent. It's a signal to the processor that the line is available for a new byte transmit. It
must be cleared from within the software.
RI - Receive Interrupt flag is automatically set upon one byte receive. It signals that
byte is received and should be read quickly prior to being replaced by a new data. This
bit is also cleared from within the software.
IE Register (Interrupt Enable)

EA - global interrupt enable/disable:


0 - disables all interrupt requests.
1 - enables all individual interrupt requests.
Bit 6 is not implemented.

ET2: Reserve for future use.

ES - enables or disables serial interrupt:


0 - UART system cannot generate an interrupt.
1 - UART system enables an interrupt.
IE Register (Interrupt Enable)

ET1 - bit enables or disables Timer 1 interrupt:


0 - Timer 1 cannot generate an interrupt.
1 - Timer 1 enables an interrupt.

EX1 - bit enables or disables external 1 interrupt:


0 - change of the pin INT0 logic state cannot generate an interrupt.
1 - enables an external interrupt on the pin INT0 state change.

ET0 - bit enables or disables timer 0 interrupt:


0 - Timer 0 cannot generate an interrupt.
1 - enables timer 0 interrupt.

EX0 - bit enables or disables external 0 interrupt:


0 - change of the INT1 pin logic state cannot generate an interrupt.
1 - enables an external interrupt on the pin INT1 state change.
IP Register (Interrupt Priority)

If an interrupt of higher priority arrives while an interrupt is


in progress, it will be immediately stopped and the higher
priority interrupt will be executed first.

 If two interrupt requests of equal priority arrive at the same


time then the interrupt to be serviced is selected according to
the following priority list:

External interrupt INT0


Timer 0 interrupt
External Interrupt INT1
Timer 1 interrupt
Serial Communication Interrupt
PS - Serial Port Interrupt priority bit
PT1 - Timer 1 interrupt priority
PX1 - External Interrupt INT1 priority
PT0 - Timer 0 Interrupt Priority
PX0 - External Interrupt INT0 Priority
PCON register

SMOD: Baud rate is twice as much higher by setting this bit.

GF1 :General-purpose bit (available for use).

GF1 :General-purpose bit (available for use).

GF0 :General-purpose bit (available for use).

PD: By setting this bit the microcontroller enters the Power Down mode.

IDL: By setting this bit the microcontroller enters the Idle mode.