Top Banner
www.vidyarthiplus.com www.vidyarthiplus.com DATE: STUDY OF 8051 MICROCONTROLLER EXP NO.: AIM: To study the 8051 microcontroller. SPECIFICATIONS OF 8051 MICRICONTROLLER: Internal ROM or EPROM of 0 to 4k byte memory. Internal RAM of 128 bytes. 32 I/O pins arranged as four 8 bit ports P0-P3. Two 16 bit timer/counter T0 and T1. Two external and three internal interrupt source. Operating frequency 1MHZ to 16MHZ. Full duplex serial data receiver/transmitter SBUF. 8 bit CPU with register A and B. SPECIFICATION OF 89C51 MICROCONTROLLER: Compatible with 19CS-51 products. 8k byte of in-system re-programmable flash memory. Endurance-1000 write/erase cycle. Fully 3 level program memory lock. Fully static memory operation- 0Hz to 24Hz. 256x8 bit internal RAM. 32 programmable I/O lines. Three 16 bit timer/counter. 8 interrupt source. Programmable serial channel. Low power idle and power down modes. SPECIAL FUNCTION REGISTERS: The 8051 operations that do not use the internal 128-byte RAM addresses from 00h to 7fh are done by a group of specific internal registers, each called as special function registers. SFR may be addressed much like internal RAM using address from 80h to ffh.
136

STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

Dec 25, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: STUDY OF 8051 MICROCONTROLLER

EXP NO.:

AIM:

To study the 8051 microcontroller.

SPECIFICATIONS OF 8051 MICRICONTROLLER:

Internal ROM or EPROM of 0 to 4k byte memory.

Internal RAM of 128 bytes.

32 I/O pins arranged as four 8 bit ports P0-P3.

Two 16 bit timer/counter T0 and T1.

Two external and three internal interrupt source.

Operating frequency 1MHZ to 16MHZ.

Full duplex serial data receiver/transmitter SBUF.

8 bit CPU with register A and B.

SPECIFICATION OF 89C51 MICROCONTROLLER:

Compatible with 19CS-51 products.

8k byte of in-system re-programmable flash memory.

Endurance-1000 write/erase cycle.

Fully 3 level program memory lock.

Fully static memory operation- 0Hz to 24Hz.

256x8 bit internal RAM.

32 programmable I/O lines.

Three 16 bit timer/counter.

8 interrupt source.

Programmable serial channel.

Low power idle and power down modes.

SPECIAL FUNCTION REGISTERS:

The 8051 operations that do not use the internal 128-byte RAM addresses from 00h to

7fh are done by a group of specific internal registers, each called as special function registers.

SFR may be addressed much like internal RAM using address from 80h to ffh.

Page 2: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

IE REGISTER: (Interrupt enable)

The interrupt sources can be individually enable or disable by setting or

clearing a bit in SFR IE. And also interrupt register contains a global disable bit EA which

disable all interrupt at once.

SYMBOL POSITION NAME AND SIGNIFICANCE

EA IE.7 Enable all control bit. Cleared by s/w to disable all interrupts, Set

to 1 to permit individual interrupt.

- IE.6 (Reserved)

ET2 IE.5 (Reserved)

ES IE.4 Enable serial port interrupt

ET1 IE.3 Enable timer 1 overflow bit

EX1 IE.2 Enable external interrupt

ET0 IE.1 Enable timer 0 overflow bit

EX0 IE.0 Enable external interrupt 0

IP REGISTER: (Interrupt priority)

Each interrupt source can be individually programmed to one of two priority

by setting or clearing a bit in SFR.

SYMBOL POSITION NAME AND SIGNIFICANCE

- IP.7 Not implemented

- IP.6 Not implemented

PT2 IP.5 Reserved for future use

PS IP.4 Priority of serial port s/c by program

PT1 IP.3 Priority of timer 1 overflow bit

PX1 IP.2 Priority of external interrupt 1

PT0 IP.1 Priority of timer 0 overflow interrupt

PX0 IP.0 Priority of external interrupt 0

PCON REGISTER: (Power Mode Control)

It controls the data rate

SYMBOL POSITION NAME AND SIGNIFICANCE

SMOD PCON.7 Serial baud rate modify. Set 1 to double baud rate.

- PCON 6-4 Not defined (or ) not implemented

GF1 PCON.3 General purpose user flag bit 1

GF0 PCON.2 General purpose user flag bit 0

PD PCON.1 Power down bit

IDL PCON.0 Idle mode bit

Page 3: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

THE TIMER CONTROL (TCON):

TCON has control bits and flags for the timers in the upper nibble and control bits and

flag for the external interrupt in the lower nibble.

BIT SYMBOL FUNCTION

7 TF1 Timer1 overflow flag

6 TR1 Timer1 run control bit

5 TF0 Timer0 overflow flag set when timer rolls from 1s to 0 cleared when

processor vectors to execute interrupt service routine located at program

address 000Bh

4 TR0 Timer0 run control bit set to 1 program to enable timer to count cleared

to 0 by program by half timer

3 IE1 External interrupt 1 edge flag

2 IT1 External interrupt 1 signal type control bit

1 IE0 External interrupt 0 edge 7 flag

0 IT0 External interrupt 0 signal type control bit

THE TIMER MODE CONTROL (TMOD):

TMOD is dedicated to two timers and can be consider to the two duplicate 4 bit registers

each of which control actions of one of timers.

BIT SYMBOL FUNCTION

7/3 Gate Gating control

6/2 C/T Timer/counter selector

5/1 M1 Timer/counter operating mode select bit 1

set/cleared by program to select mode

4 /0 M0 Timer/counter operating mode select bit 0

set/cleared by program to select mode

THE SERIAL PORT CONTROL (SCON):

SCON controls data communication.

BIT SYMBOL FUNCTION

7 SM0 Serial port mode bit 0 set/cleared by program to select mode

6 SM1 Serial port mode bit 1 set/cleared by program to select mode

5 SM2 Multiprocessor communication bit

4 REN Receive enable bit

3 TB8 Transmitted bit 8

2 RB8 Received bit 8

1 TI Transmit interrupt flag

0 RI Receive interrupt flag

Page 4: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

SBUF:

SBUF is an 8 bit register dedicated for serial communication in 8051. It can be

accessed like any other register.

TRANSMISSION:

When a byte of data is to be transmitted via the TX0 pin. The SBUF is loaded with

data type.

RECEPTION:

When 8051 receives data serially via RXO pin of it, the 8051 de frames it. The start

and stop bit are separated out from a byte of data.

PORTS IN 8051 MICROCONTROLLER:

PORT 0:

Port 0 is an 8 bit port. It is bidirectional. As an output port it can risk high TTL inputs

when 1’s.

PORT 1:

Port 1 is an 8 bit bidirectional I/O port with internal pull ups. The ports pins are

externally being pulled low. Its source current(TTL) is high because of the internal pull ups.

PORT 2:

It is an 8 bit bidirectional I/O ports with internal for TTL inputs. It accesses to

external data memory that use 16 bit address.

PORT 3:

It is an 8 bit bidirectional port with internal pull ups. Each pin of the port will have

special features. The special features are given in the below table.

PIN ALTERNATIVE FUNCTIONS

P3.0 RXD(switch input port)

P3.1 TXD(serial output port)

P3.2 INTO(external interrupt 0)

P3.3 INT1(external interrupt 1)

P3.4 T0(Timer 0 external input)

P3.5 T1(Timer 1 external input)

P3.6 WR(external write data memory)

P3.7 RD(external read data memory)

XTAL1:

Page 5: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Input to the inverting oscillator amplifier and input to the internal clock operating

circuit.

XTAL2:

