You are on page 1of 38

PANTECH PROLABS INDIA PVT.

LTD

8051 MICROCONTROLLER
PS – TRAINER-8051B

USER MANUAL

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

1
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

TABLE OF CONTENTS

CHAPTER 1: INTRODUCTION PAGE NO


1.1 WELCOME 04

1.2 PS – 8086 BOARD OVERVIEW 05

1.3 PS – 8086 SPECIFICATIONS 06

CHAPTER – 2: SYSTEM DESCRIPTION


2.1 HARDWARE 07
2.2 MAPPING OF DEVICES
2.3 POWER SUPPLY DETAILS
2.4 KEYBOARD DETAILS

CHAPTER – 3: COMMANDS AND KEYS


3.1 RESET 13
3.2 H (HELP MENU) 13
CHAPTER – 4: OPERATING INSTRUCTIONS
4.1 POWER ON 14
4.2 PROGRAM ENTRY USING ASSEMBLER 15
4.3 ENTERING MNEMONICS 16
4.4 DISASSEMBLER

CHAPTER 5: PROGRAMMING DETAILS

5.1 8051 OVERVIEW 20


5.2 REGISTERS
5.3 BREAKPOINT

2
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

CHAPTER 6: EXAMPLE PROGRAMS

6.1 ADDITION 22
6.2 SUBTRACTION 23
6.3 MULTIPLICATIONS 24
6.4 DIVISION 25
6.5 MULTI BYTE ADDITION 26
6.6 LARGEST ELEMENT IN AN ARRAY 28
6.7 PROGRAMS FOR SORTING 29
6.8 BCD TO HEX CONVERSION 30
6.9 HEX TO BCD CONVERSION 31
6.10 ASCII TO HEX CONVERSION 32
6.11 SQUARE ROOT OF A GIVEN NUMBER 33
6.12 PARITY GENERATION 34

3
PS – 8051 USER MANUAL

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) PS-8051 Board
2) Sample device (NXP 89V51RD2)
3) Cross cable (RS232)
4) 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

4
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.

5
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

6
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:

STARTADDRESS ENDADDRESS SOCKET NO IC USED TOTAL CAPACITY


0000 7FFF U3 27256 32 K BYTE

ALLOCATION OF RAM:

STARTADDRESS ENDADDRESS SOCKET NO IC USED TOTAL CAPACITY


8000 FFFF U6 62256 32 K BYTE

7
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 CONNECTOR.NO

CONTL REG 4003


U2 PORT A 4000 J1
PORT B 4001
PORT C 4002

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 J4 J3

PA0 1 2 PA1 P1.0 1 2 P1.1 PC0 1 2 PC1


PA2 3 4 PA3 P1.2 3 4 P1.3 PC2 3 4 PC3
PA4 5 6 PA5 P1.4 5 6 P1.5 PC4 5 6 PC5
PA6 7 8 PA7 P1.6 7 8 P1.7 PC6 7 8 PC7
PB0 9 10 PB1 P3.0 9 10 P3.1 CS6 9 10 CS7
PB2 11 12 PB3 P3.2 11 12 P3.3 CS8 11 12 CS9
PB4 13 14 PB5 P3.4 13 14 P3.5 CS10 13 14 CS11
PB6 15 16 PB7 P3.6 15 16 P3.7 15 16
17 18 GND 17 18 GND 17 18 GND
19 20 GND 19 20 GND 19 20 GND
VCC VCC VCC

20-PIN FRC 20-PIN FRC 20-PIN FRC

50 PIN EXPANSION CONNECTOR:

8
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 1 2
D0 3 4 D1VCC
D2 5 6 D3
D4 7 8 D5
D6 9 10 D7
A0 11 12 A1
A2 13 14 A3
A4 15 16 A5
A6 17 18 A7
A8 19 20 A9
A10 21 22 A11
A12 23 24 A13
A14 25 26 A15
PCLK 27 28
RST 29 30
31 32 INT0
INT1 33 34
35 36 RD
WR 37 38
ALE 39 40 EA
PSEN 41 42 CS6
CS7 43 44 CS8
CS9 45 46
RXD 47 48 TXD
VCC 49 50 GND

KEYBOARD CONNECTOR:
5V

R13 R12
1K 1K
PS2
5

PC07 2 8 PC06

1 6

JP1
3

