Vous êtes sur la page 1sur 28

MICROCONTROLLERS

LAB
MANUAL

LAB CODE: EC 607, EE 410

LIST OF EXPERIMENTS

1. Study the architecture of 8051


2. Study the pin diagram of 8051
3. Study the instruction set of 8051
4. WAP to add two 8 bit numbers
5. WAP to subtract two 8 bit numbers
6. WAP to multiply two 8 bit numbers
7. WAP to divide two 8 bit numbers
8. WAP to perform 2s complement of a 8 bit numbers
9. WAP to add two Multi-Byte numbers
10.WAP to sub two Multi-Byte numbers
11.WAP to mul two Multi-Byte numbers
12.WAP to perform ORL between two 8 bit numbers
13.WAP to perform ANL between two 8 bit numbers
14.WAP to perform XRL between two 8 bit numbers

EXPERIMENT NO: 01

STUDY THE ARCHITECTURE OF 8051


Aim :

To study the architecture of 8051 microcontroller

Description:
o The microcontroller incorporates all the features that are found in
microprocessor.
o The microcontroller has built in ROM, RAM, Input Output ports, Serial Port,
o timers, interrupts and clock circuit. A microcontroller is an entire computer
o manufactured on a single chip. Microcontrollers are usually dedicated
devices
o embedded within an application.
o For example, microcontrollers are used as engine controllers in automobiles
and as exposure and focus controllers in cameras.
o In order to serve these applications, they have a high concentration of onchip facilities such as serial ports, parallel input output ports, timers,
counters, interrupt control, analog-to-digital converters, random access
memory, read only memory, etc.
o The I/O, memory, and on-chip peripherals of a microcontroller are selected
depending on the specifics of the target application. Since microcontrollers
are powerful digital processors, the degree of control and programmability
they provide significantly enhances the effectiveness of the application.
FEATURES OF 8051 MICROCONTROLLER:

8-bit ALU, Accumulator, 8-bit Registers and 8-bit data bus; hence it is an 8bitmicrocontroller
Boolean processor
Multiply, divide and compare instructions
4 register banks with 8 registers each (memory mapped)
Fast interrupt with register bank switching
Interrupts and threads with selectable priority supporting basic multitasking up to
hardware assisted, small real-time operating systems (RTOS) with preemptive
multitasking
Dual 16-bit address bus It can access 2 x 216 memory locations 64 kB (65536
locations) each of RAM and ROM
128 bytes of on-chip RAM (IRAM)

4 KB of on-chip ROM, with a 16-bit (64 KB) address space (PMEM)


Four byte bi-directional input/output port
UART (serial port)
Two 16-bit Counter/timers
Power saving mode (on some derivatives)

INTERNAL ARCHITECTURE OF 8051 MICROCONTROLLER


128 Byte RAM for Data Storage:
o MC 8051 has 128 byte Random Access memory for data storage.
o Random accessmemory is non volatile memory.
o During execution for storing the data the RAM is used.
o RAM consists of the register banks, stack for temporary data storage.
o It also consists of some special function register (SFR) which are used for
some
o specific purpose like timer, input output ports etc

4KB ROM:

In 8051, 4KB read only memory (ROM) is available for program storage.
This is used for permanent data storage. Or the data which is not changed
during the processing like the program or algorithm for specific
applications.

This is volatile memory the data saved in this memory does not disappear
after power failure.

Timers and Counters:

In MC8051, two timer pins are available T0 and T1 , by these timers


we can give the delay of particular time if we use these in timer
mode.
We can count external pulses at these pins if we use these pins in
counter mode.
16 bits timers are available. Means we can generate delay between
0000H to FFFFH.
Two special function registers are available.

If we want to load T0 with 16 bit data then we can load separate


lower 8 bit
In TL0 and higher 8 bit in TH0.
In the same way for T1.
TMOD, TCON registers are used for controlling timer operation.

Serial Port:
There are two pins available for serial communication TXD and RXD.
Normally TXD is used for transmitting serial data which is in SBUF register,
RXD is used for receiving the serial data.
SCON register is used for controlling the operation