Output from the inverting oscillator amplifier.

PIN DIAGRAM OF 8051:

RESULT:

Thus the study of 8051 microcontroller is completed

Page 6: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 7: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: BASIC TUTORIAL FOR KEIL SOFTWARE

EXP NO.:

INTRODUCTION

This tutorial will assist you in writing your first 8051 Assembly language program

using the popular Keil Compiler. Keil offers an evaluation package that will allow the

assembly and debugging of files 2K or less. This package is freely available at their web site.

Keil’s website address is www.keil.com.The sample program included in the tutorial toggles

Ports 1 and 2 on the 8051. The compiled program has been tested using the 8051 board from

MicroDigitalEd.com. The program also works with other systems that have Port 1 and 2

available.

PROCEDURE :

STARTING A NEW ASSEMBLER PROJECT

1) Open Keil version4 from the Start menu.

2) Select New Project from the Project Menu.

3) Name the project ‘FILE NAME.a51’.

4) Click on the Save Button.

5) The device window will be displayed.

6) Select ‘atmel’ and double click on it.

7) Scroll down and select the 89C51 part and click ok.

8) Click File Menu and select New.

9) A new window will open up in the Keil IDE.

10) Type the assembly language program and save it.

Note: Do not add standard start-up code while creating assembler based project.

ADDING FILE TO PROJECT AND CREATING HEX FILE

Expand Target 1 in the Tree Menu.

1) Right click on target and select options for target.

2) Set the crystal oscillator frequency as 11.0592MHz.

3) Click on the output tab and select ‘create hex file’ and click ok.

CREATING A SOURCE FILE

1) Select source group1 on the tree menu and right click on it.

2) Click on add files to group ‘source group1’.

3) Select asm files, double click on the file name and add it to the source.

Page 8: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

BUILDING AND EXECUTING THE PROJECT

1) Select the project tab and click on build target.

2) Translate, build and rebuild the program.

3) In the Build Window it should report ‘0 Errors (s), 0 Warnings’.

4) Click on debug and select start/stop debug session.

5) Click ok for the evaluation mode.

6) Select view and click on memory windows and select any one memory

7) Give the address and press enter. And give the values.

8) For interfacing programs : Click on Peripherals. Select I/O Ports, Select Port 1.A

new window should port will pop up. This represents the Port and Pins.

9) Now debug and run the program.

10) Verify the output.

FOR C COMPILER PROJECTS

1. Add standard start-up code while creating assembler based project.

2. Name the project ‘FILE NAME.C’.

3. Remaining procedure is same as that of assembly language program.

RESULT:

Thus the study of Keil is done and the procedure is also explained.

Page 9: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

ADDITION AND SUBTRACTION

Addition

Direct & immediate Addressing

org 0000h

mov r1,#05h

mov a,#04h

add a,r1

end

Input: r1=0x02

a=0x03

Output: a= 0x05

Internal memory

Indirect Addressing

org 0000h

mov r1,53h

mov a,25h

mov r2,a

add a,r1

end

Input:

Memory I:53h I:25h

Data 05 06

Output: a=0x0B

Page 10: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: 8-BIT ADDITION AND SUBTRACTION USING 89C51

EXP NO.:

AIM:

To perform 8-bit addition and subtraction using 89C51 assembly language.

APPARATUS REQUIRED:

PC, Keil uvision 4 software

ALGORITHM FOR ADDITION

Direct Addressing Mode:

1) Assign a direct value to R1.

2) Assign another value to the accumulator.

3) Add the values present in both a and R1.

4) The result is stored back to the accumulator.

5) End

Register Addressing Mode:

1) Assign a value to the accumulator

2) Move the accumulator value to the register R1.

3) Assign another value to the accumulator.

4) Add the values present in accumulator and R1.

5) The result stored in the accumulator is moved to register R2.

6) End.

Indirect Addressing Mode (internal memory):

1) Assign an address (internal memory)to register R1.

2) Assign another address to the accumulator.

3) Move the value in the accumulator to register R2.

4) Add the values in accumulator and R2.

5) The result is stored in the accumulator.

6) End.

Page 11: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Register addressing

org 000h

mov a,#10h

mov r1,a

mov a,#03h

add a,r1

mov r2,a

end

Input: r1=0x10

r2=0x13

Output: a=0x13

External

Indirect Addressing

org 0000h

mov dptr,#1000h

movx a,@dptr

mov r0,a

inc dptr

movx a,@dptr

add a,r0

inc dptr

movx @dptr,a

end

Inputs Output

Memory x:1000h x:1001h x:1002h

Data 05 01 06

Page 12: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Indirect Addressing Mode (External memory):

1) Initialize the external memory with data pointer.

2) Move the memory content which is addressed by the dptr to accumulator.

3) Move the accumulator data to R0.

4) Increment the data pointer.

5) Move the data which is pointed by the dptr to accumulator.

6) Add the values int accumulator and R0.

7) Increment dptr.

8) Move the result from accumulator to the external memory.

9) End.

ALGORITHM FOR SUBTRACTION

Direct addressing mode:

1) Assign a direct value to R1.

2) Assign a value to the accumulator.

3) Subtract the values in accumulator and R1.

4) The result is stored in the accumulator.

5) End

Register addressing mode:

1) Assign a value to the accumulator.

2) Move the value from the accumulator to register R1.

3) Assign another value to the accumulator.

4) Subtract the values in a and r1.

5) Move the result in accumulator to the register R2.

6) End.

Indirect addressing mode (internal memory):

1) Assign an address (internal memory) in a register.

2) Assign another address to the accumulator.

3) Move the value of a to register R2.

4) Subtract the data in accumulator and R1.

5) The result in accumulator.

6) End.

Page 13: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Subtraction

direct & immediate Addressing

org 000h

mov r1,#11h

mov a,#03h

subb a,r1

end

Input: r1= 0x11h

a=0x03h

Output: a=0x08h

Internal memory - Indirect Addressing

org 000h

mov r1,53h

mov a,25h

mov r2,a

subb a,r1

end

Input:

Memory I:53h I:25h

Data 05 07

Output: a=0x02

Page 14: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Indirect addressing mode (external memory):

1) Initialize the external memory with dptr.

2) Move the memory content which is addressed by dptr to accumulator.

3) Move the data from accumulator to register R0.

4) Increment the dptr.

5) Move the data in memory location which is pointed by dptr to accumulator.

6) Subtract the accumulator data with R0.

7) Increment the content of dptr.

8) Move the result from accumulator to external memory.

Page 15: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Register addressing

org 000h

mov a,#10h

mov r1,a

mov a,#03h

subb a,r1

mov r2,a

end

Input: r1=0x10

r2=0x13

Output: a=0x03

External - Indirect Addressing

org 0000h

mov dptr,#1000h

movx a,@dptr

mov r0,a

inc dptr

movx a,@dptr

subb a,r0

inc dptr

movx @dptr,a

end

Inputs Output

Memory x:1000h x:1001h x:1002h

Data 05 01 04

Page 16: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

RESULT:

Thus the assembly language program for 8-bit addition and subtraction is

performed.

Page 17: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Multiplication and division

Multiplication

direct & immediate Addressing

org 000h

mov b,#02

mov a,#03

mul ab

end

Input: a= 0x03h

b=0x02h

Output: a=0x06h

Internal memory

Indirect Addressing

org 000h

mov a,55h

mov b,51h

mul ab

end

Input:

Memory I:55h I:51h

Data 06 02

Output: a=0x0C

Page 18: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: 8- BIT MULTIPLICATION AND DIVISION

EXP NO.:

AIM:

To perform 8-bit multiplication and division using 89C51 assembly language.

ALGORITHM FOR MULTIPLICATION