PIN NO SIGNAL

1,2 KEYBOARD CLOCK

8,6 DATA

5 VCC

3 GND
9
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

9PIN ‘D’ TYPE (FEMALE):

NC
NC
P1
1 RXD
6
2
7 CTS
3
8
4 TXD
9
5
NC
NC
NC
GND

Universal Synchronous/ Asynchronous Receiver/ Transmitter.

RS232 bridge converter

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

10
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

LCD CONNECTOR

LCD

JP1
1
1
2 LCD 2
3 RS
4 RW 10K
5 E R1
6 D0
7 3
D1
8 D2
9 D3
10 D4
11 D5
12 D6
13 D7
14
15
16

2X16 LCD LCD

Device used: 16 × 2 / 20 × 4 LCD module

System Mapping: I/O mapped I/O.

SOCKET.NO FUNCTION ADDRESS CONNECTOR.NO

LCD COMMAND 4020


---- LCD DATA 4021 -----

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

11
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

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 H (Help Menu)


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
B BAUD RATE
D <BEG> DISASSEMBLE
E <BEG> <END> EXAMINE
G <BEG> EXECUTE
H HELP COMMANDS
I <ADDR> INTERNAL RAM
L <OFFSET> DOWNLOAD
M <ADDR> MODIFY
N NORMAL MODE
Q QUIT

R <REG> REGISTER DISPLAY


S SERIAL MODE
T <START> <END> <DS> BLOCK TRANSFER
U <BEG> <END> UP LOAD

12
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

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

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:
mov b,#12
13
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

Type the Mnemonics

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 Enter the starting Address


▁m8500

Enter Key

8500:
4A ▁

8500: Type the opcode


4A 74

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

14
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

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>: You Get the Output


8-Bit Data
24 ▁

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

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

15
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

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 Press Enter Key.
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 8500
End address 8600
Destination address 9000

Press H for help


▁t8500 8600 9000
16
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

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 Set the 2400 Baud Rate


BAUD RATE :
150, 300, 600, 1200, 2400, 4800, 9600. When using the serial Communication.

I (MODIFY INTERNAL MEMORY)

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.

17
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

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 OPCODES MNEMONICS


8500 74 12 MOV A,#12
8502 24 12 ADD A,#12
8504 90 45 00 MOV DPTR,#8600
8507 F0 MOVX @DPTR,A
8508 80 FE SJMP 8508

18
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 OPCODES MNEMONICS


8500 74 12 MOV A,#12
8502 24 12 ADD A,#12
8504 90 86 00 MOV DPTR,#8600
8507 F0 MOVX @DPTR,A
8508 80 FE 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

 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.

19
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 programmer’s 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:

20
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

Program EPROM : 0000 – 7FFF


External user RAM : 8000 – 8500 (for monitor program variables).
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 ADDRESS


CS6 4040 – 405f

CS7 4060 – 407F


CS8 4080 – 409F
CS9 40A0 – 40BF
CS10 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:


21
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

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:


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.

INPUT:
 MOV A,# 13
 ADD A,#14
OUTPUT:
 8600 27H

PROGRAM:

ADDRESS OPCODES MNEMONICS COMMENTS


8500 74 13 MOV A,#13 Give 8 bit first data in A register

8502 24 14 ADD A,#14 Give 8 bit second data in acc move

8504 90 86 00 MOV DPTR,#8600 Store in 8600 memory location

22
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

8507 F0 MOVX @DPTR,A Store the value acc move

8508 80 FE HERE: SJMP HERE End

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.

INPUT:
 MOV A,# 20
 SUBB A,#10
OUTPUT:
 8600 10H

PROGRAM:

ADDRESS OPCODES MNEMONICS COMMENDS


8500 74 20 MOV A,#20 Give 8 bit first data in A register

8502 94 10 SUBB A,#10 Give 8 bit second data in acc move

8504 90 86 00 MOV DPTR,#8600 Store in 8600 memory location

8507 F0 MOVX @DPTR,A Store the value acc move

8508 80 FE HERE: SJMP HERE End

23
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:

ADDRESS OPCODES MNEMONICS COMMENDS


8500 74 06 MOV A,#06
8502 75 F0 02 MOV F0,#02
8505 A4 MUL AB
8506 90 86 00 MOV DPTR,#8600
8509 F0 MOVX @DPTR,A
850A A3 INC DPTR
850B E5 F0 MOV A,F0
850D F0 MOVX @DPTR,A
850E 80 FE HERE: SJMP HERE
24
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 04H
 8601 00H