Input Output Ports:


There are four input output ports available P0, P1, P2, P3.
Each port is 8 bit wide and has special function register P0, P1, P2, P3
which are bit addressable means each bit can be set or reset by the Bit
instructions (SETB for high, CLR for low) independently.
The data at any port which is transmitting or receiving is in these registers.
The port 0 can perform dual works. It is also used as Lower order address
bus (A0 to A7) multiplexed with 8 bit data bus P0.0 to P0.7 is AD0 to AD7
respectively the address bus and data bus is demultiplex by the ALE signal
and latch which is further discussed in details.

Port 2 can be used as I/O port as well as higher order address bus A8 to A15.
Port 3 also have dual functions it can be worked as I/O as well as each pin
of P3 has specific function.
P3.0 RXD
P3.1 TXD Serial data transmit.
P3.2 INT0 External Interrupt 0.
P3.3 INT1 External Interrupt 1.
P3.4 T0 Clock input for counter 0.
P3.5 T1 Clock input for counter 1.
P3.6 WR Signal for writing to external memory.
P3.7 RD Signal for reading from external memory.
When external memory is interfaced with 8051 then P0 and P2 cant be
worked as I/O port they works as address bus and data bus, otherwise they
can be accessed as I/O ports.

Oscillator:
It is used for providing the clock to MC8051 which decides the speed or
baud rate of MC.
We use crystal which frequency vary from 4MHz to 30 MHz, normally we
use 11.0592 MHz frequency.

Interrupts:
Interrupts are defined as requests because they can be refused (masked) if
they are not used, that is when an interrupt is acknowledged. A special set
of events or routines are followed to handle the interrupts. These special
routines are known as interrupt handler or interrupt service routines (ISR).
These are located at a special location in memory.
INT0 and INT1 are the pins for external interrupts.

RESULT : Hence studied the architecture of 8051 microcontroller

EXPERIMENT NO: 02

STUDY THE PIN DIAGRAM OF 8051


Aim :

To study the pin diagram of 8051 microcontroller

PIN DIAGRAM OF 8051 MICROCONTROLLER

PIN DESCRIPTION :
Pins 1 to 8(Port 1): The Pins 1.0 to 1.7 are 8 Pins of port 1. Each of them can be
configured as input or output pin.

Pin 9: It is used to Reset Microcontroller 8051. A positive pulse is given on this Pin to
reset Microcontroller.

Pin 10 to 17(Port 3): These Pins are similar to Pins of Port 1. These Pins can be used as
universal Input or output. These are dual function Pins.

Function of each Pin is given as


Pin 10:
It is Serial Asynchronous Communication Input or Serial
Asynchronous Communication Output.

Pin 11:

Serial Asynchronous Communication Output or Serial Synchronous


Communication Output.

Pin 12:
Pin 13:
Pin 14:
Pin 15:
Pin 16:
Pin 17:

Interrupt 0 input.
Interrupt 1 input.
Counter 0 clock input.
Counter 1 clock input.
Writing Signal for Writing content on external RAM.
Reading Signal to read contents of external RAM.

Pin 18 and 19: These are input output PINS for oscillator. An internal oscillator is
connected to Micro controller through these PINS.

Pin 20: Pin 20 is grounded.


Pin 21 to 28 (Port 2): These Pins can be configured as Input Output Pins. But this
is only possible in case when we don't use any external
memory. If we use external memory then these pins will
work as high order address bus(A8 to A15).

Pin 29: If we uses an external ROM then it should has a logic 0 which indicates
Micro controller to read data from memory.

Pin 30: This Pin is used for ALE that is Address Latch Enable. If we uses multiple
memory chips then this pin is used to distinguish between them. This Pin
also gives program pulse input during programming of EPROM.

Pin 31: If we have to use multiple memories then by applying logic 1 to this pin
instructs Micro controller to read data from both memories first internal
and afterwards external.

Pin 32 to 39(Port 0): Similar to port 2 and 3, these pins can be used as input

output pins when we don't use any external memory.