Direct Addressing mode:

1) Assign a value to b

2) Assign a value to a

3) Perform multiplication using a and b

4) End

Register Addressing mode:

1) Assign a value to a.

2) Move the value stored in a to register R0.

3) Assign a value to b.

4) Move the value stored in b to register R1.

5) Multiply a and b.

6) End.

Indirect Addressing mode (internal memory):

1) Assign an address (internal memory) to a.

2) Move the value from accumulator to register R0.

3) Assign an address to b.

4) Move the value from b to register R1.

5) Multiply a and b.

6) End.

Page 19: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Register addressing

org 0000h

mov a,#06h

mov r0,a

mov b,#02h

mov r1,b

mul ab

end

Input: r0=0x06

r1=0x02

Output: a=0x0C

External

Indirect Addressing

org 000h

mov a,55h

mov b,51h

mul ab

end

Input:

Inputs Output

Memory x:1000h x:1001h x:1002h

Data 05 01 05

Page 20: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Indirect Addressing mode (external memory):

1) Initialize the external memory with dptr.

2) Move the memory content which is addressed by dptr to accumulator.

3) Move the data from accumulator to b.

4) Increment the data pointer.

5) Move the data which is pointed by dptr to accumulator.

6) Move the value from a to R0.

7) Multiply values of a and b and increment the dptr.

8) Move the result from accumulator to external memory.

9) End.

ALGORITHM FOR DIVISION

Direct Addressing mode:

1) Assign a value to b.

2) Assign a value to a.

3) Perform division with the values present in a and b.

4) End.

Register Addressing mode:

1) Assign a value to a.

2) Move the value stored in a to register R0.

3) Assign a value to b.

4) Move the value stored in b to register R1.

5) Divide a and b.

6) End.

Indirect Addressing mode (internal memory):

1) Assign an address (internal memory) to a.

2) Move the value from accumulator to register R0.

3) Assign another address to b.

4) Move the value from b to register R1.

5) Divide a and b.

6) End.

Page 21: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Division

direct & immediate Addressing

org 000h

mov a,#18

mov b,#06

div ab

end

Input: a= 0x18

b=0x06

Output: a=0x03

Internal memory

Indirect Addressing

org 000h

mov a,55h

mov b,51h

div ab

end

Input:

Memory I:55h I:51h

Data 06 02

Output: a=0x03

Page 22: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Indirect Addressing mode (external memory):

1) Initialize the external memory with dptr.

2) Move the memory content which is addressed by dptr to accumulator.

3) Move the data from accumulator to b.

4) Increment the data pointer.

5) Move the data which is pointed by dptr to accumulator.

6) Move the value from a to R0.

7) Divide a and b.

8) Increment the dptr.

9) Move the result from accumulator to external memory.

10) End.

Page 23: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Register addressing

org 0000h

mov a,#06h

mov r0,a

mov b,#02h

mov r1,b

div ab

end

Input: r0=0x06

r1=0x02

Output: a=0x03

External

Indirect Addressing

org 0000h

mov dptr,#1000h

movx a,@dptr

mov b,a

inc dptr

movx a,@dptr

mov r2,a

div ab

inc dptr

movx @dptr,a

end

Inputs Output

Memory x:1000h x:1001h x:1002h

Data 06 02 03

Page 24: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

RESULT:

Thus the assembly language program for 8-bit addition and subtraction is

performed.

Page 25: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Largest and smallest of numbers

Largest

org 0000h

mov r0,50h

dec r0

mov r1,#51h

mov a,@r1

mov 60h,a

loop: inc r1

mov a,@r1

cjne a,60h,l2

l2: jc l1

mov 60h,a

l1: djnz r0,loop

end

Input:

Memory 50h 51h 52h 53h 54h

Data 04 07 06 08 01

Output

60h: 08

Page 26: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: SORTING LARGEST & SMALLEST NUMBER USING

89C51

EXP NO.:

AIM:

To find the largest and smallest number among the set by using 89C51

APPARATUS:

PC with Keil µ vision4

ALGORITHM:

1) Start the Program.

2) Move the content in 50H location to R2 and then decrement R2.

3) Initially provide the data as 51H to r1 and move the content of the address shown

in R1 to accumulator A and move it to 60H.

4) Design a loop such that R1 is incremented and the content of the address shown

by R1 is moved to accumulator A.

5) Now compare the values in A and 60H location and move the control to L2.

6) Use Jump if No Carry (JNC) command to perform subtraction between 60H and

A .If there is no carry, it goes to execute L1. Now the largest number is in 60H

location.

7) Perform the loop till the content of R2 becomes Zero.

8) Use Jump if Carry (JC) instruction instead of JNC to obtain smallest number in

60H location.

9) End the Program.

Page 27: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Smallest

org 0000h

mov r0,#50h

dec r0

mov r1,#51h

mov a,@r1

mov 60h,a

loop: inc r1

mov a,@r1

cjne a,60h,l2

l2: jnc l1

mov 60h,a

l1: djnz r0,loop

end

Input:

Memory 50h 51h 52h 53h 54h

Data 04 07 06 08 01

Output:

60h:01

Page 28: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

RESULT:

Thus the assembly language program for largest and smallest numbers has been

performed.

Page 29: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Interchanging of data

Internal to internal

org 0000h

mov r2,#05h

mov r0,#70h

mov r1,#50h

loop: mov a,@r0

mov @r1,a

inc r0

inc r1

djnz r2,loop

end

Input: Output:

Memory 70h 71h 72h 73h 74h 50h 51h 52h 53h 54h

Data 04 07 06 08 01 04 07 06 08 01

Internal to external

org 0000h

mov r0,#70h

mov r1,#05h

mov dptr,#9000h

loop: mov a,@r0

movx @dptr,a

inc r0

inc dptr

djnz r1,loop

end

Input:

Memory 70h 71h 72h 73h 74h

Data 04 07 06 08 01

Output:

Memory 9000h 9001h 9002h 9003h 9004h

Data 04 07 06 08 01

Page 30: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: INTERCHANGING OF DATA WITHIN MEMORY

USING 89C51

EXP NO.:

AIM: To illustrate the data transfer within memory registers using assembly level

programming language.

APPARATUS REQUIRED: PC with Keil µ vision (version4)

ALGORITHM:

1. Start the Program

2. Provide counter value to R2 and give the address of input to R1.

3. Specify the address of output at R0.

4. Design a loop such that the address of input data contained in R1 is moved to A.

5. Now move the content of A to the address of output.ie, R0.

6. Increment R0and R1 and use Decrement and Jump if Not Zero (DJNZ) to decrease

the count and execute the loop.

7. Stop the program

Page 31: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

External to internal

org 0000h

mov dptr,#9000h

mov r1,#05h

mov r0,#70h

loop: movx a,@dptr

mov @r0,a

inc dptr

inc r0

djnz r1,loop

end

Input:

Memory 9000h 9001h 9002h 9003h 9004h

Data 04 07 06 08 01

Output:

Memory 70h 71h 72h 73h 74h

Data 04 07 06 08 01

External to External

org 000h

mov r2,#04h

mov r0,#50h

mov dptr,#9100h

loop: movx a,@dptr

mov @r0,a

inc dptr

inc r0

djnz r2,loop

mov dptr,#9400h

mov r0,#50h

goto: mov a,@r0

movx @dptr,a

inc dptr

Page 32: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 33: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

inc r0

djnz r2,goto

end

Input:

Memory 9000h 9001h 9002h 9003h 9004h

Data 04 07 06 08 01

Output:

Memory 9400h 9401h 9402h 9403h 9404h

Data 04 07 06 08 01

Page 34: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

RESULT:

The assembly language program for data transfer from internal memory to internal memory is

