You are on page 1of 39

PANTECH PROLABS INDIA PVT.

LTD

8051
MICROCONTROLLER
PS TRAINER8051B
USER
MANUAL

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

PANTECH PROLABS INDIA PVT LTD.


No:41 Santhosh nagar, Rajeshwari street, Kandhanchavadi, Chennai - 600 096
Ph: 044 6452 4445/46/47 | Fax: 044 4260 6350 |
www.pantechsolutions.net
BRANCHES @ CHENNAI | COIMBATORE | MADURAI | HYDERABAD | BANGALURU |
COCHIN | PUNE

TABLE OF CONTENTS
CHAPTER

1: INTRODUCTION

1.1

WELCOME

1.2

PS 8086 BOARD OVERVIEW

1.3

PS 8086 SPECIFICATIONS

CHAPTER 2:
2.1
2.2
2.3
2.4

4.1
4.2
4.3
4.4

5.1
5.2

06

07

COMMANDS AND KEYS


13
13
OPERATING INSTRUCTIONS

POWER ON
PROGRAM ENTRY USING ASSEMBLER
ENTERING MNEMONICS
DISASSEMBLER

CHAPTER 5:

05

SYSTEM DESCRIPTION

RESET
H (HELP MENU)

CHAPTER 4:

04

HARDWARE
MAPPING OF DEVICES
POWER SUPPLY DETAILS
KEYBOARD DETAILS

CHAPTER 3:
3.1
3.2

PAGE NO

14
15
16

PROGRAMMING DETAILS

8051 OVERVIEW
REGISTERS

PS 8051 USER MANUAL

20

PS-8051

PANTECH PROLABS INDIA PVT.LTD

5.3

BREAKPOINT

CHAPTER 6:
6.1
6.2
6.3
6.4
6.5
6.6
6.7
6.8
6.9
6.10
6.11
6.12

EXAMPLE PROGRAMS

ADDITION
SUBTRACTION
MULTIPLICATIONS
DIVISION
MULTI BYTE ADDITION
LARGEST ELEMENT IN AN ARRAY
PROGRAMS FOR SORTING
BCD TO HEX CONVERSION
HEX TO BCD CONVERSION
ASCII TO HEX CONVERSION
SQUARE ROOT OF A GIVEN NUMBER
PARITY GENERATION

PS 8051 USER MANUAL

22
23
24
25
26
28
29
30
31
32
33
34

PS-8051

PANTECH PROLABS INDIA PVT.LTD

CHAPTER

1: INTRODUCTION

1.1 WELCOME
Thank you for purchasing PS-8051 Board from PANTECH PROLABS INDIA PVT
LTD. The PS-8051 board which demonstrates the capabilities of the 40-pin 8051
(various families) Sample programs are provided to demonstrate the unique
features of the supported devices.
The PS-8051 Board Kit comes with the following:
1)
2)
3)
4)

PS-8051 Board
Sample device (NXP 89V51RD2)
Cross cable (RS232)
CD-ROM, which contains:
Sample programs
User and Technical Reference Manual
5) User and Technical Reference Manual
6)

Keyboard (101 keys)

Note: If you are missing any part of the kit, please contact our
support executive

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

1.2 PS 8051 BOARD OVERVIEW

The PS 8051 board is based on Intel 8051Microcontroller which operates at


11.0592 MHZ. The board can

operate using 101/104 PC keyboard supplied along

with the trainer kit and 2 line by 16 characters LCD display or from the PC (using the
Terminal Emulation Software).

PS 8051 is equipped with powerful software

monitor in 27C256 EPROM. Keyboard and LCD display. The board has 32KB CMOS
static RAM (type 62256). PS 8051 works on +9V DC at 1 Amp.

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

1.3 PS 8051 SPECIFICATIONS


The PS 8051 board has the following hardware features:

8051 Microcontroller operating at 11.0592MHZ.


32KB powerful software monitor in 27C256 EPROM.
64KB on chip Flash memory (partially used by Firmware).
Two 16 bit programmable on chip Timer.
32 Programmable I/O pins (24 from 8255).
50 pin FRC connector for system bus expansion.
20 pin FRC connector for user interface from 8255.
9 pin D type connector for RS 232C interface.
Six different selectable baud rates from 150 to 9600.
One timer and external interrupt.
101 PC type keyboard for entering user address/data and for commands.
Built in line by line Assemble and Disassemble.
User friendly software monitor for loading and executing programs with

