8051 manual

46
PANTECH PROLABS INDIA PVT.LTD 8051 MICROCONTROLLER PS – TRAINER-8051B USER MANUAL 1 PS – 8051 USER MANUAL PS- 8051

Upload: prithivi-raj

Post on 13-Dec-2015

33 views

Category:

Documents


6 download

DESCRIPTION

8051 programs

TRANSCRIPT

Page 1: 8051 Manual

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

Page 2: 8051 Manual

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 072.2 MAPPING OF DEVICES2.3 POWER SUPPLY DETAILS2.4 KEYBOARD DETAILS

CHAPTER – 3: COMMANDS AND KEYS

3.1 RESET 133.2 H (HELP MENU) 13

CHAPTER – 4: OPERATING INSTRUCTIONS

4.1 POWER ON 144.2 PROGRAM ENTRY USING ASSEMBLER 154.3 ENTERING MNEMONICS 164.4 DISASSEMBLER

CHAPTER 5: PROGRAMMING DETAILS

5.1 8051 OVERVIEW 20 5.2 REGISTERS 5.3 BREAKPOINT

2 PS – 8051 USER MANUAL PS-8051

Page 3: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

CHAPTER 6: EXAMPLE PROGRAMS

6.1 ADDITION 22 6.2 SUBTRACTION 236.3 MULTIPLICATIONS 246.4 DIVISION 256.5 MULTI BYTE ADDITION 266.6 LARGEST ELEMENT IN AN ARRAY 286.7 PROGRAMS FOR SORTING 296.8 BCD TO HEX CONVERSION 306.9 HEX TO BCD CONVERSION 316.10 ASCII TO HEX CONVERSION 326.11 SQUARE ROOT OF A GIVEN NUMBER 336.12 PARITY GENERATION 34

3 PS – 8051 USER MANUAL PS-8051

Page 4: 8051 Manual

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 Board2) 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

Page 5: 8051 Manual

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

Page 6: 8051 Manual

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

Page 7: 8051 Manual

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

Page 8: 8051 Manual

VCC

PA2PA0

J1

20-PIN FRC

13579

1113151719

2468101214161820

PB2PB0PA6PA4

P3.7P3.6PB6PB4

VCC

P1.1

GNDGND

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

P3.0P1.6P1.4P1.2P1.0

J4

20-PIN FRC

13579

1113151719

2468101214161820

P3.4P3.2

VCC GNDGND

CS7PC7PC5PC3PC1

PC2PC0

CS11CS9

J3

20-PIN FRC

13579

1113151719

2468101214161820

CS8CS6PC6PC4

CS10

PA5PA7

PA3PA1

PB7

PB3PB5

PB1

GNDGND

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

U2CONTL REGPORT APORT BPORT C

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

50 PIN EXPANSION CONNECTOR:

8 PS – 8051 USER MANUAL PS-8051

Page 9: 8051 Manual

D5

D1D3

A5

D7A1A3

VCC

A12

A8A10

A14PCLKRST

J6

2468101214161820222426283032343638404244464850

13579

1113151719212325272931333537394143454749

A11

A7A9

A13A15

WR

INT1

CS9

ALEPSENCS7

RD

INT0

CS8

EACS6

TXDRXDVCC GND

D6

D0D2D4

GND

A6

A0A2A4

PANTECH PROLABS INDIA PVT.LTD

The 50 Pin FRC connector is used to interconnect with the Interface cards like 8255, 8279, 8253/8251, 8259 ….

KEYBOARD CONNECTOR:

PIN NO SIGNAL

1,2 KEYBOARD CLOCK

8,6 DATA

5 VCC

3 GND

9 PS – 8051 USER MANUAL

5 V

J P 1

P S 2

1

2

5

8

6

3

R 1 31 K

P C 0 7 P C 0 6

R 1 21 K

PS-8051

Page 10: 8051 Manual

P1

594837261

NC

NC

NC

CTS

TXD

NC

NC

GND

RXD

PANTECH PROLABS INDIA PVT.LTD

9PIN ‘D’ TYPE (FEMALE):

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

Page 11: 8051 Manual

E

D1D0

D3D2

D5D4

D7D6

RWRS

JP1

2X16 LCD

123456789

10111213141516

LCD

LCD

R110K

13

2

LCD

PANTECH PROLABS INDIA PVT.LTD

LCD CONNECTOR

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

System Mapping: I/O mapped I/O.

SOCKET.NO FUNCTION ADDRESS CONNECTOR.NO

---- LCD COMMAND LCD DATA

4020 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

POWER SWITCHSupply Turned OFF

Supply Turned ON

11 PS – 8051 USER MANUAL PS-8051

Page 12: 8051 Manual

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