executed

Page 35: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

.Sum

org 000h

mov r2,#05h

mov r0,#70h

mov a,#00

loop: addc a,@r0

inc r0

djnz r2,loop

end

Input:

Memory 70h 71h 72h 73h 74h

Data 04 07 06 08 01

Output:a=0x1b

Average of n numbers

org 000h

mov r0,#70h

mov r1,#05h

mov b,#05h

mov a,#00h

loop: addc a,@r0

inc r0

djnz r1,loop

div ab

end

Input:

Memory 70h 71h 72h 73h 74h

Data 10 20 30 40 50

Output: a=0x30h

b=0x00h

Page 36: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: THE SUM AND AVERAGE OF N NUMBERS

EXP NO.:

AIM:

To find sum and the average of N numbers in assembly language programming using

Keil software.

SOFTWARE AND HARDWARE REQUIRED:

Keil u vision 4 software,Personal Computer.

ALGORITHM:

1) Start the program.

2) Initialize the register R0.

3) Initialize the register R2.

4) Initialize the values of B and A.

5) Loop: Add A and register R0 value with carry.

6) Increment R0.

7) Decrement R2 and jump to Loop if not zero.

8) Divide A and B.

9) Stop the program.

RESULT:

Thus the assembly language program for sum and average of n numbers has been

performed.

Page 37: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Prime numbers

org 0000h

mov a,#11h

mov r0,a

mov b,#02h

div ab

mov r1,a

mov r3,a

mov r2,#00h

dec r3

l2: mov a,r0

mov b,r1

div ab

mov a,b

cjne a,#00h,l1

inc r2

l1: dec r1

djnz r3,l2

end

Input: a=0x11h

Output: r2 =0x00h (prime)

Page 38: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: PRIME NUMBER OR NOT

EXP NO.:

AIM:

To find the given number is prime or not by using keil software.

SOFTWARE AND HARDWARE REQUIRED:

Keil u vision 4 software,personal computer.

ALGORITHM:

1) Start the program.

2) Initialize the memory address and move to accumulator.

3) Move the accumulator value to R0.

4) Initialize the counter value.

5) Divide the values of A and B.

6) Move accumulator value to R1.

7) Move the accumulator value to R3.

8) Assign the value to R2.

9) Decrement R3.

10) Loop: Move R1 value to accumulator.

11) Move R1 value to A.

12) Compare A and jump to Loop1 if not equal .

13) Increment R2.

14) Loop1: Decrement R1.

15) Decrement R3 jump to Loop2 if it is not zero.

16) Stop the program.

RESULT:

Thus assembly language program for prime number or not has been performed.

Page 39: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Factorial

org 000h

mov r0,#04h

mov b,r0

mov a,#01

loop: mov b,r0

mul ab

djnz r0,loop

end

Input: r0=0x04h

Output: a=0x18h

Page 40: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: FACTORIAL OF N NUMBER

EXP NO.:

AIM:

To find the N number of factorial using 89C51 in keil software.

SOFTWARE AND HARDWARE REQUIRED:

Keil u vision 4 software.

Personal Computer.

ALGORITHM:

1) Start the program.

2) Initialize the value of R0 and A.

3) Back: Move R0 value to B.

4) Multiply the value of A and B.

5) Decrement R0 jump to back if it is not zero.

6) Move A value to R1.

7) Stop the program.

.

RESULT:

Thus the assembly language program for factorial of n number has been performed

Page 41: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Swap

org 0000h

mov a,20h

swap a

mov 20h,a

end

Input Output

Memory 20h 20h

Data 30 03

Exchange

a)org 000h

mov a,#50h

mov b,#70h

mov r1,a

mov a,b

mov b,r1

end

(or)

b)org 0000h

mov r0,#50h

mov a,@r0

mov r1,a

inc r0

mov a,@r0

xch a,r1

mov @r0,a

dec r0

mov a,r1

mov @ro,a

end

Input: a=0x50h b=0x70h Output: a=0x70h

b=0x50h

Page 42: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: SWAPPING AND EXCHANGING

EXP NO.:

AIM:

To perform the exchange and swapping of given numbers or data in assembly

language using Keil software

APPARATUS REQUIRED:

System required, Keil software

ALGORITHM:

SWAPPING:

1) Start the program

2) Initialise internal memory 50h

3) Swap A so that the nibbles are exchanged

4) Move the value from A to the address

EXCHANGE:

1) Start the program

2) Assign a value to A and register R0

3) Move the value of A to the temporary variable B

4) Now move the value of R1 to A

5) Now R1being freed move the values from temporary variable B to R1

6) Thus the numbers are exchanged

RESULT:

Thus the assembly language program for swapping and exchange of data is preformed

using 8051 microcontroller

Page 43: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Code verification

a)Ones’ and Zero’s

org 0000h

mov r3,#08h

mov r1,#00h

mov r2,#00h

mov r0,#50h

mov a,@r0

loop: rlc a

jc l1

sjmp l2

l1: inc r1

sjmp l3

l2: inc r2

l3: nop

djnz r3,loop

end

Input: 1000h=0x10h

Output: r2=0x02h

r3=0x06h

r6=0x03h

Page 44: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: CODE VERIFICATION

EXP NO.:

AIM:

To execute a program for a) finding the number of one’s and zero’s in a 8 bit number.

b) to check an 8 bit code stored in 1000h of internal data memory. Codeword is valid if

3MSB are 0 and it contains two 1’s in the remaining 5 bits. If codeword is valid store FF

else store 00h in 1001h.

SOFTWARE REQUIRED:

PC with Keil uVision2 IDE

ALGORITHM:

1) Start the program

2) Initialize the DPTR with an address

3) Store 03 in the internal memory

4) Copy the data in the address pointed by DPTR to A

5) Initialize R2, R3 and R6 to 00h and R0 to 08h and B to 02h

6) Divide A by B

7) Copy the data in A to R4 and then B to A

8) If A is not equal to 01h then jump to step9

9) If carry is not set jump to step11

10) Jump to step12

11) Increment R2 and jump to step16

12) Increment R3 and copy data in R0 to A

13) If A=03h, then decrement data in 70h else jump to step 16

14) Copy data in B to A

15) If A=00h, then increment data in R6 else jump to step 16

Page 45: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

b)

org 000h

mov dptr,#1000h

movx a,@dptr

mov r2,#05h

mov r3,#03h

mov r4,#00h

mov r1,#00h

mov r0,#00h

loop: rlc a

jnc l1

sjmp l2

l1: inc r4

l2: nop

djnz r3,loop

back: rlc a

jc next

sjmp l3

next: inc r1

cjne r1,#02h,l4

cjne r4,#03h,l4

mov r0,#ffh

sjmp l3

l4: mov r0,#00h

l3: nop

djnz r2,back

mov a,r0

mov dptr,#100h

movx @dptr,a

end

Input:

1000h: 03 02 11

Output:

1001h: FFh 00h FFh

Page 46: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

16) Decrement R0 and if R0 is not equal to 00h jump to step 5

17) Copy data in R6 to A

18) If A=03h, then copy data in R2 to A else jump to step20

19) If A=02h, then A=ffh and jump to step 21, else jump to step 20

20) A=00h

21) Initialize DPTR with 1001h and copy A’s content to it

22) Stop the program

RESULT:

The assembly language program to perform code verification was executed

successfully.

Page 47: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Sorting an array

Ascending order

org 0000h

mov r7,#05h

b2: mov r6,#04h

mov r0,#70h

b1: mov a,@r0

inc r0

mov b,@r0

cjne a,b,next

sjmp back

next: jc back

mov @r0,a

dec r0

mov @r0,b

inc r0