break point facility.


Facility to connect to PC.
PS-8051 board supports Assembly and C language

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

CHAPTER 2: SYSTEM DESCRIPTION


2.1

HARDWARE DESCRIPTION

PROCESSOR CLOCK FREQUNCY:


8051 operates at 11.0592 MHz clock.

MEMORY:
Monitor EPROM: 0000 7FFF (SEGMENT)
System RAM:

0000 FFFF (SEGMENT)


8000 FFFF (Reserved For Monitor program)

User RAM Area:

8500 FFFF

ALLOCATION OF EPROM:
STARTADDR
ESS
0000

ENDADDR
ESS
7FFF

SOCKET
NO
U3

IC
USED
27256

TOTAL
CAPACITY
32 K BYTE

SOCKET
NO
U6

IC
USED
62256

TOTAL
CAPACITY
32 K BYTE

ALLOCATION OF RAM:
STARTADDR
ESS
8000

ENDADDR
ESS
FFFF

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

2.2 MAPPING OF DEVICES


PARALLEL INTERFACE:
8255

- Programmable peripheral interface.

The following are the I/O addresses for 8255

SOCKET.NO

FUNCTION

ADDRESS

CONTL REG
PORT A
PORT B
PORT C

U2

CONNECTOR.N
O

4003
4000
4001
4002

J1

CONNECTOR DETAILS
20 PIN EXPANSION CONNECTORS:
The 20 Pin FRC connector is used to interconnect with the Interface cards
like ADC, DAC, SWITCH/LED, RELAY buzzer Interfaces etc. Pin details are given
below
J1
PA0
PA2
PA4
PA6
PB0
PB2
PB4
PB6
VCC

1
3
5
7
9
11
13
15
17
19

J4
2
4
6
8
10
12
14
16
18
20

PA1
PA3
PA5
PA7
PB1
PB3
PB5
PB7
GND
GND

20-PIN FRC

P1.0 1
P1.2 3
P1.4 5
P1.6 7
P3.0 9
P3.2 11
P3.4 13
P3.6 15
17
19
VCC

J3
2
4
6
8
10
12
14
16
18
20

P1.1
P1.3
P1.5
P1.7
P3.1
P3.3
P3.5
P3.7
GND
GND

PC0
PC2
PC4
PC6
CS6
CS8
CS10

VCC

1
3
5
7
9
11
13
15
17
19

20-PIN FRC

2
4
6
8
10
12
14
16
18
20

PC1
PC3
PC5
PC7
CS7
CS9
CS11
GND
GND

20-PIN FRC

50 PIN EXPANSION CONNECTOR:

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

The 50 Pin FRC connector is used to interconnect with the Interface cards
like 8255, 8279, 8253/8251, 8259 .
J6
GND
D0
D2
D4
D6
A0
A2
A4
A6
A8
A10
A12
A14
PCLK
RST
INT1
WR
ALE
PSEN
CS7
CS9
RXD
VCC

1
3
5
7
9
11
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49

2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50

D1VCC
D3
D5
D7
A1
A3
A5
A7
A9
A11
A13
A15
INT0
RD
EA
CS6
CS8
TXD
GND

KEYBOARD CONNECTOR:
5V

PIN NO
5

R 13
1K
P C 07

P S 2
1,2
8

8,6

5
3

SIGNAL
R 12
1K
P C 06

KEYBOARD CLOCK
DATA
VCC

J P 1

GND

9PIN D TYPE (FEMALE):

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

NC
NC
P1
1
6
2
7
3
8
4
9
5

RXD
CTS
TXD
NC
NC
NC
GND

Universal Synchronous/ Asynchronous Receiver/ Transmitter.


RS232 bridge converter
DRIVERS USED:
MAX 232 is used for transmitting receiving of characters.

LCD CONNECTOR

10

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

11

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

LCD

12

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

Device used: 16 2 / 20 4 LCD module


System Mapping: I/O mapped I/O.
SOCKET.NO

FUNCTION

ADDRESS

LCD COMMAND
LCD DATA

----

4020
4021

CONNECTOR.NO

-----

2.3 POWER SUPPLY DETAILS


PS trainer kit will work at 0 9v (1 amp) from the PS power supply. Provision is made
in PS power supply to bring out on the front panel DC regulated voltage output for
interfacing with add-on cards.
+9V
1 amp
Supply Turned OFF

POWER SWITCH

