You are on page 1of 32

Microcontroller And Interfacing(8051)

Practical File

Microcontroller And Interfacing(8051)

Practical File

Submitted To: Mr. Balwant Raj SG-11520 ECE-5thSem

Submitted By: Kirti

Introduction
A microcontroller is a computer-on-a-chip built for specific tasks such as displaying/receiving information through LEDs or remote controlled devices. 8051 introduced the world to the most revolutionary set of microcontrollers. Apart from 8051, 8052 and 8031 complete the 8051 family. The 8052 microcontroller has 256 bytes of RAM and 3 timers. Programs written for 8051 projects can be used for 8052 as well. The 8031 has all features of 8051 except that it is ROM-less. An external ROM that is as large as 64 k bytes can be programmed and added to this chip for execution. The main disadvantage of adding external ROM is that 2 out of 4 ports are used up leaving less for I/O operations. The 8051 is a Harvard architecture, single chip microcontroller (C) which was developed by Intel in 1980 for use in embedded systems. The official designation for the 8051 family is MCS 51. Intels original versions were popular in the 1980s and early 1990s, but has today largely been superseded by a vast range of faster and/or functionally enhanced 8051-compatible devices manufactured by more than 20 independent manufacturers including Atmel, Infineon Technologies (formerly Siemens AG), Maxim Integrated Products (via its Dallas Semiconductor subsidiary), NXP (formerly Philips Semiconductor), Nuvoton (formerly Winbond), ST Microelectronics, Silicon Laboratories (formerly Cygnal), Texas Instruments and Cypress Semiconductor.

Important Features: It provides many functions (CPU, RAM, ROM, I/O, interrupt logic, timer, etc.) in a single package 8-bit ALU, Accumulator and 8-bit Registers; hence it is an 8-bit microcontroller 8-bit data bus It can access 8 bits of data in one operation 16-bit address bus It can access 216 memory locations 64 KB (65536 locations) each of RAM and ROM On-chip RAM 128 bytes (data memory) On-chip ROM 4 kByte (program memory) Four byte bi-directional input/output port UART (serial port) Two 16-bit Counter/timers Two-level interrupt priority Power saving mode (on some derivatives)

Internal Architecture

The system bus connects all the support devices with the central processing unit. 8051 system bus composes of an 8 bit data bus and a 16 bit address bus and bus control signals. From the figure you can understand that all other devices like program memory, ports, data memory, serial interface, interrupt control, timers, and the central processing unit are all interfaced together through the system bus. RxD and TxD (serial port input and output) are interfaced with port 3.

Memory Organization

It has an internal program of 4K size and if needed an external memory can be added (by interfacing ) of size 60K maximum. So in total 64K size memory is available for 8051 micro controller. By default, the External Access (EA) pin should be connected Vcc so that instructions are fetched from internal memory initially. When the limit of internal memory (4K) is crossed, control will automatically move to external memory to fetch remaining instructions. If the programmer wants to fetch instruction from external memory only (bypassing the internal memory), then he must connect External Access (EA) pin to ground (GND). 8051 is capable of pipelining. Pipelining makes a processor capable of fetching the next instruction while executing previous instruction. Its something like multi-tasking, doing more than one operation at a time. 8051 is capable of fetching first byte of the next instruction while executing the previous instruction.

Pin-Out Diagram AndDescription

Pin-40 : Named as Vcc is the main power source. Usually its +5V DC. You may note some pins are designated with two signals (shown in brackets). Pins 32-39: Known as Port 0 (P0.0 to P0.7) In addition to serving as I/O port, lower order address and data bus signals are multiplexed with this port (to serve the purpose of external memory interfacing). This is a bi directional I/O port (the only one in 8051) and external pull up resistors are required to function this port as I/O. Pin-31:- ALE aka Address Latch Enable is used to demultiplex the address-data signal of port 0 (for external memory interfacing.) 2 ALE pulses are available for each machine cycle. Pin-30:- EA/ External Access input is used to enable or disallow external memory interfacing. If there is no external memory requirement, this pin is pulled high by connecting it to Vcc. Pin- 29:- PSEN or Program Store Enable is used to read signal from external program memory. Pins- 21-28:- Known as Port 2 (P 2.0 to P 2.7) in addition to serving as I/O port, higher order address bus signals are multiplexed with this quasi bi directional port. Pin 20:- Named as Vss it represents ground (0 V) connection.