back: djnz r6,b1

djnz r7,b2

end

Input:

Memory 70h 71h 72h 73h 74h

Data 40 20 10 50 30

Output:

Memory 70h 71h 72h 73h 74h

Data 10 20 30 40 50

Page 48: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE: SORTING OF AN ARRAY

EXP NO.:

AIM:

To write a program for ascending and descending order of numbers by using

assembly language.

APPARATUS REQUIRED:

1. Personal computer.

2. Keil software.

ALGORITHM:

1) Start the program.

2) Assign some values to register R2.

3) Enter the comparison value in register R1 and assign at as B.

4) Assign some values to register R0.

5) Enter the comparison value to R0 and move to A and assign it to B.

6) Increment R0.

7) Move the value of R0 in B register.

8) Compare the non- zero value of A and B and assign as next.

9) Perform short jump back.

10) ASCENDING: In next program jump on carry back.

DESCENDING: In next program jump on no carry back.

11) Move the value of A to address of R0.

12) Decrement R0.

13) Stop the program.

Page 49: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Descending order

org 0000h

mov r7,#05h

b2: mov r6,#04h

mov r0,#60h

b1: mov a,@r0

inc r0

mov b,@r0

cjne a,b,next

sjmp back

next: jnc back

mov @r0,a

dec r0

mov @r0,b

inc r0

back: djnz r6,b1

djnz r7,b2

end

Input:

Memory 70h 71h 72h 73h 74h

Data 40 20 10 50 30

Output:

Memory 70h 71h 72h 73h 74h

Data 50 40 30 20 10

Page 50: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

RESULT:

Thus the assembly language program for sorting an array in ascending and decending

using 89c51 is excecuted.

Page 51: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 52: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE:

INTERFACING LED WITH 8051

EXP NO:

Aim:

To develop and verify Embedded C program for toggling LEDs connected to IO

ports of 8051 microcontroller.

Software Tools Required:

Proteus V6.0_SP0 Professional

Keil µVision4 IDE

Embedded C &Assembly Language Program

Single LED Toggle:

Algorithm:

1. Start the program.

2. Include the header file.

3. Including the required function for delay.

4. Initialize the main function and toggle the port which connected in port 0.

5. Make the loop function for continuous sequence.

6. End the program.

Assembly Language Program:

org 0000h

start:mov a,#00h

mov @r1,#0ffh

mov p2,a

acall delay

mov a,#0ffh

Page 53: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

mov p2,a

acall delay

Circuit Diagram:

Page 54: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

sjmp start

delay:

mov tmod,#10h

mov r2,#0eh

clr tf1

clr et1

st:mov th1,#00h

mov tl1,#00h

setb tr1

loop1:jnb tf1,loop1

clr tf1

clr tr1

djnz r2,st

ret

end

C-program:

#include<reg51.h>

void msdelay(unsigned int);

void main(void)

{

while(1)

{

P0=0x00;

msdelay(250);

P0=0xff;

Page 55: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

msdelay(250);

Circuit Diagram:

Page 56: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

}}

void msdelay(unsigned int dtime)

{

unsigned int i,j;

for(i=0;i<dtime;i++)

for(j=0;j<dtime;j++);

}

8 LED Toggle:

Program:

#include<reg51.h>

void delay();

void main()

{

while(1)

{

P2=0x00;

delay();

P2=0xaa;

delay();

}

} void delay ()

{

int i=0X00;

while (i<=14)

{

TMOD=0x10;

TF1=0X00;

Page 57: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

TH1=0x00;

TL1=0x00;

Page 58: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

TR1=0x01;

l1:

if(TF1==0X01)

i++;

else

goto l1;

}

}

Result:

Thus, the circuit is designed and the program to toggle single and 8 LEDs using 8051

microcontroller was successfully verified in Proteus tool.

Page 59: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 60: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE:

7-SEGMENT LED DISPLAY INTERFACE

WITH 8051

EXP NO.:

Aim:

To develop and verify Embedded C program for interfacing 7-segment display with

8051 microcontroller to count 0-9 and 0-99.

Software Tools Required:

Proteus V6.0_SP0 Professional

Keil µVision4 IDE

Embedded C and Assembly Language Program

Single 7-Segment Display

Algorithm:

1. Start the program.

2. Include the header file.

3. Include the required function for delay

4. Initialize the main function and required variables.

5. Include the loop for increment and send the data to port 2 which is connected with

seven segment display.

6. For two seven segment LED for increment and toggle the pins which is present in port

2 to display the values alternatively.

7. End the program.

Assembly Language Program:

org 0000h

start:mov p2,#3fh

acall delay

mov p2,#06h

acall delay

mov p2,#5bh

Page 61: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Circuit Diagram:

7 Segment Led Pin Diagram:

Page 62: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

acall delay

mov p2,#4fh

acall delay

mov p2,#66h

acall delay

mov p2,#6dh

acall delay

mov p2,#7dh

acall delay

mov p2,#07h

acall delay

mov p2,#7fh

acall delay

mov p2,#6fh

acall delay

sjmp start

delay:

mov tmod,#10h

mov r2,#0eh

clr tf1

clr et1

st:mov th1,#00h

mov tl1,#00h

setb tr1

loop1:jnb tf1,loop1

clr tf1

clr tr1

djnz r2,st

ret

end

Page 63: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 64: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

C-Program:

#include<reg51.h>

void msdelay(unsigned int);

void main(void)

{

while(1)

{

P2=0x3f;

msdelay(250);

P2=0x06;

msdelay(250);

P2=0x5b;

msdelay(250);

P2=0x4f;

msdelay(250);

P2=0x66;

msdelay(250);

P2=0x6d;

msdelay(250);

P2=0x7d;

msdelay(250);

P2=0x07;

msdelay(250);

P2=0x7f;

msdelay(250);

P2=0x6f;

msdelay(250);

}}

void msdelay(unsigned int dtime)

{

unsigned int i,j;

Page 65: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

for(i=0;i<dtime;i++)

for(j=0;j<dtime;j++);

}

Circuit Diagram:

Page 66: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Double 7-Segment Display:

Program:

#include<reg51.h>

void delay();

void main()

{

int i,j,k;

int a[]={0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};

while (1)

{

for(i=0;i<10;i++)

for(j=0;j<10;j++)

for(k=0;k<500;k++)

{

P3=0x03;

P2=a[i];

delay();

P3=0x02;

P2=a[j];

delay();

P2=0xff;

}}}

void delay ()

{{

TMOD=0x10;

TF1=0X00;

TH1=0xff;

TL1=0x00;

TR1=0x01;

l1:

if(TF1!=0X01)

Page 67: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

goto l1;

}}

Page 68: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Result:

Thus, the circuit is designed and the program to display 0-9 and 0-99 by interfacing single

and double 7-segment display with microcontroller was successfully verified in Proteus tool.

Page 69: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 70: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE:

LED DOT MATRIX INTERFACE WITH 8051

EXP NO.:

Aim:

To develop and verify Embedded C program for interfacing LED dot matrix display

with 8051 microcontroller and to display character.

Software Tools Required:

Proteus V6.0_SP0 Professional

Keil µVision4 IDE

Embedded C

Algorithm:

1. Start the program.

2. Include the header file.

3. Include the required delay function.

4. Initialize the main function and required variables.

5. The rows of the DOT Matrix are connected with the port 3.

6. The columns of the DOT Matrix are connected with the port 2.

7. Make the desire input in terms of column and toggle, display the output in terms of

rows.

8. End the program.

Program:

#include<reg51.h>

void msdelay(unsigned int);

void main(void)

Page 71: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