Supply Turned ON

2.4 KEYBOARD DETAILS


101 PC type keyboard is interfaced to Microcontroller through its port pin.
Communication between keyboard and Microcontroller takes place using 2 wires one for
serial clock and serial data (P1.6 and P1.7).

CHAPTER 3 COMMANDS AND KEYS


3.1 RESET
This Reset key is located in the PS-8051 trainer kit. On depressing this key the
program starts executing from the beginning i.e. at reset address 0000. On power on reset
message PS 8051 is displayed in local LCD display.

3.2

13

H (Help Menu)

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

PRESS H KEY This key is used in PS 51/31 to get into help menu and it will display
the following commands.
A <BEG>

ASSEMBLE

BAUD RATE

D <BEG>

DISASSEMBLE

E <BEG> <END>

EXAMINE

G <BEG>

EXECUTE

HELP COMMANDS

I <ADDR>

INTERNAL RAM

L <OFFSET>

DOWNLOAD

M <ADDR>

MODIFY

NORMAL MODE

QUIT

R <REG>

REGISTER DISPLAY

SERIAL MODE

<START>

<END>

<DS>
U <BEG> <END>

BLOCK TRANSFER
UP LOAD

CHAPTER 4 OPERATING INSTRUCTIONS


4.1 POWER ON
Connect the PS 8051 board to the power having the following specifications.
+9V DC

1 Amp

Switch on the power supply after ensuring the correct voltages. Following message will
appear on the LCD display.
PAN TECH
8051

14

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

On power on or after reset the display shows PANTECH 8051 as a sign on message. The
prompt character is displayed in the next line informing the user, that the board is ready to
accept the commands.

4.2 PROGRAM ENTRY USING ASSEMBLER:


ENTERING MNEMONICS

Example:
PAN TECH

Enter the starting Address

a8500

Enter Key
User program starts from address 8500. Display the following and waits for the user
data to be typed in the second line .
EXAMPLE:

8500:
mov a,#12

Type the Mnemonics


Enter Key

8502:

Type the Mnemonics

mov b,#12

Enter Key

EXIT COMMAND:
Double enter you get the main menu

Press H for help

PROGRAM ENTRY USING OPCODE:


Modify External memory
Press H for help
m8500

Enter the starting Address


Enter Key

8500:
4A

8500:

Type the opcode

4A 74

15

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

Enter the space bar key


8501:

Type the opcode

56 12
Enter the space bar key

EXIT COMMAND: Double enter you get the main menu


ENTERING G EXECUTING COMMAND
Press H for help

Enter starting address

G8500
Enter key
After executing display

Executing display

To EXIT Execution Mode

PRESS RESET Switch

4.3 ENTERING RESULT COMMAND:


Press H for help

Enter the Memory Location

m <address>
Enter Key

<Address>:
24

You Get the Output


8-Bit Data

4.4 DISASSEMBLER
Disassemble converts the hex byte stored in the memory into equivalent
mnemonics. To enter into disassemble mode, type D in the command mode followed
by the memory address.
EXAMPLE:
Press H for help

Enter the Starting Address

d8500

16

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

Enter Key
8500:

74

12

MOV A,#12
Enter the Space Bar Key
8502:

75 0B 12

MOV B,#12

Enter the space bar key

M (MODIFY EXTERNAL MEMORY):


Using this command the user can display/modify any external memory address.
Modify External memory
Press H for help

Enter the starting Address

m8500

R (REGISTER DISPLAY)
EXAMPLE:
Press H for help

Enter the starting Address

RA
Enter Key
A = FF

Enter the Space Bar Key


A = FF
B = FF
Enter the Space Bar Key till the end of Registers

T (TRANSFER COMMAND)
EXAMPLE:
T8500 8600 9000

17

Press Enter Key.

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

The above command transfer the memory content starting from source start
address 8500 to destination start address 8600 till source end address 9000 is
reached
Starting address
End address
Destination address

8500
8600
9000

Press H for help


t8500 8600 9000

Enter Key

T: 8500 to 9000

Enter Key

for Exit Command

N (LOCAL MODE)
When this key is depressed on PC keyboard, the PS 8051 Kit starts working through
local 101 key keyboard. Serial communication is disabled. Following message will
appear in the LCD display.
! Normal Mode!

B (BAUD RATE)
Press the B
BAUD RATE : @0150
@150

Enter the Space Bar Key to change Baud Rate