Pins 18 and 19:- Used for interfacing an external crystal to provide system clock. Pins 10 17:- Known as Port 3. This port also serves some other functions like interrupts, timer input, control signals for external memory interfacing RD and WR , serial communication signals RxD and TxD etc. This is a quasi bi directional port with internal pull up. Pin 9:- As explained before RESET pin is used to set the 8051 microcontroller to its initial values, while the microcontroller is working or at the initial start of application. The RESET pin must be set high for 2 machine cycles. Pins 1 8:- Known as Port 1. Unlike other ports, this port does not serve any other functions. Port 1 is an internally pulled up, quasi bi directional I/O port.

Experiment No. 1
Aim: Write A Program To Perform Addition Of 10 Numbers Lying At Memory Location 3000H. Apparatus: Microcontroller Trainer Kit, Keil Software, PC or Laptop

Program:
Memory OpLocation Code
2010 2013 2015 90,00,30 78,09 E0

Label Mnemonics Operands


MOV MOV MOVX

Comments

2016 2017 2018

F9,1D A3 E0 Again

MOV INC MOVX

DPTR,#3000H Mov 16 bit addr to DPTR R0,#09H Mov 8 bit addr to register R0. A,@DPTR Move the contents of memory location which is saved at DPTR to Acc. R1,A Move the contents of Acc. To register R1 DPTR Increment DPTR A,@DPTR Move the contents of memory location which is saved at DPTR to Acc. Add The Contents Of Acc. And Register Move the contents of Acc. To register R1
Decrement register R0 and jump to label if no

2019 201A
201B

29 F9
D8,2A

ADD MOV
DJNZ

A,R1 R1,A
R0,Again

zero.

201D

80,F9

Here

SJMP

Here

End Of Program

Procedure:
1. Connect the power supply to the Micro controller Kit. 2. Load the data first 3. Then load the program starting from 2010H with opcodes. 4. To execute the program press the keys In the following sequence: RESET---GO----1st MEMORY LOCATION----FILL. 5. 'E' will be displayed indicating execution of program. 6. For getting the result ,press the keys as follows: 7. RESFT---EXMEM---MEMORY LOCATION WHERE THE RESULT IS STORED- NEXT 8. Switch off Die power supply.

Precautions:
1. Never touch the IC'S during operation. 2. Opcodes must be fed properly and carefully. 3. Program must be executed before result is displayed.

Flow Chart:
Start End Load DPTR With 16 bit Addr

Load Register R0 with 8 bit addr for count

Copy contents from memory to Acc.

Save it in R1 and increment DPTR for next number

If no zero

Add those numbers

Save the result in R1

Decrement the count

If Zero

Output:
Memory Address Data 3000H 3001H 3002H 3003H 3004H 3005H 3006H 3007H 3008H 3009H 02H 01H 03H 01H 04H 03H 01H 00H 05H 01H

Result: 16H at memory location 01H

Experiment No. 2
Aim: Write A Program To Perform Conversion Of 5 Numbers Into Its Nibbles Lying At Memory Location 3000H And Save The nibbles Apparatus: Microcontroller Trainer Kit, Keil Software, PC or Laptop

Program:
Memory Location 2010 2013 2015 2017 Op-Code 90,00,30 78,09 79,50 E0 Again Label Mnemonics MOV MOV MOV MOVX Operands Comments

2018 201A 201B 201C

54,01 09 F7 E0

ANL INC MOV MOVX

DPTR,#3000H Mov 16 bit addr to DPTR R0,#05H Mov 8 bit addr to register R0. R1,#50H Mov 8 bit addr to register R1 A,@DPTR Move the contents of memory location which is saved at DPTR to Acc. A,#0FH And the contents of ACC. With 0FH R1 Increment R1 @R1,A A,@DPTR Move the contents of ACC. To register R1 Move the contents of memory location which is saved at DPTR to Acc. And the contents of ACC. With F0H.

201D

54,F0

ANL

A,#F0H

201F 2020 2021 2022 2023

C4 09 F7 A3 D8,3C

SWAP INC MOV INC DJNZ

A R1 @R1,A DPTR R0,Again

Swap the bits of ACC. Increment R1 Move the contents of ACC. To register R1 Increment DPTR Decrement register R0 and jump to label if no zero. End Of Program

2026

80,F9

Here

SJMP

Here

Procedure:
1. Connect the power supply to the Micro controller Kit. 2. Load the data first 3. Then load the program starting from 2010H with opcodes. 4. To execute the program press the keys In the following sequence: RESET---GO----1st MEMORY LOCATION----FILL. 5. 'E' will be displayed indicating execution of program. 6. For getting the result ,press the keys as follows: 7. RESFT---EXMEM---MEMORY LOCATION WHERE THE RESULT IS STORED- NEXT 8. Switch off Die power supply.