{ while(1)

{

Circuit Diagram:

Dot Matrix Led Array Diagram (7x5):

Page 72: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

P3=0x01;

P2=0x01;

msdelay(50);

P3=0x02;

P2=0xf6;

msdelay(50);

P3=0x04;

P2=0xf6;

msdelay(50);

P3=0x08;

P2=0xf6;

msdelay(50);

P3=0x10;

P2=0x01;

msdelay(50);

Page 73: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

}

}

void msdelay(unsigned int dtime)

{

unsigned int i,j;

for(i=0;i<dtime;i++)

for(j=0;j<dtime;j++);

}

Result:

Thus, the circuit is designed and the program to display character ‘A’ by interfacing

led dot matrix display with microcontroller was successfully verified in Proteus tool.

Page 74: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE:

STEPPER MOTOR CONTROL USING 8051

EXP NO.:

Aim:

To develop and verify Embedded C program for controlling the rotation of stepper

motor with step angle 2’ at 30’ clockwise direction and 25’ anticlockwise direction by

interfacing it with 8051 microcontroller.

Software Tools Required:

Proteus V6.0_SP0 Professional

Keil µVision4 IDE

Embedded C.

Algorithm:

1. Start the program.

2. Include the header file.

3. Include the required delay function.

4. Initialize the main function .

5. Toggle the port 2 connected with ULN2003A.

6. Toggle the function for 00 to 11 to rotate in clockwise direction.

7. Toggle the function for 11 to 00 to rotate in anticlockwise direction.

8. End the program.

Program:

#include<reg51.h>

void msdelay(int k);

void main()

{

int i,k,q;

int j;

int steprev[5]={0x06,0x0c,0x08};

int stepfor[5]={0x0c,0x06,0x03,0x09};

P2=0x00;

Page 75: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Circuit Diagram:

Stepper Motor:

Page 76: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

for(i=0;i<3;i++)

{

j=0;

while(j<4)

{

P2=stepfor[j];

j++;

msdelay(1);

}

}

for(k=0;k<3;k++)

{

P2=stepfor[k];

msdelay(1);

}

msdelay(14);

q=0;

while(q<3)

{

P2=steprev[q];

q++;

msdelay(1);

}

l3:P2=0x08;

goto l3;}

void msdelay(int k)

{

int i;

for(i=0;i<k;i++)

{

TMOD=0x01;

TH0=0x00;

Page 77: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

TL0=0x00;

PIN DIAGRAM ULN2003:

Page 78: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

TR0=1;

while(TF0==0);

TR0=0;

TF0=0;

} }

Result:

Thus, the circuit is designed and the program to control the rotation direction of

stepper motor by interfacing with microcontroller was successfully verified in Proteus tool.

Page 79: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 80: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE:

LCD INTERFACING WITH 8051

EXP NO.:

Aim:

To develop and verify Embedded C program for display characters in LCD by

interfacing with 8051 microcontroller.

Software Tools Required:

Proteus V6.0_SP0 Professional

Keil µVision4 IDE

Embedded C and Assembly Language Program

Algorithm:

1. Start the program.

2. Include the header file.

3. Include the required delay function.

4. Include the function for LCD initialization .

5. Send the data to the port 2 connected in data pin of LCD.

6. End the program.

Assembly Language Program:

org 0000h

lcdisp:mov a,#3ch

acall cmd

acall delay

mov a,#0eh

acall cmd

acall delay

mov a,#06h

acall cmd

acall delay

mov a,#01h

acall cmd

Page 81: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Circuit Diagram:

Page 82: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

acall delay

mov a, #87h

acall cmd

acall delay

mov a,#'O'

acall display

acall delay

mov a,#'U'

acall display

acall delay

mov a,#'T'

acall display

acall delay

mov a,#'P'

acall display

acall delay

mov a,#'U'

acall display

acall delay

mov a,#'T'

acall display

acall delay

mov a,#' '

acall display

acall delay

mov a,#'H'

acall display

acall delay

mov a,#'E'

acall display

acall delay

mov a,#'R'

acall display

Page 83: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

acall delay

LCD DISPLAY LM017L PIN DIAGRAM:

Page 84: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

mov a,#'E'

acall display

acall delay

sjmp lcdisp

cmd: mov p3,a

clr p2.0

clr p2.1

setb p2.2

acall delay

clr p2.2

ret

display: mov p3,a

setb p2.0

clr p2.1

setb p2.2

acall delay

clr p2.2

ret

delay: mov tmod,#10h

mov r2,#03h

clr tf1

clr et1

st:mov th1,#00h

mov tl1,#00h

setb tr1

loop1:jnb tf1,loop1

clr tf1

clr tr1

djnz r2,st

ret

end

Page 85: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

HEX CODE COMMAND TO LCD INSTRUCTION REGISTER

01 Clear Display Screen

02 Return Home

04 Decrement Cursor(Shift cursor to left)

05 Shift display Right

06 Increment Cursor (shift Cursor to Right)

07 Shift Display left

08 Display OFF, Cursor OFF

0A Display OFF, Cursor ON

0C Display ON, Cursor OFF

0E Display ON, Cursor Blinking

0F Display OFF, Cursor Blinking

10 Shift Cursor Position To Left

14 Shift Cursor Position To Right

18 Shift The Entire Display To The Left

1C Shift The Entire Display To The Right

80 Force Cursor Beginning Of First Line

C0 Force Cursor Beginning Of Second Line

38 2 Lines and 5x7 Matrix

Page 86: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

C-Program:

#include<reg51.h>

sbit RS=P2^0;

sbit RW=P2^1;

sbit EN=P2^2;

#define port P3

void msdelay(int k);

void lcd_display(unsigned char value);

void lcd_cmd(unsigned int value);

void main()

{

int q;

unsigned char out[20]={'o','u','t','p','u','t',' ','h','e','r','e'};

while(1)

{

lcd_cmd(0x38);

msdelay(100) ;

lcd_cmd (0x0e);

msdelay(100) ;

lcd_cmd(0x01);

msdelay(100);

for(q=0;q<11;q++)

{lcd_display(out[q]);

msdelay(100);

} } }

void lcd_cmd(unsigned int value)

{

P3=value;

RS=0;

RW=0;

EN=1;

Page 87: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

msdelay(100);

EN=0;}

void lcd_display(unsigned char value)

Page 88: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

{

RS=1;

P3=value;

RW=0;

EN=1;

msdelay(100);

EN=0;

}

void msdelay(int dtime)

{

Int i,j;

for(i=0;i<dtime;i++)

for(j=0;j<dtime;j++);

}

Result:

Thus, the circuit is designed and the program to display characters by interfacing LCD

display with microcontroller was successfully verified in Proteus tool.

Page 89: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE:

Page 90: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DC MOTOR CONTROL USING 8051

EXP NO.:

Aim:

To develop and verify Embedded C program for controlling the rotation direction of

DC motor by interfacing it with 8051 microcontroller using H-bridge.

Software Tools Required:

Proteus V6.0_SP0 Professional

Keil µVision4 IDE

Embedded C.

Algorithm:

1. Start the program.

2. Include the header file.

3. Include the required delay function.

4. Initialize the main function and required variables.

5. Send the data 01 to the port 2 connected with the L293D driver Ic for clockwise

direction.

6. Send the data 10 to the port 2 connected with the L293D driver Ic for anticlockwise

direction.

7. End the program.

Program:

#include<reg51.h>

sbit left=P3^0;

sbit right=P3^1;

void msdelay()

{

TMOD=0x01;

TH0=0x00;

TL0=0x00;

TR0=1;

Page 91: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Circuit Diagram:

PIN DIAGRAM- L293D

Page 92: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DC MOTOR:

while(TF0==0);

TR0=0;

TF0=0;

}

void main()