When ALE or Pin 30 is at 1 then this port is used as data bus,
when ALE pin at 0, then this port is used as lower order
address bus(A0 to A7).

Pin 40: VCC +5V power supply.

RESULT : Hence studied the pin diagram of 8051 microcontroller

EXPERIMENT NO: 03

STUDY THE INSTRUCTION SET OF 8051


Aim : To study the instruction set of 8051 Microcontroller
Types of instructions

Arithmetic Instructions
Branch Instructions
Data Transfer Instructions
Logic Instructions
Bit-oriented Instructions

Instruction set Description :


Data Transfer Instructions:
Data transfer instructions move the content of one register to another. The register the content of
which is moved remains unchanged. If they have the suffix X (MOVX), the data is exchanged
with external memory.

INSTRUCTIONS

BYTES

INSTRUCTIONS

BYTES

MOV @R0,#data

MOV R6,iram addr

MOV @R1,#data

MOV R7,iram addr

MOV @R0,A

MOV bit addr,C

MOV @R1,A

MOV iram addr,#data

MOV @R0,iram addr

MOV iram addr,@R0

MOV @R1,iram addr

MOV iram addr,@R1

MOV A,#data

MOV iram addr,R0

MOV A,@R0

MOV iram addr,R1

MOV A,@R1

MOV iram addr,R2

MOV A,R0

MOV iram addr,R3

MOV A,R1

MOV iram addr,R4

MOV A,R2

MOV iram addr,R5

MOV A,R3

MOV iram addr,R6

MOV A,R4

MOV iram addr,R7

MOV A,R5

MOV iram addr,A

MOV A,R6

MOV i addr,i addr

MOV A,R7

MOVX @DPTR,A

MOV A,iram addr

MOVX @R0,A

MOVX @R1,A

MOVX A,@DPTR

MOV DPTR,#data16

MOVX A,@R0

MOV R0,#data

MOVX A,@R1

MOV R1,#data

MOV R4,A

MOV R2,#data

MOV R5,A

MOV R3,#data

MOV R6,A

MOV R4,#data

MOV R7,A

MOV R5,#data

MOV R0,iram addr

MOV R6,#data

MOV R1,iram addr

MOV R7,#data

MOV R2,iram addr

MOV R0,A

MOV R3,iram addr

MOV R1,A

MOV R4,iram addr

MOV R2,A

MOV R5,iram addr

MOV R3,A

XCH A,R3

XCH A,@R0

XCH A,R4

XCH A,@R1

XCH A,R5

XCH A,R0

XCH A,R6

XCH A,R1

XCH A,R7

XCH A,R2

XCH A,iram addr

POP iram addr

PUSH iram addr

SWAP A

Arithmetic instructions
Arithmetic instructions perform several basic operations such as addition, subtraction,
division, multiplication etc. After execution, the result is stored in the first operand.

Instructions

Bytes

Flags

ADD A,#data

C, AC, OV

ADD A,iram addr

C, AC, OV

ADD A,@RI

C, AC, OV

ADD A, Rn

C, AC, OV

ADDC A,#data

C, AC, OV

ADDC A,i addr

C, AC, OV

ADDC A,@Ri

C, AC, OV

ADDC A, Rn

C, AC, OV

SUBB A,#data

C, AC, OV

SUBB A,iram addr

C, AC, OV

SUBB A,@Ri

C, AC, OV

SUBB A,Rn

C, AC, OV

INC A

None

INC iram addr

None

INC @Ri

None

INC Rn

None

INC DPTR

None

DEC A

None

DEC iram addr

None

DEC @Ri

None

DEC Rn

None

DIV AB

C, OV

MUL AB

C, OV

DA A

LOGICAL GROUP OF INSTRUCTIONS


Instructions

Bytes

Flags

ANL iram addr,A

None

ANL iram addr,#data

None

ANL A,#data

None

ANL A,iram addr

None

ANL A,@R0

None

ANL A,@R1

None

ANL A,R0

None

ANL A,R1

None

ANL A,R2

None

ANL A,R3

None