BAUD RATE : @0150


@2400

Enter Key
BAUD RATE

Set the 2400 Baud Rate


:

150, 300, 600, 1200, 2400, 4800, 9600.

When using the serial Communication .

I (MODIFY INTERNAL MEMORY)

18

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

This command is similar to that of modify external except it displays/modifies


internal 128 bytes of 8051 Microcontroller. Use of UP, DOWN and ENTER keys are
also as described above. The example program is given in chapter 6
Note: This command is one of the important commands used to modify the internal
memory of controller.

PROGRAMMING THE 8051 TRAINER KIT:


PROCEDURE 1: TO ENTER THE MNEMONICS

Initially connect the 9V adaptor to J2 connector

Switch ON the PS-8051kit using slide Switch SW1

PANTECH- 8051 will be displayed on the LCD

Connect the Keyboard in PS/2 connector

Depress A starting address of the program for Ex: A8500


For ex: A8500 enter key
Type the mnemonics MOV A,#12 press Enter key
Type the mnemonics ADD A<#12 press Enter key and continue the same
procedure till the end of the program
ADDRESS
8500
8502
8504
8507
8508

19

OPCODES
74 12
24 12
90 45 00
F0
80 FE

MNEMONICS
MOV A,#12
ADD A,#12
MOV DPTR,#8600
MOVX @DPTR,A
SJMP 8508

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

To verify the code depress D starting address and depress space bar to see
next memory location
For Ex: D8500 and press spacebar till the end of the program

To execute the program Depress G staring address for Ex: G8500.

To see the result depress M result address for Ex: M8600.

To view the output in the Register depress R and press enter key in
keyboard.

PROCEDURE 2: TO ENTER THE OPCODE


Follow the same procedure till step 4

Depress M starting address of the program for Ex: M8500


For ex: M8500 press enter
Type the opcode 74 press space bar
Type the opcode 12 press space bar and continue the same till the end of
the program
ADDRESS
8500
8502
8504
8507
8508

OPCODES
74 12
24 12
90 86 00
F0
80 FE

MNEMONICS
MOV A,#12
ADD A,#12
MOV DPTR,#8600
MOVX @DPTR,A
SJMP 8508

To view the code depress D starting address and depress space bar to see
next memory location
For Ex: D8500 and press spacebar till the end of the program

20

To execute the program Depress G staring address for Ex: G8500 and press
Reset Switch(SW2)

To see the result depress M result address for Ex: M8600.

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

To view the output in the Register depress R and press enter key in keyboard

Note: 1) M is used for displaying the result, for Ex: M8500


2) M is used to entering the Opcode.
3) M is used for entering the data.
Note: There are two ways to enter the program
1) Mnemonics method
2) Opcode method

CHAPTER 5 PROGRAMMING DETAILS


This chapter describes the technique for developing program in PS 8051 board. For
the development of program it is essential to get familiar with the machine code of
8051 Microcontroller or mnemonics of instruction set.

5.1 REGISTERS:
From the programmers point of view 8051 has the following register:

A or Accumulator used for all logical and arithmetical operations.


B register (8 bit) used in multiply/divides instructions only.
R0, R1, R2, R3, R4, R5, R6, and R7 register are general-purpose registers.
Program counter is 16 bit register capable of addressing from 0000-FFFF
Stack pointer is an 8-bit register. It is initialized a value of 70, please note the
value of SP is incremented by 1 or 2 (whereas SP decrements 1 or 2 in 8085
or Z80) depending on the type of instructions. Also stack uses only internal

128 bytes of memory.


Status/Flag register keeps track of flags.

5.2 MONITOR PROGRAM:


Monitor the program uses following areas:

21

Program EPROM

: 0000 7FFF

External user RAM

: 8000 8500 (for monitor program variables).

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

Internal RAM

: 256 bytes RAM 128 bytes used by 8051 itself.


Area from 40 to 6F is available for user.

User Interrupts

: Timer 0 interrupt vectors to address 800b.


External interrupt 0 vector to address 8003.
(The user has to enable desired interrupts in his program).

Chip select signals for user:


Chip select

CS6
CS7
CS8
CS9
CS10

ADDRESS
4040 405f
4060 407F
4080 409F
40A0 40BF
40C0 40DF

5.3 BREAKPOINT:

When writing program it is essential to debug