Precautions:
1. Never touch the IC'S during operation. 2. Opcodes must be fed properly and carefully. 3. Program must be executed before result is displayed.

Flow Chart:
Start And ACC. With F0H

Load DPTR With 16 bit Addr

Swap A and increment DPTR

Load Register R0 with 8 bit addr for count

Save the Higher Nibble in R1

Load Register R1 with 8 bit addr to save result

If no zero

Decrement the count

Copy the contents of memory to accumulator End

If Zero

And ACC. With 0FH

Save the lower nibble in R1

Load The Number Again and increment R1

Output:

Inputs

Result:

Experiment No. 3
Aim: Write A Program To Find The Largest Number From An Array Of 8 Numbers Lying At Location 3000H Apparatus: Microcontroller Trainer Kit, Keil Software, PC or Laptop

Program:
Memory Location 2010 2013 2015 Op-Code 90,00,30 78,07 E0 Label Mnemonics MOV MOV MOVX Operands Comments

2017 2018 201A

F9 A3 E0 Again

MOV INC MOVX

DPTR,#3000H Mov 16 bit addr to DPTR R0,#07H Mov 8 bit addr to register R0. A,@DPTR Move the contents of memory location which is saved at DPTR to Acc. R1,A Move the contents of Acc. To Register R1 DPTR Increment DPTR A,@DPTR Move the contents of memory location which is saved at DPTR to Acc. Compare Acc. With Register R1 and jump to label Jump If carry to label Move the contents of ACC. To register R1

201B

B4,01,00

CJNE

A,#01H,Next

201C 201D

40,02 F9

Next

JC MOV

Largest R1,A

201F

D8,3B

Largest

DJNZ

R0,Again

2020

80,F9

Here

SJMP

Here

Decrement register R0 and jump to label if no zero. End Of Program

Procedure:
1. Connect the power supply to the Micro controller Kit. 2. Load the data first 3. Then load the program starting from 2010H with opcodes. 4. To execute the program press the keys In the following sequence: RESET---GO----1st MEMORY LOCATION----FILL. 5. 'E' will be displayed indicating execution of program. 6. For getting the result ,press the keys as follows: 7. RESFT---EXMEM---MEMORY LOCATION WHERE THE RESULT IS STORED- NEXT 8. Switch off Die power supply.

Precautions:
1. Never touch the IC'S during operation. 2. Opcodes must be fed properly and carefully. 3. Program must be executed before result is displayed.

Flow Chart:
Start

If No zero Load DPTR With 16 bit Addr

Decrement The Count

If zero Load Register R0 with 8 bit addr for count End

Copy the contents of memory to accumulator

Copy the contents to Register R1 and increment DPTR

Load Next Number

Compare Acc. With Register R1

Carry Jump If Carry

No carry

Output:

Inputs

Result: E6H at memory location 01H

Experiment No. 4
Aim: Write A Program To Perform Conversion Of 5 Numbers Into Its Nibbles Lying At Memory Location 3000H And Save The nibbles Apparatus: Microcontroller Trainer Kit, Keil Software, PC or Laptop

Program:
Memory Location 2010 2013 2015 2017 2018 Op-Code 90,00,30 78,60 79,50 7A,0A E0 Again Label Mnemonics MOV MOV MOV MOV MOVX Operands Comments

201A 201B 201D 201E 201F

54,01 60,0B F7 A3 09

ANL JZ MOV INC INC

DPTR,#3000H Mov 16 bit addr to DPTR R0,#60H Mov 8 bit addr to register R0. R1,#50H Mov 8 bit addr to register R1. R2,#0AH Move the contents of Acc. To Register R1 A,@DPTR Move the contents of memory location which is saved at DPTR to Acc. A,#01H And contents of Acc. With 01H Even Jump if zero to label @R1,A DPTR R1 Move the content to addr stored at R1 Increment DPTR Increment R1

2020 2022 2023 2024 2025

80,05 F6 08 A3 DA,1D Even

SJMP MOV INC INC DJNZ

Count @R0,A R0 DPTR R2, Again

Short jump to label Move the content to addr stored at R0 Increment Register R0 Increment DPTR Decrement register R2 and jump to label if no zero. End of program

Count

2027

80,F9

HERE SJMP

HERE

Procedure:
1. Connect the power supply to the Micro controller Kit. 2. Load the data first 3. Then load the program starting from 2010H with opcodes. 4. To execute the program press the keys In the following sequence: RESET---GO----1st MEMORY LOCATION----FILL. 5. 'E' will be displayed indicating execution of program. 6. For getting the result ,press the keys as follows: 7. RESFT---EXMEM---MEMORY LOCATION WHERE THE RESULT IS STORED- NEXT 8. Switch off Die power supply.

