You are on page 1of 46

Micro-Controllers And

Interfacing(MCI)

Unit-IV
Presented by
R. Padmasree
Assistant Prof.
Department of ECE
8051 Pin configuration
Pin 1 to Pin 8 (Port 1) – Pin 1 to Pin 8 are assigned to Port 1 for simple
I/O operations. They can be configured as input or output pins depending
on the logic control i.e. if logic zero (0) is applied to the I/O port it will
act as an output pin and if logic one (1) is applied the pin will act as an
input pin. These are bidirectional pins.
Pin 9 (RST) – Reset pin. It is an active-high-input pin,the
microcontroller will reset i.e. it will close and terminate all activities.
Pin 10 to Pin 17 (Port 3) – Pin 10 to pin 17 are port 3 pins which are
also referred to as P3.0 to P3.7. These pins can be used as universal input
or output pins. These pins are bidirectional pins. These pins also have
some additional functions which are as follows:
P3.0 (RXD) : 10th pin is RXD (serial data receive pin) which is for
serial input. Through this input signal microcontroller receives data for
serial communication
P3.1 (TXD) : 11th pin is TXD (serial data transmit pin) which is serial
output pin. Through this output signal microcontroller transmits data for
serial communication.
P3.2 and P3.3 (INT0′, INT1′ ) : 12th and 13th pins are for External
Hardware Interrupt 0 and Interrupt 1 respectively. When this interrupt is
activated(i.e. when it is low), 8051 gets interrupted in whatever it is doing
and jumps to the vector value of the interrupt (0003H for INT0 and
0013H for INT1) and starts performing Interrupt Service Routine (ISR)
from that vector location.
P3.4 and P3.5 (T0 and T1) : 14th and 15th pin are for Timer 0 and Timer
1 external input. They can be connected with 16 bit timer/counter.
P3.6 (WR’) : 16th pin is for external memory write i.e. writing data to the
external memory.
P3.7 (RD’) : 17th pin is for external memory read i.e. reading data from
Pin 18 and Pin 19 (XTAL2 And XTAL1) – These pins are connected to
an external oscillator which is generally a quartz crystal oscillator. They
are used to provide an external clock frequency of 4MHz to 30MHz.
Pin 20 (GND) – This pin is connected to the ground. It has to be
provided with 0V power supply. Hence it is connected to the negative
terminal of the power supply.
Pin 21 to Pin 28 (Port 2) – Pin 21 to pin 28 are port 2 pins also referred
to as P2.0 to P2.7. When additional external memory is interfaced with
the 8051 microcontroller, pins of port 2 act as higher-order address bytes.
These pins are bidirectional.
Pin 29 (PSEN) – PSEN stands for Program Store Enable. It is output,
active-low pin. This is used to read external memory. In 8031 based
system where external ROM holds the program code, this pin is
connected to the OE pin of the ROM.
Pin 30 (ALE/ PROG) – ALE stands for Address Latch Enable. It is input,
active-high pin. This pin is used to distinguish between memory chips when
multiple memory chips are used. It is also used to de-multiplex the multiplexed
address and data signals available at port 0.
Pin 31 (EA/ VPP) – EA stands for External Access input. It is used to
enable/disable external memory interfacing. In 8051, EA is connected to Vcc as
it comes with on-chip ROM to store programs. For other family members such
as 8031 and 8032 in which there is no on-chip ROM, the EA pin is connected to
the GND.
Pin 32 to Pin 39 (Port 0) – Pin 32 to pin 39 are port 0 pins also referred to as
P0.0 to P0.7. They are bidirectional input/output pins. They don’t have any
internal pull-ups. Hence, 10 K? pull-up registers are used as external pull-ups.
Port 0 is also designated as AD0-AD7 because 8051 multiplexes address and
data through port 0 to save pins.
Pin 40 (VCC) – This pin provides power supply voltage i.e. +5 Volts to the
Architecture of 8051
Accumulator (Register A*): It is an 8-bit register used for many
operations including addition, subtraction, multiplication, division, and
Boolean bit manipulations. This is also used for all data transfers
between 8051 and any external memory. It can also be used as a general
purpose register. The results obtained from arithmetic and logical
instructions are always stored in Accumulator.

Register B: It is an 8-bit register specially used for direct multiplication


and division operation with Accumulator. Both A and B registers are
called math registers in 8051 family.

Arithmetic and Logic unit(ALU): It is used to perform 8-bit arithmetic


and logical operations.
Program/processor status word(PSW):-

RS1 RS0 Bank Select