12 PS – 8051 USER MANUAL PS-8051

Page 13: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

U <BEG> <END> 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.

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

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:

Type the Mnemonics

Enter Key

13 PS – 8051 USER MANUAL PS-8051

PAN TECH

8051

PAN TECH▁a8500

8500:

mov a,#12

Page 14: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

Type the Mnemonics

Enter Key

EXIT COMMAND:

Double enter you get the main menu

PROGRAM ENTRY USING OPCODE:

Modify External memory

Enter the starting Address

Enter Key

Type the opcode

Type the opcode

Enter the space bar key

EXIT COMMAND: Double enter you get the main menu ENTERING ‘G ‘EXECUTING COMMAND

Enter starting address

14 PS – 8051 USER MANUAL PS-8051

8502:

mov b,#12

Press H for help▁

Press H for help▁m8500

8500:

4A ▁ 8500:

4A 74

8501:

56 12

Press H for help▁G8500

Page 15: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

Enter key After executing display

Executing display

4.3 ENTERING RESULT COMMAND:

Enter the Memory Location

Enter Key

You Get the Output8-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:Enter the Starting Address

Enter Key

Enter the Space Bar Key

Enter the space bar key

15 PS – 8051 USER MANUAL PS-8051

Press H for help▁m <address>

<Address>:

24 ▁

Press H for help▁d8500

8500: 74 12

MOV A,#12

8502: 75 0B 12

MOV B,#12

Page 16: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

M (MODIFY EXTERNAL MEMORY):

Using this command the user can display/modify any external memory address.

Modify External memory

Enter the starting Address

R (REGISTER DISPLAY)

16 PS – 8051 USER MANUAL PS-8051

Press H for help▁m8500

Page 17: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

EXAMPLE:Enter the starting Address

Enter Key

Enter the Space Bar Key

Enter the Space Bar Key till the end of Registers

T (TRANSFER COMMAND)

17 PS – 8051 USER MANUAL PS-8051

Press H for help▁RA

A = FF

A = FF

B = FF

Page 18: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

Enter Key

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.

B (BAUD RATE) Press the ‘B ‘

Enter the Space Bar Key to change Baud Rate

Enter Key Set the 2400 Baud Rate

18 PS – 8051 USER MANUAL PS-8051

Press H for help▁t8500 8600 9000

T: 8500 to 9000▁

! Normal Mode!

BAUD RATE : @0150

@150

BAUD RATE : @0150

@2400

Page 19: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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.

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

19 PS – 8051 USER MANUAL PS-8051

Page 20: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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

20 PS – 8051 USER MANUAL PS-8051

Page 21: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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.

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 method2) 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

21 PS – 8051 USER MANUAL PS-8051

Page 22: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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:

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:

5.3 BREAKPOINT:

22 PS – 8051 USER MANUAL PS-8051

Chip select ADDRESS

CS6 4040 – 405f

CS7 4060 – 407F

CS8 4080 – 409F

CS9 40A0 – 40BF

CS10 40C0 – 40DF

Page 23: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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.

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:

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:

23 PS – 8051 USER MANUAL PS-8051

BREAK POINT SUBROUTINE ADDRESS 00BB

Page 24: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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:

24 PS – 8051 USER MANUAL PS-8051

Page 25: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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:

25 PS – 8051 USER MANUAL PS-8051

Page 26: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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

26 PS – 8051 USER MANUAL PS-8051

Page 27: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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)

27 PS – 8051 USER MANUAL PS-8051

Page 28: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

8602 04H

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

OUTPUT: 8700 04H 8701 06H 8702 08H

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

28 PS – 8051 USER MANUAL PS-8051

Page 29: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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

29 PS – 8051 USER MANUAL PS-8051

Page 30: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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

30 PS – 8051 USER MANUAL PS-8051

Page 31: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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.

31 PS – 8051 USER MANUAL PS-8051

Page 32: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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.

32 PS – 8051 USER MANUAL PS-8051

Page 33: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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.

33 PS – 8051 USER MANUAL PS-8051

Page 34: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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:

34 PS – 8051 USER MANUAL PS-8051

Page 35: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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

35 PS – 8051 USER MANUAL PS-8051

Page 36: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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

36 PS – 8051 USER MANUAL PS-8051

Page 37: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

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

37 PS – 8051 USER MANUAL PS-8051

Page 38: 8051 Manual

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

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

38 PS – 8051 USER MANUAL PS-8051

Page 39: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

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

39 PS – 8051 USER MANUAL PS-8051

Page 40: 8051 Manual

PANTECH PROLABS INDIA PVT.LTD

5. The transferred data’s “yes” (ASCII) value are stored from 8400h onwards in the kit2.

40 PS – 8051 USER MANUAL PS-8051