Precautions:
1. Never touch the IC'S during operation. 2. Opcodes must be fed properly and carefully. 3. Program must be executed before result is displayed.

Procedure For Keil Simulation:


1. Open Keil Vision. 2. Click The Project Tab And Click On New Vision Project. 3. Enter The Name And Destination For The Project. 4. Now Select The device For Which You Want To Write The Program (For Example: If You Are Programming For 8051 c Select AT89C51 From Atmel Devices Listed In The Windows. 5. Now Go To File And Click On New File And Save This File With .asm Extension i.e. for Assembly Language Programming. 6. In The Project Workspace Window- Right Click Target1 And Select Options For Target1 And Enter The Desired Crystal Frequency. 7. Now Write Your Program In Assembly Language And Go To Project Tab Clink On Build And Check For Errors And Warnings. 8. After Successful Simulation Go To Debug Tab And Click On Start/Stop Debug Session . 9. Press F5 To Run The Whole Program At Once And F11 To Run Each Instructions One After Other. 10.Check The Results In The Register Window i.e. On The Left Side Of The Disassembly Window.

Flow Chart:
Start

End Load 16 bit Addr in DPTR

Decreme nt R2

Load 8 bit Addr in R0,R1 and R2 Jump to Count

Increment DPTR and Register R0

Copy Contents from Memory to Acc.

Increment DPTR and Register R1

Save The Number In register R0

And Acc. With 01H

Save The Number In R1

Yes Even

Jump If Zero

No Odd

Output :
Inputs

Even Numbers (R0)

Odd Numbers (R1)

Experiment No. 5
Aim: Write A Program To Perform Conversion Of 5 Numbers Into Its Nibbles Lying At Memory Location 3000H And Save The nibbles Apparatus: Microcontroller Trainer Kit, Keil Software, PC or Laptop

Program:
Memory Location 2010 2012 2013 2015 2017 Op-Code 74,AA F5,90 78,FF 79,FF D9,F9 Count Here Again Label Mnemonics MOV MOV MOV MOV DJNZ Operands A,#0AAH P1,A R0,#FFH R1,#FFH R1,Here Comments Load Acc. With 8 bit addr Output Acc. data To Port1 Mov 8 bit addr to register R0. Mov 8 bit addr to register R1. Decrement register R1 and jump to label if no zero. Decrement register R0 and jump to label if no zero. Complement Acc. Jump To label End Of Program

2019

D8,2D

DJNZ

R0,Count

201B 201C 201E

F4 80,1C 80,F9 Here

CPL SJMP SJMP

A Again Here

Procedure:
1. Connect the power supply to the Micro controller Kit. 2. Load the data first 3. Then load the program starting from 2010H with opcodes. 4. To execute the program press the keys In the following sequence: RESET---GO----1st MEMORY LOCATION----FILL. 5. 'E' will be displayed indicating execution of program. 6. For getting the result ,press the keys as follows: 7. RESFT---EXMEM---MEMORY LOCATION WHERE THE RESULT IS STORED- NEXT 8. Switch off Die power supply.

Precautions:
1. Never touch the IC'S during operation. 2. Opcodes must be fed properly and carefully. 3. Program must be executed before result is displayed.

Flow Chart:
Start

Load Acc. With Data to Sent

Output data to Led's connected at Port1

Load Register R0 and R1 with 8 bit addr for appropriate delay

No Zero

Decremen t Count

If Gets Zero

Complement Acc.

Procedure For Keil Simulation:


1. Open Keil Vision. 2. Click The Project Tab And Click On New Vision Project. 3. Enter The Name And Destination For The Project. 4. Now Select The device For Which You Want To Write The Program (For Example: If You Are Programming For 8051 c Select AT89C51 From Atmel Devices Listed In The Windows. 5. Now Go To File And Click On New File And Save This File With .asm Extension i.e. for Assembly Language Programming. 6. In The Project Workspace Window- Right Click Target1 And Select Options For Target1 And Enter The Desired Crystal Frequency. 7. Now Write Your Program In Assembly Language And Go To Project Tab Clink On Build And Check For Errors And Warnings. 8. After Successful Simulation Go To Debug Tab And Click On Start/Stop Debug Session . 9. Press F5 To Run The Whole Program At Once And F11 To Run Each Instructions One After Other. 10.Check The Results In The Register Window i.e. On The Left Side Of The Disassembly Window.

You might also like