0 0 Bank – 0
0 1 Bank – 1
1 0 Bank – 2
1 1 Bank – 3
Data pointer (DPTR): It is a 16-bit register used to hold the address of
internal or external data as well as code memory. This is the only register
used to access data from 16-bit external memory. It can be used as two 8-bit
registers namely DPH (Data Pointers High) and DPL (Data Pointer Low).
Program Counter (PC): It is a 16-bit register, which holds the address of
the next instruction to be executed. It is also called as Instruction Pointer
(IP) and it is not directly accessible to the programmer. PC is automatically
incremented after every instruction and may be altered by certain program
control instructions.
Special Function Registers (SFR’s):
SFR’s are a group of registers used for specific purposes in 8051 controller,
mainly to configure, control and operate. Each SFR is an 8-bit register,
which uses address locations from 80H to FFH, All SFR’s are discussed
below:
,
Interrupt Enable(IE) register
Interrupt Priority(IP) register
Using IP register it is possible to change the priority levels of an interrupts by
clearing or setting the individual bit in the Interrupt priority (IP) register as shown
below:
Timer Mode(TMOD) Register

To enable timer-1/0 Counter or Timer selection

M1 M0 Mode selection
0 0 Mode-0
0 1 Mode-1
1 0 Mode-2
1 1 Mode-3
Timer Control(TCON) Register
Serial Control(SCON) register
Power Control(PCON) register
TIMER MODES

• Mode 0: This is a 13-bit timer mode


It uses 5 bits of TL0 or TL1 and all of the 8-bits of TH0
or TH1 that means the timer operation completes with
“8192” pulses.
• Mode 1: This is a16-bit timer mode,
It uses 8 bits of TL0 or TL1 and 8-bits of TH0 or
TH1,which means the timer operation completes with
maximum clock pulses that “65535”.
• Mode 2: This mode is an 8-bit auto reload mode
Both the timer registers are configured as 8-bit
timers/counters (TL1 and TL0) with automatic reload and the
timer operation completes with only “256” clock pulses.
• Mode 3: Timer mode "3" is known as split-timer mode.
When Timer 0 is placed in mode 3, it becomes two separate
8-bit timers.
.
Serial Data Modes
8051 micro controller communicate with another peripheral device
through RXD and TXD pin of port3.controller have four mode of serial
communication. This four mode of serial communication are below.
1. Serial data mode 0 - fixed baud Rate.
2. Serial data mode 1 - variable baud rate.
3. Serial data mode 2 - fixed baud Rate.
4. Serial Data mode 3 - variable baud rate.

The Baud rate, on the other hand, refers to the amount of signal unit
transmissions in a second
Bit Rate = Total number of Bits per Baud x Baud
Rate
Serial data mode-0
• In this mode, the serial port works like a shift register and the data transmission
works synchronously with a clock frequency of fosc /12.
• Serial data is received and transmitted through RXD. 8 bits are transmitted/
received at a time.
• The shift frequency or baud rate is always 1/12 of the oscillator frequency.
Serial data mode-1
• In mode-1, the serial port functions as a standard Universal Asynchronous Receiver
Transmitter (UART) mode. 10 bits are transmitted through TXD or received
through RXD.
• The 10 bits consist of one start bit (which is usually '0'), 8 data bits (LSB is sent
first/received first), and a stop bit (which is usually '1'). Once received, the stop bit
goes into RB8 in the special function register SCON. The baud rate is variable
Serial Data Mode-2 Multiprocessor
• In this mode 11 bits are transmitted through TXD or received through
RXD.
• The various bits are as follows: a start bit (usually '0'), 8 data bits (LSB
first), a programmable 9 th (TB8 or RB8)bit and a stop bit (usually '1').
• While transmitting, the 9 th data bit (TB8 in SCON) can be assigned the
value '0' or '1'.
• On reception of the data, the 9 th bit goes into RB8 in 'SCON', while the
stop bit is ignored.
• The baud rate is programmable to either 1/32 or 1/64 of the oscillator
frequency.
Serial Data Mode-3 - Multi processor mode

• In this mode 11 bits are transmitted through TXD or received through