PROGRAM:

ADDRESS OPCODES MNEMONICS COMMENDS


8500 74 08 MOV A,#08
8502 75 F0 02 MOV F0,#02
8505 84 DIV AB
8506 90 86 00 MOV DPTR,#8600
8509 F0 MOVX @DPTR,A
850A A3 INC DPTR
850B E5 F0 MOV A,F0

25
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

850D F0 MOVX @DPTR,A


850E 80 FE HERE: SJMP HERE

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 02H
 8601 03H (FIRST INPUT)
 8602 04H

 8610 02H
 8611 03H (SECOND INPUT)
 8612 04H

OUTPUT:
 8700 04H
 8701 06H
 8702 08H

26
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

PROGRAM:

ADDRESS OPCODES MNEMONICS COMMENDS


8500 C3 CLR C
8501 7C 03 MOV R4,#03
8503 90 86 00 MOV DPTR,#8600
8506 A8 82 MOV R0,DPL
8508 A9 83 MOV R1,DPH
850A 90 8610 MOV DPTR,#8610
850D AA 82 MOV R2,DPL
850F AB 83 MOV R3,DPH
8511 90 87 00 MOV DPTR,#8700
8514 C0 82 LOOP: PUSH DPL
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

27
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

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 HERE: SJMP HERE

6.6 LARGEST ELEMENT IN AN ARRAY

THEORY:

 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 05H, 09H, 06H, 05H, 03H
 8605 07H, 0AH, 0BH, 7FH ,04H

OUTPUT:
 860A 7FH

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENDS


8500 90 86 00 MOV DPTR,#8600
8503 75 40 00 MOV 40,#00
8506 7D 0A MOV R5,#0A
8508 E0 LOOP2: MOVX A,@DPTR
8509 B5 40 08 CJNE A,40,LOOP1
28
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

850C A3 LOOP3: INC DPTR


850D DD F9 DJNZ R5,LOOP2
850F E5 40 MOV A,40H
8511 F0 MOVX @DPTR,A
8512 80 FE HLT: SJMP HLT
8514 40 F6 LOOP1: JC LOOP3
8516 F5 40 MOV 40H,A
8518 80 F2 SJMP LOOP3

6.7 PROGRAMS FOR SORTING

THEORY:

 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:

ADDRESS OPCODE MNEMONICS COMMENDS


8500 78 05 MOV R0,#05
8502 E8 LOOP3: MOV A,R0
8503 F9 MOV R1,A
8504 90 86 00 MOV DPTR,#8600
8507 C0 83 LOOP2: PUSH DPH
8509 C0 82 PUSH DPL
850B E0 MOVX A,@DPTR
850C F5 F0 MOV F0,A

29
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

850E A3 INC DPTR


850F E0 MOVX A,@DPTR
8510 B5 F0 00 CJNE A,F0,LOOP1
8513 50 09 LOOP1: JNC LOOP
8515 D0 82 POP DPL
8517 D0 83 POP DPH
8519 F0 MOVX @DPTR,A
851A A3 INC DPTR
851B E5 F0 MOV A,F0
851D F0 MOVX @DPTR,A
851E D9 E7 LOOP: DJNZ R1,LOOP2
8520 D8 E0 DJNZ R0,LOOP3
8522 80 FE HERE: SJMP HERE

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.

INPUT:
 8600 15H
OUTPUT:
 8601 0FH

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENDS


8500 90 86 00 MOV DPTR,#8600
8503 E0 MOVX A,@DPTR
8504 FD MOV R5,A
8505 54 F0 ANL A,#F0
8507 C4 SWAP A
30
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

8508 F9 MOV R1,A


8509 ED MOV A,R5
850A 54 0F ANL A,#0F
850C FA MOV R2,A
850D E9 MOV A,R1
850E 75 F0 0A MOV F0,#0A
8511 A4 MUL AB
8512 2A ADD A,R2
8513 A3 INC DPTR
8514 F0 MOVX @DPTR,A
8515 80 FE HERE: SJMP HERE

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 0FH
OUTPUT:
 8601 00H
 8602 15H

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENDS


8500 90 86 00 MOV DPTR,#8600
8503 E0 MOVX A,@DPTR
8504 75 F0 64 MOV F0,#64
8507 84 DIV AB

31
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

8508 A3 INC DPTR


8509 F0 MOVX @DPTR,A
850A E5 F0 MOV A,F0
850C 75 F0 0A MOV F0,#0A
850F 84 DIV AB
8510 C4 SWAP A
8511 25 F0 ADD A,F0
8513 A3 INC DPTR
8514 F0 MOVX @DPTR,A
8515 80 FE 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 0AH
OUTPUT:
 8700 41H

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENDS


8500 90 86 00 MOV DPTR,#8600
8503 E0 MOVX A,@DPTR
8504 F8 MOV R0,A

32
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

8505 94 0A SUBB A,#0A


8508 50 05 JNC LOOP1
8509 E8 MOV A,R0
850A 24 30 ADD A,#30
850C 80 03 SJMP LOOP
850E E8 LOOP1: MOV A,R0
850F 24 37 ADD A,#37
8511 90 87 00 LOOP: MOV DPTR,#8700
8514 F0 MOVX @DPTR,A
8515 80 FE HERE: SJMP 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 32 = 09.
 8 bit square root number for follows

INPUT:
 8600 09H
OUTPUT:
 8700 03H

PROGRAM:

ADDRESS OPCODES MNEMONICS


8500 90 86 00 MOV DPTR,#8600
8503 E0 MOVX A,@DPTR
33
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

8504 F9 MOV R1,A


8505 7A 01 MOV R2,#01
8507 E9 LOOP: MOV A,R1
8508 8A F0 MOV F0,R2
850A 84 DIV AB
850B FB MOV R3,A
850C AC F0 MOV R4,F0
850E 9A SUBB A,R2
850F 60 03 JZ RESULT
8511 0A INC R2
8512 80 F3 SJMP LOOP
8514 90 87 00 RESULT: MOV DPTR,#8700
8517 EB MOV A,R3
8518 F0 MOVX @DPTR,A
8519 80 FE 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 01H
PROGRAM:

ADDRESS OPCODE MNEMONICS


8500 90 86 00 MOV DPTR,#8600
8503 E0 MOVX A,@DPTR
8504 FD MOV R5,A
8505 7A 00 MOV R2,#00
8507 7B 08 MOV R3,#08
8509 13 L00P1 : RRC A

34
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

850A 70 01 JNZ LOOP2


850C 0A INC R2
850D DB FA LOOP2 : DJNZ R3,LOOP1
850F EA MOV A,R2
8510 75 F0 02 MOV F0,#02
8513 84 DIV AB
8514 E5 F0 MOV A,F0
8516 70 06 JNZ LOOP3
8518 74 01 MOV A,#01
851A 7F FF MOV R7,#FF
851C 80 04 SJMP LOOP4
851E 74 00 LOOP3 : MOV A,#00
8520 7F 00 MOV R7,#00
8522 90 87 00 LOOP4 : MOV DPTR,#8700
8525 F0 MOVX @DPTR,A
8526 8F 90 MOV 90,R7
8528 80 FE HERE : SJMP H

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:

ADDRESS OPCODE MNEMONICS COMMENT


8500 75 89 20 MOV TMOD,#20 T1/8-bit/auto reload
35
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

8503 75 8D 05 MOV TH1,05 TH1 = 5


8506 D2 8E SETB TR1 Start The Timer 1
8508 30 8F FD BACK: JNB TR1,BACK Till Timer Rolls Over
850B B2 90 CPL 90 P1.0 to hi, lo
850D C2 8F CLR TF1 Clear Timer 1 flag
850F 80 F7 SJMP BACK

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:

36
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

9100 758921 MOV TMOD,#21H


9103 758DF5 MOV TH1,#0F5H
9106 759852 MOV SCON,#52H
9109 758700 MOV PCON,#00H
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
37
PS – 8051 USER MANUAL

PS-8051
PANTECH PROLABS INDIA PVT.LTD

9111 3098FD WAIT : JNB RI,WAIT


9114 E599 MOV A,SBUF
9116 C298 CLR RI
9118 C28E CLR TR1
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 data’s “yes” (ASCII) value are stored from 8400h onwards in the kit2.

38
PS – 8051 USER MANUAL

PS-8051

You might also like