them and for this break points are necessary.
Normally these are achieved by using software Break points. However 8051 does not
have any such facility. Other conventional methods require extra hardware and
hence these are avoided in PS 8051 board.
Wherever break points are required they can be called like subroutines. As soon as
break point is called all the register values are saved and displayed on the console
or in local display.
BREAK POINT SUBROUTINE
ADDRESS 00BB
It is possible to continue the program execution just by depressing G and enter in
local mode.

BREAK POINT DISPLAY IN LOCAL MODE:


When break point is encountered, all the register values are saved and the Acc.
Value is displayed in the LCD display. Now use SPACE key to check register values
one by one.

BREAK POINT DISPLAY IN SERIAL MODE:


22

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

When break point is encountered, all the register values are saved and all the
register value will be displayed on the console.

CHAPTER 6:

EXAMPLE PROGRAMS

6.1 8- BIT ADDITION


ALGORITHM:

Initialize the pointer to the memory for data and result.


The ADD instruction writes the result in the accumulator.
Store the result into Memory from A registers.

MOV A,# 13
ADD A,#14

INPUT:
OUTPUT:
8600

27H

PROGRAM:
ADDRES

OPCODE

S
8500

S
74 13

MOV A,#13

Give 8 bit first data in A

8502

24 14

ADD A,#14

register
Give 8 bit second data in acc

MOV DPTR,#8600

move
Store in 8600 memory

23

8504

90 86

8507

00
F0

8508

80 FE

MNEMONICS

COMMENTS

location

MOVX @DPTR,A
HERE:

SJMP HERE

Store the value acc move


End

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

6.2 8- BIT SUBTRACTION


ALGORITHM:

Initialize the pointer to the memory for data and result.


The SUBB instruction writes the result in the accumulator.
Store the result into Memory from A registers.

MOV A,# 20
SUBB A,#10

INPUT:
OUTPUT:
8600

10H

PROGRAM:
ADDRES

24

OPCODE

S
8500
8502

S
74 20
94 10

8504

90 86 00

8507
8508

F0
80 FE

MNEMONICS

COMMENDS

MOV A,#20
SUBB A,#10

Give 8 bit first data in A register


Give 8 bit second data in acc

MOV

move
Store in 8600 memory location

DPTR,#8600
MOVX @DPTR,A
HERE:
SJMP HERE

Store the value acc move


End

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

6.3 8-BIT MULTIPLICATIONS


THEORY:

Using the accumulator, Multiplication is performed and the result is stored.

Immediate addressing is employed.


The MUL instruction writes the result in the accumulator
INPUT:

MOV A,# 06H


MOV F0,#02H

OUTPUT:
8600

0CH

PROGRAM:
ADDRES

OPCODE

MNEMONICS

S
8500
8502
8505
8506
8509
850A
850B
850D
850E

S
74 06
75 F0 02
A4
90 86 00
F0
A3
E5 F0
F0
80 FE

MOV A,#06
MOV F0,#02
MUL AB
MOV DPTR,#8600
MOVX @DPTR,A
INC DPTR
MOV A,F0
MOVX @DPTR,A
HERE:
SJMP HERE

25

COMMENDS

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

6.4 8-BIT DIVISION


THEORY:

Using the accumulator, Division is performed and the result is stored.

Immediate addressing is employed.


The div instruction writes the result in the accumulator
INPUT:

MOV A,# 08H


MOV F0,#02H

OUTPUT:
8600
8601

04H
00H

PROGRAM:
ADDRES

OPCODE

MNEMONICS

S
8500
8502
8505
8506
8509
850A
850B
850D
850E

S
74 08
75 F0 02
84
90 86 00
F0
A3
E5 F0
F0
80 FE

MOV A,#08
MOV F0,#02
DIV AB
MOV DPTR,#8600
MOVX @DPTR,A
INC DPTR
MOV A,F0
MOVX @DPTR,A
HERE:
SJMP HERE

26

COMMENDS

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

6.5 MULTI BYTE ADDITION


THEORY:

The multi-byte addition program adds only in sets of 8-bits.


The LSD of the two numbers is added first. Now, the next set of 8-bits is added,
Taking into consideration the status of carry due to the previous addition.
Addition is done till the length of the number specified becomes zero.

INPUT:

8600
8601
8602

02H
03H
04H

(FIRST INPUT)

8610
8611
8612

02H
03H
04H

(SECOND INPUT)

8700
8701
8702

04H
06H
08H

OUTPUT:

PROGRAM:

27

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

ADDRES

OPCODE

28

MNEMONICS

COMMENDS

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

8500

C3

CLR C

8501

7C 03

MOV R4,#03

8503

90 86 00

MOV

8506
8508

A8 82
A9 83

850A

90 8610

850D

AA 82

DPTR,#8610
MOV R2,DPL

850F

AB 83

MOV R3,DPH

8511

90 87 00

MOV

8514

C0 82

8516

C0 83

PUSH DPH

8518

88 82

MOV DPL,R0

851A

89 83

MOV DPH,R1

851C

E0

MOVX A,@DPTR

851D

F5 F0

MOV F0,A

851F

A3

INC DPTR

8520

A8 82

MOV R0,DPL

8522

A9 83

MOV R1,DPH

8524

8A 82

MOV DPL,R2

8526

8B 83

MOV DPH,R3

8528

E0

MOVX A,@DPTR

8529

35 F0

ADDC A,B

852B

A3

INC DPTR

852C

AA 82

MOV R2,DPL

852E

AB 83

MOV R3,DPH

8530

D0 83

POP DPH

8532

D0 82

POP DPL

8534

F0

MOVX @DPTR,A

8535

A3

INC DPTR

8536

DC DC

DJNZ R4,LOOP

8538

80 FE

DPTR,#8600
MOV R0,DPL
MOV R1,DPH
MOV

DPTR,#8700
LOOP:
PUSH DPL

HERE:

SJMP HERE

6.6 LARGEST ELEMENT IN AN ARRAY


THEORY:
29

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

Let Internal memory location (say 40H) has the biggest number i.e.
zero.
Now the biggest number in internal memory location is stored in
memory as the Result.
Now compare the first number with internal memory location. If it is
greater, move it to internal memory
INPUT:
8600
8605

05H, 09H, 06H, 05H, 03H


07H, 0AH, 0BH, 7FH ,04H

OUTPUT:

860A

7FH

PROGRAM:
ADDRES

OPCODE

MNEMONICS

S
8500

90

86

MOV DPTR,#8600

8503

00
75

40

MOV 40,#00

8506
8508
8509

00
7D 0A
E0
B5
40

MOV R5,#0A
LOOP2: MOVX A,@DPTR
CJNE A,40,LOOP1

850C
850D
850F
8511
8512
8514
8516
8518

08
A3
DD F9
E5 40
F0
80 FE
40 F6
F5 40
80 F2

LOOP3: INC DPTR


DJNZ R5,LOOP2
MOV A,40H
MOVX @DPTR,A
HLT: SJMP HLT
LOOP1: JC LOOP3
MOV 40H,A
SJMP LOOP3

6.7

COMMENDS

PROGRAMS FOR SORTING

THEORY:
30

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

The sorting technique used here is relatively simple. First consider the first two
numbers of the array.

INPUT:
8600

05H, 08H, 07H, 06H, 04H

OUTPUT:

8600

04H, 05H, 06H, 07H, 08H

PROGRAM:
ADDRES

OPCODE

S
8500
8502
8503
8504

78 05
E8
F9
90
86

8507
8509
850B
850C
850E
850F
8510

00
C0 83
C0 82
E0
F5 F0
A3
E0
B5
F0

8513
8515
8517
8519
851A
851B
851D
851E
8520
8522

00
50 09
D0 82
D0 83
F0
A3
E5 F0
F0
D9 E7
D8 E0
80 FE

MNEMONICS

LOOP3:

MOV R0,#05
MOV A,R0
MOV R1,A
MOV DPTR,#8600

LOOP2:

PUSH DPH
PUSH DPL
MOVX A,@DPTR
MOV F0,A
INC DPTR
MOVX A,@DPTR
CJNE A,F0,LOOP1

LOOP1:

JNC LOOP
POP DPL
POP DPH
MOVX @DPTR,A
INC DPTR
MOV A,F0
MOVX @DPTR,A
DJNZ R1,LOOP2
DJNZ R0,LOOP3
SJMP HERE

LOOP:
HERE:

COMMENDS

6.8 BCD TO HEX CONVERSION


THEORY:
8 bit two digit BCD number system into Hexadecimal number system.
Binary coded decimal (BCD) is a system of writing numerals that assigns a
four-digit binary code to each digit 0 through 9 in a decimal (base-10)
numeral.
31

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

INPUT:
8600
OUTPUT:
8601

15H
0FH