{

P2=0x00;

while(1)

{

if(left==0)

{

P2=0x02;

msdelay();

}

if(right==0)

{

P2=0x01;

msdelay();

}

if((right==1)&&(left==1))

{

P2=0x00;

msdelay();

}

}

Page 93: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

}

Result:

Thus, the circuit is designed and the program to control the rotation direction of DC

motor by interfacing with microcontroller using H-bridge was successfully verified in Proteus

tool.

Page 94: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE:

ADC INTERFACING WITH 8051

EXP NO.:

Aim:

To develop and verify Embedded C program for measuring temperature using 8051

microcontroller with interfacing ADC0808IC and Lcd display.

Software Tools Required:

Proteus V6.0_SP0 Professional

Keil µVision4 IDE

Embedded C and Assembly Language Program.

Algorithm:

1. Start the program.

2. Include the header file.

3. Initialize the port variables and set the parameters.

4. Include the require functions for delay and LCD functions.

5. Initialize the main function and required variables.

6. Initialize the necessary parameters for ADC by calling the functions which includes

read and write operations to ADC0804.

7. Initialize the interrupts for ADC to read the data to the microcontroller throw the port 1.

8. Calculate the angular conversion operation on the received 8 bit values to find the

approximate temperature.

9. Display the content which present in port 3 connected with data port in LCD display.

10. Change the temperature and check the parameters of temperature variation in LCD

display.

11. End the program.

Assembly Language Program:

org 0000h

wd bit p2.6

Page 95: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

intr bit p2.7

Circuit Diagram:

Page 96: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

mov p1,#0ffh

start:

setb intr

clr wd

setb wd

here: jb intr, here

clr p2.5

acall h2d

acall d2a

acall display

setb p2.5

sjmp start

h2d:

mov a,p1

mov b,#0ah

div ab

mov r0,b

mov b,#0ah

div ab

mov r1,b

mov r2,a

ret

d2a:

mov a,r0

orl a,#30h

mov r3,a

Page 97: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

mov a,r1

ADC 0804 PIN DIAGRAM:

Page 98: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

orl a,#30h

mov r4,a

mov a,r2

orl a,#30h

mov r5,a

display:mov a,#38h

acall cmd

acall delay

mov a,#0eh

acall cmd

acall delay

mov a,#01h

acall cmd

acall delay

mov a,r5

acall disp

acall delay

mov a,#06h

acall cmd

acall delay

mov a,r4

acall disp

acall delay

mov a,#06h

acall cmd

acall delay

Page 99: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

mov a,r3

TEMPERATURE SENSOR LM34 PIN DIAGRAM:

Page 100: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

acall disp

acall delay

mov a,#06h

acall cmd

acall delay

ret

cmd:mov p3,a

clr p2.0

clr p2.1

setb p2.2

acall delay

clr p2.2

ret

disp:mov p3,a

setb p2.0

clr p2.1

setb p2.2

acall delay

clr p2.2

ret

delay:

mov r6,#50h

here2: mov r7,#0ffh

here3:djnz r7,here3

djnz r6,here2

ret

Page 101: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

end

Page 102: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

C-Program:

#include<reg51.h>

sbit INTR=P2^7;

sbit RS=P2^0;

sbit RW=P2^1;

sbit EN=P2^2;

sbit R=P2^5;

sbit W=P2^6;

void delay();

void convert(unsigned int value);

void lcmd(unsigned int);

void ldata(unsigned int);

void main()

{

while(1)

{

unsigned int value;

P1=0xFF;

lcmd(0x38);

delay();

lcmd(0x0E);

delay();

lcmd(0x01);

delay();

INTR=1;

R=1;

W=1;

W=0;

delay();

W= 1;

delay();

while(INTR==1);

Page 103: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

R=0;

Page 104: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

delay();

value=P1;

convert(value);

INTR=1;

} }

void convert(unsigned int v)

{

unsigned int x,d1,d2,d3;

x=v/10;

d1=(v%10)+48;

v=x;

x=x/10;

d2=(v%10)+48;

d3=(x%10)+48;

ldata(d3);

delay();

ldata(d2);

delay();

ldata(d1);

delay();

}

void lcmd(unsigned int a)

{

P3=a;

RS=0;

RW=0;

EN=1;

delay();

EN=0;

}

void ldata(unsigned int a)

Page 105: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

{

P3=a;

RS=1;

Page 106: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

RW=0;

EN=1;

delay();

EN=0;

}

void delay()

{

int j;

for(j=0;j<2;j++)

{

TMOD=0x10;

TF1=0x00;

TH1=0x00;

TL1=0x00;

TR1=0x01;

while(TF1==0x00);

TR1=0x00;

}

}

Page 107: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Result:

Thus, the circuit is designed and programmed to develop and verify Embedded C

program for measuring temperature using 8051 microcontroller with interfacing ADC0804IC

and Lcd display.

Page 108: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE:

DAC INTERFACING WITH 8051

EXP NO.:

Aim:

To develop and verify Embedded C program for digital to analog conversion using

8051 microcontroller with interfacing DAC0808 IC.

Software Tools Required:

Proteus V6.0_SP0 Professional

Keil µVision4 IDE

Embedded C and Assembly Language Program.

Algorithm:

1. Start the program.

2. Include the header file.

3. Initialize the port variables.

4. Include the required function for delay.

5. Initialize the main function and assign the required value.

6. The data port of DAC 0808 connected in port 2 of microcontroller.

7. Make a looping operation and shifting operation to send the data to port 2.

8. The output variation can be displayed in oscilloscope.

9. End the program.

Assembly Language Program:

org 0000h

l2:mov r2,#0ah

mov a,#00h

l1:mov p2,a

acall delay

Page 109: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

inc a

djnz r2,l1

sjmp l2

delay:

Circuit Diagram:

DAC PIN DIAGRAM

Page 110: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

mov tmod,#10h

mov th1,#00h

mov tl1,#00h

setb tr1

l3:jnb tf1,l3

clr tr1

ret

end

C-Program:

# include <reg51.h>

void msdelay(unsigned int);

void main()

{

while(1)

{

int j,k;

j=10;

for(k=0;k<j;k++)

Page 111: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

{

P2=k;

msdelay(1);

}

}

}

void msdelay(unsigned int t)

{

int k;

for(k=0;k<t;k++)

{

TMOD =0X01;

TH0=0X00;

TL0=0X00;

TR0=0X01;

ANALOG OUTPUT:

Page 112: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

while(TF0==0);

TR0=0;

TF0=0;

}

}

Result:

Thus, the circuit is designed and programmed to develop and verify Embedded C

program for digital to analog conversion using 8051 microcontroller with interfacing

DAC0808IC.

Page 113: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 114: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE:

KEYPAD INTERFACING WITH 8051

EXP NO.:

Aim:

Interface the keypad with the 8051 microcontroller

Software Tools Required:

Proteus V6.0_SP0 Professional

Keil µVision4 IDE

Embedded C and Assembly Language Program.

Algorithm:

1. The keyboard is used to type data to a screen; this is mostly used in security purposes.

2. The keyboard consists of rows and columns.

3. Use LCD in order to display the pressed keys on keyboard.

4. The keypad rows are to be connected to port1 and columns are connected to port3 and

we can access press key using this ports and send to LCD which is connected to port0

5. At first make all rows to 1, then again make row1 zero and check for which column

goes to zero, then corresponding key is sent to LCD display which displays the key

pressed

6. This operation continues by making a row zero and all other ones.

7. This process goes on to detect the pressed key and to display it on the LCD.

Assembly language program:

org 0000h

mov p2,#00h

key: setb p1.4

setb p1.5

setb p1.6

Page 115: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