RXD.
• The various bits are: a start bit (usually '0'), 8 data bits (LSB first), a
programmable 9 th bit and a stop bit (usually '1').
• Mode-3 is same as mode-2, except the fact that the baud rate in mode-
3 is variable (i.e., just as in mode-1).
f baud = (2 SMOD /32) * ( fosc / 12 (256-TH1)
8051 Assembler Directives

ORG (Origin):- ORG directive is used to specify a location in program


memory where the program following directive is to be placed.
Syntax: ORG ROM-address
Address can be given in either in hex or decimal.
For example :ORG 100 or ORG 1000h

EQU:- The EQU directive is used to replace a number by a symbol.


Syntax: Name EQU Constant
For example: MAXIMUM EQU 99
SET:-The SET directive is also used to replace a number by a symbol. The
significant difference compared to the EQU directive is that the SET directive
can be used an unlimited number of times.

Syntax : Name SET Constant


E.g.:- SPEED SET 45

BIT:- The BIT directive is used to replace a bit address by a symbol. The bit
address must be in the range of 0 to 255 (00 H to FF H).

Syntax: Name BIT 8051-bit


E.g.:- OUTPUT BIT 6 ;
Bit at address 06 is assigned the name “OUTPUT”.
CODE:- The CODE directive is used to assign a symbol to a program memory address.
Since the maximum capacity of program memory is 64K, the address must be in the
range of 0 to 65535(0000 H to FFFF H).

Syntax: Name CODE code-address


For example: RESET CODE 0 ;
Memory location 00h called “RESET”.
DATA:- The DATA directive is used to assign a symbol to an address within internal
RAM and SFR. The address must be in the range of 0 to 255 (00 H to FF H). It is
possible to change or assign a new name to any register.

Syntax: Name DATA data-address


For example: TEMP12 DATA 32 ;
Register at address 32 is named as “TEMP12”.
IDATA:- The IDATA directive is used to change or assign a new name to
an indirectly addressed register. It is an address of entire internal RAM.
Syntax: Name IDATA idata-address
For example: TEMP22 IDATA 32 ;
Register whose address is in register ;at address 2 is named as “TEMP22”

XDATA:-The XDATA directive is used to assign a name to registers


within external (additional) RAM memory. The addresses of these
registers cannot be larger than 65535 (0000 h to FFFF h).
Syntax: Name XDATA xdata-address
For example:TABLE_1 XDATA 2048 ;
Register stored in external; memory at address 2048 is named; as
“TABLE_1”.
USING:- The USING directive is used to define which register
bank (registers R0-R7) is to be used in the program.

Syntax: USING Bank-no;

USING 0 ; Bank 0 is used (registers R0-R7 at RAM-addresses 0-7)


USING 1; Bank 1 is used (registers R0-R7 at RAM-addresses 8-15)
USING 2 ; Bank 2 is used (registers R0-R7 at RAM-addresses 16-
23)
USING 3 ; Bank 3 is used (registers R0-R7 at RAM-addresses 24-
31).
END
The END directive is used at the end of every program. It
indicates the end of program. The assembler will stop compiling
once the program encounters this directive.

Syntax: END

DB (Define Byte)
The DB directive is used for writing specified value into
program memory

NUM1 DB 22,33
Instruction Set

8051 Microcontroller have set of instruction to perform different


operations. There are five group of instruction which are listed below.
• Arithmetic Instructions.
• Logic Instructions.
• Data Transfer Instructions.
• Branch Instructions
• Bit-oriented Instructions
Data Transfer Instructions

Mnemonic Description
MOV Move Data
MOVC Move Code
MOVX Move External Data
PUSH Move Data to Stack
POP Copy Data from Stack
XCH Exchange Data between two Registers
XCHD Exchange Lower Order Data between two Registers
Arithmetic instructions
Mnemonic Description
ADD Addition without Carry
ADDC Addition with Carry
SUBB Subtract with Carry
INC Increment by 1
DEC Decrement by 1
MUL Multiply
DIV Divide
DA A Decimal Adjust the Accumulator (A Register)
Logical instructions
Mnemonic Description
ANL Logical AND
ORL Logical OR
XRL Ex-OR
CLR Clear Register
CPL Complement the Register
RL Rotate a Byte to Left
RLC Rotate a Byte and Carry Bit to Left
RR Rotate a Byte to Right
RRC Rotate a Byte and Carry Bit to Right
SWAP Exchange lower and higher nibbles in a Byte
Boolean or Bit manipulation instructions
Mnemonic Description
CLR Clear a Bit (Reset to 0)
SETB Set a Bit (Set to 1)
MOV Move a Bit
JC Jump if Carry Flag is Set
JNC Jump if Carry Flag is Not Set
JB Jump if specified Bit is Set
JNB Jump if specified Bit is Not Set
JBC Jump if specified Bit is Set and also clear the Bit
ANL Bitwise AND
ORL Bitwise OR
CPL Complement the Bit
Branch Instructions
Mnemonic Description
LJMP Long Jump (Unconditional)
AJMP Absolute Jump (Unconditional)
SJMP Short Jump (Unconditional)
JZ Jump if A is equal to 0
JNZ Jump if A is not equal to 0
CJNE Compare and Jump if Not Equal
DJNZ Decrement and Jump if Not Zero
NOP No Operation
LCALL Long Call to Subroutine
ACALL Absolute Call to Subroutine (Unconditional)
RET Return from Subroutine
RETI Return from Interrupt
JMP Jump to an Address (Unconditional)
Addressing Modes

The 8051 Family of Microcontrollers allows five types of Addressing


Modes for addressing the Operands. They are:
• Immediate Addressing --------MOV A, #030H
• Register Addressing ------MOV A, R5
• Direct Addressing ------------- MOV A, 47H
• Register – Indirect Addressing ----------MOV A, @R1
• Indexed Addressing ------------- MOVC A, @A+DPTR

You might also like