PROGRAM:
ADDRES

OPCODE

MNEMONICS

S
8500

90 86

MOV DPTR,#8600

8503
8504
8505
8507
8508
8509
850A
850C
850D
850E

00
E0
FD
54 F0
C4
F9
ED
54 0F
FA
E9
75 F0

MOVX A,@DPTR
MOV R5,A
ANL A,#F0
SWAP A
MOV R1,A
MOV A,R5
ANL A,#0F
MOV R2,A
MOV A,R1
MOV F0,#0A

8511
8512
8513
8514
8515

0A
A4
2A
A3
F0
80 FE

MUL AB
ADD A,R2
INC DPTR
MOVX @DPTR,A
HERE:
SJMP HERE

COMMENDS

6.9 HEX TO BCD CONVERSION


THEORY:
8 bit two digit Hexadecimal number system into BCD number system.

The hexadecimal number system (also called base-16) is a number system


that uses 16 unique symbols to represent a particular value. Those symbols
are 0-9 and A-F.

INPUT:
8600

32

0FH

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

OUTPUT:

8601
8602

00H
15H

PROGRAM:
ADDRES

OPCODE

S
8500
8503
8504
8507
8508
8509
850A
850C
850F
8510
8511
8513
8514
8515

90 86 00
E0
75 F0 64
84
A3
F0
E5 F0
75 F0 0A
84
C4
25 F0
A3
F0
80 FE

MNEMONICS

COMMENDS

MOV DPTR,#8600
MOVX A,@DPTR
MOV F0,#64
DIV AB
INC DPTR
MOVX @DPTR,A
MOV A,F0
MOV F0,#0A
DIV AB
SWAP A
ADD A,F0
INC DPTR
MOVX @DPTR,A
HERE: SJMP HERE

6.10 ASCII TO HEX CONVERSION


THEORY:
8 bit two digit ASCII l number system into hex decimal number system.
Acronym for the American Standard Code for Information Interchange.
Pronounced ask-ee, ASCII is a code for representing English characters as
numbers, with each letter assigned a number from 0 to 127

INPUT:
8600
OUTPUT:
8700

0AH
41H

PROGRAM:

33

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

ADDRES
S
8500

OPCODE

MNEMONICS

90 86

8503
8504
8505
8508
8509
850A
850C
850E
850F
8511

00
E0
F8
94
50
E8
24
80
E8
24
90

8514
8515

00
F0
80 FE

0A
05
30
03
37
87

COMMENDS

MOV DPTR,#8600
MOVX A,@DPTR
MOV R0,A
SUBB A,#0A
JNC LOOP1
MOV A,R0
ADD A,#30
SJMP LOOP
LOOP1: MOV A,R0
ADD A,#37
LOOP:
MOV DPTR,#8700
MOVX @DPTR,A
SJMP HERE

HERE:

6.11 SQUARE ROOT OF A GIVEN NUMBER


THEORY:
A square root of a number a is a number y such that y2 = a, or, in other
words, a number y whose square (the result of multiplying the number by
itself, or y y) is a.[1] For example, 3 is a square root of 09 because 3 2 = 09.
8 bit square root number for follows

INPUT:
8600
OUTPUT:
8700

09H
03H

PROGRAM:
ADDRES

34

OPCODE

MNEMONICS

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

S
8500
8503
8504
8505
8507
8508
850A
850B
850C
850E
850F
8511
8512
8514
8517
8518
8519

S
90 86 00
E0
F9
7A 01
E9
8A F0
84
FB
AC F0
9A
60 03
0A
80 F3
90 87 00
EB
F0
80 FE

MOV DPTR,#8600
MOVX A,@DPTR
MOV R1,A
MOV R2,#01
LOOP: MOV A,R1
MOV F0,R2
DIV AB
MOV R3,A
MOV R4,F0
SUBB A,R2
JZ RESULT
INC R2
SJMP LOOP
RESULT: MOV DPTR,#8700
MOV A,R3
MOVX @DPTR,A
HERE:
SJMP HERE

6.12 PARITY GENERATION


THEORY:

Even parity bit and odd parity bit. When using even parity, the parity bit is set
to 1

INPUT:

8600

02H, 04H,06H, 08H

OUTPUT:
8700
PROGRAM:

ADDRES
S
8500
8503
8504
8505
8507
8509
850A
850C
850D
850F
8510

OPCODE
90

01H
MNEMONICS

86