ANL A,R4

None

ANL A,R5

None

ANL A,R6

None

ANL A,R7

None

ORL iram addr,A

None

ORL iram addr,#data

None

ORL A,#data

None

ORL A,iram addr

None

ORL A,@R0

None

ORL A,@R1

None

ORL A,R0

None

ORL A,R1

None

ORL A,R2

None

ORL A,R3

None

ORL A,R4

None

ORL A,R5

None

ORL A,R6

None

ORL A,R7

None

XRL iram addr,A

None

XRL iram addr,#data

None

XRL A,#data

None

XRL A,iram addr

None

XRL A,@R0

None

XRL A,@R1

None

XRL A,R0

None

XRL A,R1

None

XRL A,R2

None

XRL A,R3

None

XRL A,R4

None

XRL A,R5

None

XRL A,R6

None

XRL A,R7

None

CPL A

None

CPL C

CLR C

CLR A

None

RL A

RLC A

RR A

None

RRC A

BIT ORIENTED GROUP OF INSTRUCTIONS


Instructions

Bytes

Flags

SETB C

SETB bit addr

None

CPL bit addr

None

CLR bit addr

None

ORL C,bit addr

ORL C,/bit addr

ANL C,bit addr

ANL C,/bit addr

MOV C,bit addr

NONE

BRANCH GROUP INSTRUCTIONS


Instructions

Bytes

Flags

ACALL page0

None

ACALL page1

None

ACALL page2

None

ACALL page3

None

ACALL page4

None

ACALL page5

None

ACALL page6

None

ACALL page7

None

AJMP page0

None

AJMP page1

None

AJMP page2

None

AJMP page3

None

AJMP page4

None

AJMP page5

None

AJMP page6

None

AJMP page7

None

CJNE A,#data,reladdr

CJNE A,iram addr,reladdr

CJNE @R0,#data,reladdr

CJNE @R1,#data,reladdr

CJNE R0,#data,reladdr

CJNE R1,#data,reladdr

CJNE R2,#data,reladdr

CJNE R3,#data,reladdr

CJNE R4,#data,reladdr

CJNE R5,#data,reladdr

CJNE R6,#data,reladdr

CJNE R7,#data,reladdr

DJNZ iram addr,reladdr

None

DJNZ R0,reladdr

None

DJNZ R1,reladdr

None

DJNZ R2,reladdr

None

DJNZ R3,reladdr

None

DJNZ R4,reladdr

None

DJNZ R5,reladdr

None

DJNZ R6,reladdr

None

DJNZ R7,reladdr

None

JB bit addr,reladdr

None

JBC bit addr,reladdr

None

JC reladdr

None

JMP @A+DPTR

None

JNB bit addr,reladdr

None

JNC reladdr

None

JNZ reladdr

None

JZ reladdr

None

LCALL code addr

None

LJMP code addr

None

RET

None

RETI

None

SJMP reladdr

None

NOP

None

RESULT : Hence studied the instruction set of 8051


microcontroller

EXPERIMENT NO: 04

PROGRAM FOR ADDITION OF TWO 8 BIT NUMBERS


AIM : To write a program for adding two 8 bit numbers
Program:

MOV A, # data
MOV B, # data
ADD A, B
INT O3
Output:

Test data:

A = 08H
B = 02H
AFTER ADDITION OPERATION
A = 0AH
B = 02H

EXPERIMENT NO : 05

PROGRAM FOR SUBTRACTION OF TWO 8 BIT NUMBERS


AIM : To write a program for Subtracting two 8 bit numbers
Program:

MOV A, # data
MOV B, # data
SUBB A, B
INT O3

Output:

Test data:

A = 08H
B = 02H
AFTER SUBTRACTION OPERATION
A = 06H
B = 02H

EXPERIMENT NO : 06

PROGRAM FOR MULTIPLICATION OF TWO 8 BIT NUMBERS


AIM : To write a program for multiplying two 8 bit numbers
Program:

MOV A, # data
MOV F0, # data
MUL AB
INT O3

Output:

Test data:

A = 08H
B = 02H
AFTER MULTIPLICATION OPERATION
A = 16H (LOWER 8 BITS)
B = 00H (HIGHER 8 BITS)

EXPERIMENT NO: 07

PROGRAM FOR DIVISION OF TWO 8 BIT NUMBERS


AIM : To write a program for dividing two 8 bit numbers
Program:

MOV A, # data
MOV F0, # data
DIV AB
INT O3

Output :

Test data:

A = 08H
B = 02H
AFTER DIVISION OPERATION
A = 04H (QUOTIENT)
B = 00H (REMAINDER)

EXPERIMENT NO: 08

PROGRAM FOR FINDING 2S COMPLEMENT OF A 8 BIT NO


AIM : To write a program for finding complement of a given
number
Program:

MOV A, #data
CPL A
INC A
INT 03

Output :

Test data:

A = 08H 0000 1000


CPL A - 1111 0111
INC A - 1111 1000
AFTER PROGRAM
A = F8 H

EXPERIMENT NO: 09

PROGRAM FOR MULTIBYTE ADDITION OF TWO MULTIBYTE NOS


AIM : To write a program for adding two multibyte numbers

Program :
MOV A, # data (last 8 bits of A data)
MOV B, # data (last 8 bits of B data)
ADD A,B
MOV R0, A
MOV A,# data (first 8 bits of A data)
MOV B, # data (first 8 bits of B data)
ADDC A,B
INT 03
Output :
Test data :

Consider two multibyte numbers as


A = 1234H
B = 4567H
After mulitbyte addition
Result should be = 5801H

EXPERIMENT NO: 10

PROGRAM FOR MULTIBYTE SUBTRACTION OF TWO MULTIBYTE


NUMBERS
AIM : To write a program for subtracting two multibyte
numbers
Program :
MOV A, # data (last 8 bits of A data)
MOV B, # data (last 8 bits of B data)
SUBB A,B
MOV R0, A
MOV A,# data (first 8 bits of A data)
MOV B, # data (first 8 bits of B data)
SUBB A,B
INT 03
Output:
Test data:

Consider two multibyte numbers as


A = 4567H
B = 1234H
After mulitbyte subtraction
Result should be = 3333H

EXPERIMENT NO: 11

PROGRAM FOR MULTIBYTE MULTIPLICATION OF TWO


MULTIBYTE NOS
AIM : To write a program for multiplying two mulibyte
numbers
Program :
MOV A, # data (last 8 bits of A data)
MOV B, # data (last 8 bits of B data)
MUL AB
MOV R0, A
MOV B,A
MOV R1,A
MOV A,# data (first 8 bits of A data)
MOV B, # data (first 8 bits of B data)
MUL AB
INT 03
Output :
Test data :

A = 0402H
B = 0204H

After program execution


R0 = 08

RI = 00

A = 08

B = 00

EXPERIMENT NO: 12

PROGRAM FOR OR LOGIC


AIM : To write a program for finding OR Logic two 8 bit
numbers
Program :
MOV A,#data
MOV R0,#data
ORL A,R0
INT 03

Output :
Test data :
A = 84 H = 1000 0100
R0 = 12 H = 0001 0010
AFTER ORL
A = 1001 0110 = 96 H

EXPERIMENT NO: 13

PROGRAM FOR OR LOGIC


AIM : To write a program for finding AND Logic two 8 bit
numbers
Program :
MOV A,#data
MOV R0,#data
ANL A,R0
INT 03

Output :
Test data :
A = 84 H = 1000 0100
R0 = 92 H = 1001 0010
AFTER ANL
A = 1000 0000 = 80 H

EXPERIMENT NO: 14

PROGRAM FOR OR LOGIC


AIM : To write a program for finding EX - OR Logic two 8 bit
numbers
Program :
MOV A,#data
MOV R0,#data
XRL A,R0
INT 03

Output :
Test data :
A = 84 H = 1000 0100
R0 = 12 H = 0001 0010
AFTER XRL
A = 1001 0110 = 96 H

Vous aimerez peut-être aussi