setb p1.7

clr p1.0

Circuit Diagram:

Page 116: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

setb p1.1

setb p1.2

setb p1.3

jnb p1.4,k7

jnb p1.5,k8

jnb p1.6,k9

jnb p1.7,ka

setb p1.0

clr p1.1

setb p1.2

setb p1.3

jnb p1.4,k4

jnb p1.5,k5

jnb p1.6,k6

jnb p1.7,kb

setb p1.0

setb p1.1

clr p1.2

setb p1.3

jnb p1.4,k1

jnb p1.5,k2

jnb p1.6,k3

jnb p1.7,kc

setb p1.0

setb p1.1

Page 117: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

setb p1.2

clr p1.3

HEX(Matrix) Keypad Structure:

Page 118: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

jnb p1.4,kf

jnb p1.5,k0

jnb p1.6,ke

jnb p1.7,kd

jmp key

k7:jnb p1.4,k7

mov p2,#07h

jmp key

k8:jnb p1.5,k8

mov p2,#7fh

jmp key

k9:jnb p1.6,k9

mov p2,#6fh

jmp key

ka:jnb p1.7,ka

mov p2,#77h

jmp key

k4:jnb p1.4,k4

mov p2,#66h

jmp key

k5:jnb p1.5,k5

mov p2,#6dh

jmp key

k6:jnb p1.6,k6

mov p2,#7dh

Page 119: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

jmp key

kb:jnb p1.7,kb

Page 120: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

mov p2,#7fh

jmp key

k1:jnb p1.4,k1

mov p2,#06h

jmp key

k2:jnb p1.5,k2

mov p2,#5bh

jmp key

k3:jnb p1.6,k3

mov p2,#4fh

jmp key

kc:jnb p1.7,kc

mov p2,#39h

jmp key

kf:jnb p1.4,kf

mov p2,#71h

jmp key

k0:jnb p1.5,k0

mov p2,#3fh

jmp key

kd:jnb p1.7,kd

mov p2,#3fh

jmp key

ke:jnb p1.6,ke

mov p2,#79h

Page 121: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

jmp key

end

Page 122: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

C-Program:

#include<reg51.h>

sbit r1=P1^0;

sbit r2=P1^1;

sbit r3=P1^2;

sbit r4=P1^3;

sbit c1=P1^4;

sbit c2=P1^5;

sbit c3=P1^6;

sbit c4=P1^7;

void delay(unsigned int k)

{

int j;

for(j=0;j<k;j++)

{

TMOD=0x10;

TF1=0x00;

TH1=0x00;

TL1=0x00;

TR1=0x01;

while(TF1==0x00);

TR1=0x00;

TF1=0x00;

}

}

int reg_key()

{

Page 123: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 124: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

c1=1;

c2=1;

c3=1;

c4=1;

r1=0;r2=1;r3=1;r4=1;

if(c1==0){delay(1); while(c1==0) return 0x07;}

if(c2==0){delay(1); while(c2==0) return 0x7f;}

if(c3==0){delay(1); while(c3==0) return 0x6f;}

if(c4==0){delay(1); while(c4==0) return 0x77;}

r1=1;r2=0;r3=1;r4=1;

if(c1==0){delay(1); while(c1==0) return 0x66;}

if(c2==0){delay(1); while(c2==0) return 0x6d;}

if(c3==0){delay(1); while(c3==0) return 0x7d;}

if(c4==0){delay(1); while(c4==0) return 0x7f;}

r1=1;r2=1;r3=0;r4=1;

if(c1==0){delay(1); while(c1==0) return 0x06;}

if(c2==0){delay(1); while(c2==0) return 0x5b;}

if(c3==0){delay(1); while(c3==0) return 0x4f;}

if(c4==0){delay(1); while(c4==0) return 0x39;}

r1=1;r2=1;r3=1;r4=0;

if(c1==0){delay(1); while(c1==0) return 0x71;}

if(c2==0){delay(1); while(c2==0) return 0x3f;}

if(c3==0){delay(1); while(c3==0) return 0x79;}

if(c4==0){delay(1); while(c4==0) return 0x3f;}return 0x00;}

void main()

{

int c=0;

Page 125: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 126: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

P2=0x00;

while(1)

{

P2=c;

while(!(c=reg_key()));

}

}

Result:

Thus, the circuit is designed and programmed to develop and verify Embedded C

program for keypad interfacing using 8051 microcontroller

Page 127: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 128: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE:

SERVO DESIGN USING 8051

EXP NO.:

Aim:

To interface servo motor with 8051 microcontroller and to program it to rotate the

servo to 60’ after 1sec delay and it has to further rotate to 180’ then after 2 sec delay it has to

stop in 120’.

Software Tools Required:

Proteus V6.0_SP0 Professional

Keil µVision4 IDE

Embedded C.

Algorithm:

1. Start the program.

2. Include the header file.

3. Include the required delay function.

4. Initialize the main function and required variables.

5. Keep the degree of rotation of servo motor from 0’ to 180’

6. Send the data to the port 2 connected with PWM output pin for rotation.

7. End the program.

Program:

#include<reg51.h>

void t0delay(int a,int b);

void main()

{

int i;

for(i=0;i<50;i++)

{

Page 129: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Circuit Diagram:

SERVO MOTOR

Page 130: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

P2=0x01;

t0delay(0xfb,0x44);

P2=0x00;

t0delay(0x66,0x66);

}

for(i=0;i<50;i++)

{

P2=0x01;

t0delay(0xea,0x9c);

P2=0x00;

t0delay(0x66,0x66);

}

for(i=0;i<50;i++)

{

P2=0x01;

t0delay(0xfa,0x10);

P2=0x00;

t0delay(0x66,0x66);

}

}

void t0delay( int a,int b)

{

TMOD=0x01;

TH0=a;

TL0=b;

TR0=1;

Page 131: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

while(TF0==0);

SERVO MOTOR PULSE WIDTH FOR 60’

Page 132: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

TR0=0;

TF0=0;

}

Result:

Thus, the circuit is designed and programmed to develop and verify Embedded C

program for Servo motor interfacing using 8051 microcontroller

Page 133: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Page 134: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

DATE:

SERIAL COMUNICATION USING 8051

MICROCONTROLLER

EXP NO.:

Aim:

To develop and verify Embedded C program for serial communication using 8051

microcontroller.

Software TOOLS Required:

Proteus V6.0_SP0 Professional

Keil µVision4 IDE

Embedded C.

Algorithm:

1. Start the program.

2. Include the header file.

3. Include the function for delay.

4. Initialize the main and required variables.

5. Initialize timer control and timer mode select register and set the mode to auto reload

mode.

6. Initialize the timer value TH1 register to be F3 for the baud rate of 2400.

7. Send the ASCII value for a to z throw port P2.

8. Display the output throw the virtual terminal.

9. End the program.

Program:

#include<reg51.h>

void delay(int k);

void main()

{

int i;

while(1)

{

TMOD=0x21;

TH1=0XFD;

Page 135: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

Circuit Diagram:

OUTPUT:

Page 136: STUDY OF 8051 MICROCONTROLLER - vidyarthiplus.com

www.vidyarthiplus.com

www.vidyarthiplus.com

SCON=0X50;

TR1=1;

for(i=48;i<=58;i++)

{

SBUF=i;

while(TI==0);

delay(14);

TI=0;

}

}

}

void delay(int k)

{

int j;

for(j=0;j<k;j++)

{

TH0=0x00;

TL0=0x00;

TR0=0x01;

while(TF0==0);

TR0=0;

TF0=0;

}

}

Result:

Thus, the circuit is designed and programmed to develop and verify Embedded C

program for Serial communication using 8051 microcontroller.