MOV DPTR,#8600

00
E0
FD
7A 00
7B 08
13
70 01
0A
DB FA
EA
75
F0

MOVX A,@DPTR
MOV R5,A
MOV R2,#00
MOV R3,#08
RRC A
JNZ LOOP2
INC R2
DJNZ R3,LOOP1
MOV A,R2
MOV F0,#02

L00P1 :

LOOP2 :

02

35

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

8513
8514
8516
8518
851A
851C
851E
8520
8522
8525
8526
8528

84
E5 F0
70 06
74 01
7F FF
80 04
74 00
7F 00
90
87
00
F0
8F 90
80 FE

LOOP4 :

DIV AB
MOV A,F0
JNZ LOOP3
MOV A,#01
MOV R7,#FF
SJMP LOOP4
MOV A,#00
MOV R7,#00
MOV DPTR,#8700

HERE :

MOVX @DPTR,A
MOV 90,R7
SJMP H

LOOP3 :

6.13 TIMER AND COUNTER


THEORY:
Assume XTAL = 11.0592 MHz, find the frequency of the square wave
generated on pin P1.0 in the following program
In mode 2 we do not need to reload TH since it is auto-reload. Now (256 - 05)
1.085 us =251 1.085 us = 272.33 us is the high portion of the pulse.
Since it is a 50% duty cycle square wave, the period T is twice that; as a result
T = 2 272.33 us = 544.67 us and the frequency =1.83597 kHz
PROCEDURE:
Execute the program. Output generate the square wave J4 connector P1.0 in
terminated

PROGRAM:
ADDRES

OPCODE

MNEMONICS

S
8500

75

89

MOV TMOD,#20

8503

20
75

8D

MOV TH1,05

8506
8508

05
D2 8E
30
8F

850B
850D
850F

FD
B2 90
C2 8F
80 F7

36

BACK:

SETB TR1
JNB TR1,BACK
CPL 90
CLR TF1
SJMP BACK

COMMENT
T1/8-bit/auto reload
TH1 = 5
Start The Timer 1
Till Timer Rolls Over
P1.0 to hi, lo
Clear Timer 1 flag

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

6.14 SENDING DATA THROUGH SERIAL PORT BETWEEN CONTROLLER


KITS

THEORY:
8051 to transfer the letter A serially at 9600 baud continuously. Use 8-bit
data and 1 stop bit.
PROCEDURE:
Through open the PC hyper terminal window (serial window) .set 9600 BUAD
RATE
PS2 KIT press B set 9600 baud rate value after execution program.

INPUT: IN TRANSMITTER KIT

850B:

41

TRANSMITTER PROGRAM:

9100

758921

MOV TMOD,#21H

9103

758DF5

MOV TH1,#0F5H

9106

759852

MOV SCON,#52H

9109

758700

MOV PCON,#00H

37

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

910C

D28E

SETB TR1

910E

7445

MOV A, #45H

9110

3114

ACALL TRANS

9112

80FE

HALT : SJMP HALT

9114

F599

TRANS: MOV SBUF,A

9116

3099FD

WAIT : JNB TI,WAIT

9119

C299

CLR TI

911B

22

RET

OUTPUT: IN RECEIVER KIT

8700:

41

RECEIVER PROGRAM:

9100

758921

MOV TMOD,#21H

9103

758DF5

MOV TH1,#0F5H

9106

759852

MOV SCON,#52H

9109

758700

MOV PCON,#00H

910C

909200

MOV DPTR,#9200H

910F

D28E

SETB TR1

9111

3098FD

9114

E599

MOV A,SBUF

9116

C298

CLR RI

9118

C28E

CLR TR1

38

WAIT :

JNB RI,WAIT

PS 8051 USER MANUAL

PS-8051

PANTECH PROLABS INDIA PVT.LTD

911A

F0

MOVX @DPTR,A

911B

A3

INC DPTR

911C

80FE

HALT :

SJMP HALT

Procedure:
1. Connect the two microcontroller kit using RS232 cable
2. Enter the transmitter program in 1ST microcontroller kit & receiver
program in 2nd
microcontroller kit.
3. First run the receiver program in kit2 and then run the transmitter program
in kit1.
4. After executing the transmitter program, reset the kit and go to location
8700h
5. The transferred datas yes (ASCII) value are stored from 8400h onwards
in the kit2.

39

PS 8051 USER MANUAL

PS-8051

You might also like