0% found this document useful (0 votes)
67 views74 pages

Mesl Manual

The document provides instructions for the Microprocessor and Embedded Systems Laboratory course. It includes: - Details of the lab in-charges and course approval. - Outcomes and prerequisites for the course, which involves programming microcontrollers and embedded systems using assembly language and C. - An index of experiments involving 8-bit and 16-bit arithmetic operations, interfacing, and programming peripherals using 8085, 8051, and PIC microcontrollers. - A sample program showing 8-bit addition using different addressing modes on the 8085 microprocessor to illustrate the concepts and experiments covered in the lab course.

Uploaded by

Parthu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views74 pages

Mesl Manual

The document provides instructions for the Microprocessor and Embedded Systems Laboratory course. It includes: - Details of the lab in-charges and course approval. - Outcomes and prerequisites for the course, which involves programming microcontrollers and embedded systems using assembly language and C. - An index of experiments involving 8-bit and 16-bit arithmetic operations, interfacing, and programming peripherals using 8085, 8051, and PIC microcontrollers. - A sample program showing 8-bit addition using different addressing modes on the 8085 microprocessor to illustrate the concepts and experiments covered in the lab course.

Uploaded by

Parthu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

DEPARTMENT OF ELECTRICAL AND ELECTRONICS

ENGINEERING

INSTRUCTION MANUAL
FOR

U15EEP602
MICROPROCESSOR AND EMBEDDED
SYSTEMS LABORATORY

Lab In-charges : Mr.M.Mathankumar/Assistant Professor


Mr.S.Suryaprakash/Assistant Professor

Approved by : Dr.Rani Thottungal , HoD/EEE

1
Department of
_______________________________________

LABORATORY RECORD
Name :__________________ Roll No.:__________

Class :___________________ Branch :__________

Certified Bonafide Record of Work done by_______________________________

Place:

Date: Staff In-Charge

University Register No.:

Submitted for the University Practical Examination held on

__________________________________

Internal examiner External examiner


MICROPROCESSOR AND EMBEDDED L T P C
U15EEP602
SYSTEMS LABORATORY 0 0 4 2
COURSE OUTCOMES
After successful completion of this course, the students will be able to
CO1 Write simple 8/16- bit processor controller programs using ALP K2
CO2 Interface input/output devices to the microcontroller/processor using ALP K3
CO3 Program on-board peripherals using Embedded C for 8/16 bit controllers K2
Interface control and monitor simple hardware modules using firmware
CO4 K3
programming
CO5 Visualize and analyze the internals of hardware using IDE K4
Design and develop interactive systems using microcontroller and open source
CO6 K4
electronics platform.

PRE-REQUISITE
Microprocessor, Embedded Systems
CO/PO Mapping
(S/M/W indicates strength of correlation) S-Strong, M-Medium, W-Weak
Programme Outcomes(POs) PSOs
COs
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
CO1 S M W
CO2 M S W M
CO3 M S W
CO4 M S W M
CO5 S W M
CO6 S S M W W M

COURSE ASSESSMENT METHODS

Direct Indirect
1. Laboratory Exercise 1. Course Exit Survey
2. Model Exam
3. End Semester Exam

LIST OF EXPERIMENTS
a) MICROPROCESSOR LABORATORY

8-bit Microprocessor – 8085


1. Programs for 8/16 bit arithmetic operations using 8085 processor.
Programs using arithmetic and control instructions.
2. A/D interfacing and D/A interfacing.

b) EMBEDDED SYSTEMS LABORATORY


8-bit Microcontroller – 8051

3. Programs for 8/16 bit arithmetic operations using 8051 Microcontroller


 Addition & subtraction of 8-bit data
 Multi-byte addition & Array addition
 Multiplication & Division

4. Programs with control instructions & bit manipulation instructions


 Search for the largest and smallest numbers in an array
 Ascending and Descending order
5. Stepper motor interfacing

8051 Program using Embedded C

6. LED interface to 8051 and timer programming.


7. Rolling display using LCD interface
8. Serial communication to PC- hyper link terminal
9. PWM generation
10. Temperature monitoring system.

PIC16F877 program using Embedded C

11. PWM generation of 3 phase inverter


12. Speed sensing and monitoring from PC.

Experiments beyond the syllabus should be conducted

Practical:48 Hours Total: 48 Hours


INDEX

Exp. Date Name of the Experiment Pg. Marks Signature


No. No.
CYCLE-I
1. Programs for 8-bit and 16-bit
arithmetic operations using 8085
processor
2. Programs using control instructions-
8085
3. Analog to Digital Interfacing
4. Digital to analog interfacing
5. Programs for 8-bit arithmetic
operations using 8051
microcontrollers
6. Programs using control instructions-
8051
7. Stepper Motor interfacing with 8051
CYCLE-II
8051 PROGRAMS USING EMBEDDED C
8. LED interfacing to 8051 and timer
programming.
9. Rolling display using LCD interface
10. Serial communication
11. PWM Generation
12. Temperature Monitoring System
PIC 16F877 PROGRAMS USING EMBEEDED C
13. PWM generation of 3 phase inverters
14. Speed sensing and monitoring from
PC
8085 Microprocessor
and 8051
Microcontroller
Programming using
Assembly Language
Ex.No:1

PROGRAMS USING ARITHMETIC OPERATIONS-8085

INTRODUCTION

a) OBJECTIVE:
i) To perform 8-bit addition, subtraction, multiplication and division in 8085
microprocessors.
ii) To perform 16-bit addition and subtraction in 8085 microprocessors.

ACQUISITION

a) MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 8085 Microprocessor kit - - 1

b) ALGORITHM:
8 BIT ADDITION
IMMEDIATE ADDRESSING MODE:
STEP:1: Start the program.
2: Load the number to the accumulator using immediate addressing mode
3. Load the number to the B register using immediate addressing mode
4: Add the numbers.
5: Store the accumulator content in a memory location.
6: Stop the program.
INDIRECT ADDRESSING MODE:
STEP:1: Start the program.
2: Initialize HL Memory pointer
3: Content of the memory location is transferred to the accumulator.
4: Increment the address of HL pair.
5: Add the memory content to the accumulator.
6: Increment the address of HL pair
7: Transfer the accumulator content to the memory location.
8: Stop the program.
DIRECT ADDRESSING MODE:
STEP:1: Start the program.
2: Load the first data into the accumulator.
3: Move the content of accumulator to B register
4: Load the second data into the accumulator.
5: The accumulator content is added with the B register content.
6: Store accumulator content to a memory location.
7: Stop the program.

PROGRAM: ADDITION OF TWO 8 BIT NUMBERS [DIFFERENT MODES]

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
IMMEDIATE
4100 3E START MVI A,10 A = 10
4101 10
4102 06 MVI B,20 B = 20
4103 20
4104 80 ADD B A = A+B
4105 32 STA 4200 4200 = 30
4106 00
4107 42
4108 76 HALT HLT
INDIRECT
4100 21 START LXI H,4000 HL = 4000
4102 00
4102 42
4103 7E MOV A,M M,A
4104 23 INX H Increment HL reg
4105 8E ADD M A = A+M
4106 23 INX H Increment HL reg
4107 77 MOV M,A A,M
4108 76 HALT HLT
DIRECT
4100 3A LDA 4204
4101 04
4102 42
4103 5F MOV E,A
4104 3A LDA 4205
4105 05
4106 42
4107 83 ADD E
4108 32 STA 4206
4109 06
410A 42
410B 76 HALT HLT

RESULT:
INPUT: 09, 02
OUTPUT: B

8 BIT SUBTRACTION

ALGORITHM:

IMMEDIATE ADDRESSING MODE:

STEP:1: Start the program.


2: Load the number to the accumulator using immediate addressing mode
3. Load the number to the B register using immediate addressing mode
4: Subtract the numbers.
5: Store the accumulator content in a memory location.
6: Stop the program.

INDIRECT ADDRESSING MODE:

STEP:1: Start the program.


2: Initialize HL Memory pointer
3: Content of the memory location is transferred to the accumulator.
4: Increment the address of HL pair.
5: Subtract the memory content to the accumulator.
6: Increment the address of HL pair
7: Transfer the accumulator content to the memory location.
8: Stop the program.

DIRECT ADDRESSING MODE:


STEP:1: Start the program.
2: Load the first data into the accumulator.
3: Move the content of accumulator to B register
4: Load the second data into the accumulator.
5: The accumulator content Subtract with the B register content.
6: store accumulator content to a memory location.
7: Stop the program.

PROGRAM: SUBTRACTION TWO 8 BIT NUMBERS [DIFFERENT MODES]

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
DIRECT
4100 3A START LDA 4200 Initialize the data
4101 00
4102 42
Move the content of A
4103 47 MOV B,A
to B
4104 3A LDA 4201 Initialize the next data
4105 01
4106 42
4107 90 SUB B Subtract the B
4108 32 STA 4202 Store the Result
4109 02
410A 42
410B 76 HLT
IMMEDIATE
4100 3E START MVI A,20H Move 20H to A
4101 20
4102 D6 MVI B,15H Move 15H to B
4103 15
4104 90 SUB B Subtract 15 from 20
Store A Content in
4105 32 STA 4150
4100H
4106 50
4107 41
4108 76 HALT HLT
IN DIRECT
4100 21 START LXI H,4200 Initialize the data
4101 00
4102 42
Move the content M to
4103 7E MOV A,M
A
4104 23 INX H
4105 96 SUB M Subtract the data
4106 23 INX H
4107 77 MOV M,A
4108 76 HLT

RESULT:
INPUT : 05 , 02
OUTPUT : 03

8 BIT MULTIPLICATION
ALGORITHM:

STEP:1: Start the program.


2: Initialize the multiplicand and multiplier.
3: Set multiplier as counter.
4: Add the multiplicand with a zero initialized HL pair.
5: Repeat the step 4, until the counter becomes zero.
6: Move HL register pair to a memory location.
7. Stop the program.

PROGRAM: 8 BIT MULTIPLICATION

ADDRESS OPCODE LABEL MNEMONICS OPERAND COMMENT


4100 3A START LDA 4500 Initialize HL reg. to
4101 00 4500
4102 45
4103 5F MOV E,A Transfer first data to
reg. B
4104 16 MVI D,00 Increment HL reg. to
point next mem.
Location.
4105 00 Clear the acc.
4106 3A LDA 4501
4107 01 Clear C reg for carry
4108 45

4109 4F MOV C,A Add multiplicand


multiplier times.
410A 21 LXI H,0000 Jump to NEXT if there
410B 00 is no carry
410C 00
410D 19 NEXT DAD D Increment C reg
410E 0D DCR C Decrement B reg
410F C2 JNZ NEXT Jump to L1 if B is not
4110 0D zero.
4111 41
4112 22 SHLD 4502
4113 02
4114 45
4115 76 HLT Stop the program

RESULT:
INPUT: 04, 03
OUTPUT: 0C
8 - BIT DIVISION
ALGORITHM:
STEP:1: Start the program.
2: Initialize the dividend, divisor and counter.
3: Shift left the dividend and quotient.
4: If divisor is greater than the dividend decrease the count and if count is
not zero, repeat step 3.
5: If divisor is lesser than dividend and store the resulting value as
dividend.
6: Decrement the count and repeat step 3.
7. Now, the lower register of the register pair contains quotient while the
other contains the remainder.
8. Stop the program.

PROGRAM: DIVISION OF TWO 8 – BIT NUMBERS

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 3A LDA 4150H Load divisor to B
4101 50
4102 41
4103 47 MOV B,A
4104 3A LDA 4151H Load dividend to A
4105 51
4106 41
4107 0E MVI C,00H Initialize quotient=0
4108 00
4109 B8 CMP B
410A DA JC LOOP
410B 13
410C 41
410D 90 SUB B Dividend – Divisor
410E 0C INR C Quotient=quotient+ 1
410F B8 CMP B Is Divident <Divisor
4110 D2 JNC LOOP1 If not repeat again
4111 09
4112 41
Yes, then store
4113 32 STA 4152H
remainder
4114 52
4115 41
4116 79 MOV A,C
4117 32 STA 4153H Store quotient
4118 53
4119 41
411A 76 HLT

RESULT:
INPUT: 08, 04
OUTPUT: A= 2,, B= 0
MULTIBYTE ADDITION

ALGORITHM:

STEP: 1: Start the program.


2: Clear the accumulator content and load the number of bytes per number.
3: Set up memory pointer.
4: Add the content of DE pair with accumulator.
5: Increment the memory pointer.
6: Decrement the byte counter and repeat till zero.
7: Display the result.
8: Stop the program.
PROGRAM:

MNEMONIC
HEXADECIMAL HEXADECIMAL COMMENTS
INSTRUCTION
ADDRESS OPCODE LABLE INSTR. OPERAND
4100 2A LHLD 4150
4101 50
4102 41
4103 EB XCHG D
4104 2A LHLD 4152
4105 52
4106 41
4107 19 DAD D
4108 22 SHLD 4250
4109 50
410A 42
410B 76 HLT

RESULT:
INPUT: 2345, 1234
OUTPUT :3579

MULTIBYTE SUBTRACTION
ALGORITHM:

Step1: Start the program.


2: Clear the accumulator content and load the number of bytes per number.
3: Set up memory pointer.
4: subtract the content of DE pair with accumulator.
5: Increment the memory pointer.
6: Decrement the byte counter and repeat till zero.
7: Display the result.
8: Stop the program.
PROGRAM:
MNEMONIC
HEXADECIMAL HEXADECIMAL COMMENTS
INSTRUCTION
ADDRESS OPCODE LABLE INSTR. OPERAND
4100 2A START LHLD 4150H Initialize the data
4101 50
4102 41
4103 EB XCHG
Initialize the second
4104 2A LHLD 4200H
data
4105 00
4106 42
4107 7B MOV A,E Move content A,E
4108 95 SUB L Subtract L
4109 6F MOV L,A Move content A,L
410A 7A MOV A,D Move content D,A
410B 9C SBB H
410C 67 MOV H,A Move content A,H
410D 22 SHLD 4250H
410E 50
410F 42
4110 76 HLT

RESULT:

INPUT: 2345, 1234


OUTPUT:1111

INFERENCE AND ANALYSIS


8085 is a 8-bit processor and it can process only 8-bit data. If 16 bit data is to be
processed it is divided into two 8-bit data and then processed.
Different addressing modes in 8085 processor were understood.
Thus, the following programs were executed using 8085
 Addition, Subtraction of two eight-bit numbers
 Multiplication, Division of two eight-bit numbers
 Multibyte Addition and Subtraction
 Sum of array of given Numbers
Ex. No:2

PROGRAMS USING CONTROL INSTRUCTIONS-8085

INTRODUCTION

OBJECTIVE:
To perform the following operations using control instructions
o Increment/Decrement of numbers
o Sum of array of given numbers
o Largest and smallest of given numbers
o Ascending and Descending order.

ACQUISITION

MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 8085 Microprocessor kit - - 1

ALGORITHM:
a. Increment

Step 1: Move the number to A


2: Move the content to B reg
3: Increment the counter
4: Decrement the counter
5: If the counter is non-zero go to step3 Else continue
6: Store accumulator value in HL
7: End.
b. Decrement

Step 1: Move the no to accumulator and control to B reg.


2: Decrement the no  Increment the counter.
3: Check if counter is zero if no continue Else go to step2.
4: Store accumulator value in HL.
5: End.
PROGRAM: INCREMENT

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4000 3E MVI A, O5H Set the no
4001 05
4002 06 MVI B, O5H Set the counter
4003 05
4004 3C LOOP INR A Increment no
4005 05 DCR B Decrement counter
Check if counter
4006 C2 JNZ LOOP
zero if no go to 4004
4007 04
4008 40
4009 32 STA 41OOH Store the A value in 4100
400A 00
400B 41
400C 76 HLT

PROGRAM: DECREMENT

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4000 3E MVI A, O5H Set the no
4001 05
4002 06 MVI B, O5H Set the no
4003 05
4004 3D LOOP DCR A Decrement no
4005 05 DCR B Decrement counter
Check if counter is
4006 C2 JNZ LOOP
zero if no go to 4004
4007 04
4008 40
4009 32 STA 41OOH Store A in 4100
400A 00
400B 41
400C 76 HLT

RESULT:
INPUT: 09
OUTPUT:10
SUM OF ARRAY OF GIVEN NUMBERS
ALGORITHM:

Step1: Start the program


2: Initialize HL register pair
3: Move the count to register D
4: Move the content of memory to accumulator
5: Increment the pointer
6: Add the content of memory to accumulator
7: Decrement the count
8: Check whether the value of count is 0 if yes continue else go to Step5
9: Increment the pointer
10: Move the accumulator content to memory.
11: Stop.

PROGRAM: SUM OF ARRAY OF GIVEN NUMBERS

MNEMONIC
HEXADECIMAL HEXADECIMAL COMMENTS
INSTRUCTION
ADDRESS OPCODE LABLE INSTR. OPERAND
4100 21 START LXI H,4200 HL4200
4101 00
4102 42
4103 16 MVI D,04
4104 03
4105 7E MOV A, M
4106 23 LOOP INX H Increment HL pair
4107 8E ADD M Add the data
4108 15 DCR D
4109 C2 JNZ LOOP If D0, LOOP
410A 06
410B 41
410C 23 INX H Increment the H
410D 77 MOV M, A
410E 76 HLT

RESULT:
INPUT: 01, 02, 03, 04, 05
OUTPUT: 0F
LARGEST OF ‘n’ NUMBERS

ALGORITHM:

Step 1: Start
2: Store (N-1) no of data in data table-1
3: Load accumulator with the content of memory location which is
stored in register pair DE initially memory location in DE.
4: Compare A with the content at the next memory location.
5: Check if carry is let, if no go to 8
6: Clear carry
7: Move the memory content to A
8: Initialize next memory location
9: Decrement C
10: Check result is 0 if no go to 4
11: Store the content of A eargest no data table
12: Stop.

PROGRAM: LARGEST OF ‘n’ NUMBERS

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4051 0E MVI C,02H (Data table –1) (3–1=2)
4052 02
4053 11 LXI D,410H Initialize Memory pointer
4054 00
4055 41
4056 1A LDAX D Load A with data in next data
4057 21 LXI H,4101H
4058 01
4059 41
405A BE OVER CMP M CompareMaccumulator ,
If Memory is greater than MOV
405B D2 JNC AGREAT
it to A
405C 61
405D 40
405E 37 STC Set Carry
405F 3F CMC Complement carry
4060 7E MOV A,M Memory A
4061 23 AGREAT INX H Increment Mem Pointer
4062 0D DCR C Dec count
4063 C2 JNZ OVER If all the no Checked
4064 5A
4065 40
4066 21 LXI H,4200H Initialize memory pointer
4067 00
4068 42
4069 77 MOV M,A A  memory (4200)
406A 76 HLT

RESULT:
INPUT: 02,0A, 03
OUPUT: 0A

SMALLEST OF ‘n’ NUMBERS

ALGORITHM:

Step 1: Start
2: Store (N-1) in Register C
3: Load Register part DE with lower & upper value of memory address
4: Load the data to from memory location .whose address is stored in DE.
5: Initialize the next memory address of data values thro HL
6: Compare the memory with A
7: Check whether carry is Let YES go to 9
8: Store smallest no 5A
9: Clear Carry
10: Initialize the new memory address thro HL
11: Decrement register C
12: Check whether result is 0 if no go to step 6
13: Store the smallest no in a memory location
14: Stop
PROGRAM: SMALLEST OF ‘n’ NUMBERS

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4051 0E MVI C,02H (Data table –1) (3–1=2)
4052 02
4053 11 LXI D,4100H Initialize HL
4054 00
4055 41
4056 1A LDAX D Load all data in D
4057 21 LXI H,4101H Next data is read
4058 01
4059 41
405A BE OVER CMP M Compare M with A,
405B DA JC ALESS If Memory is greater goto 405F
405C 5F
405D 40
405E 7E MOV A,M Else ore sall no to all set carry
405F 37 ALESS STC
4060 3F CMC Complement carry
4061 23 INX H Increment Memory
4062 0D DCR C Decrement counter
Check whether the current to
4063 C2 JNZ OVER
zero
4064 5A
4065 40
4066 21 LXI H,4200H Initialize mem ptr
4067 00
4068 42
4069 77 MOV M,A Store A in memory
406A 76 HLT

RESULT:

INPUT: 05, 0A, 02

OUTPUT:02
ASCENDING ORDER
ALGORTHIM:

Step 1: Start
2: Initialize counter by N-1
3: Initialize memory pointer counter 2 by N-1
4: Get the first no from memory
5: Increment memory pointer
6: Check if the power no is greater than the present no .it yes SWAP
their position decrement counter2
7: Check counter2 is 0 if yes decrement counter else goto 4
8: Check counter1 is 0 if yes stop else goto 3
9: Stop

ASCENDING ORDER
HEXADECIMAL MNEMONIC INSTRUCTION
COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 06 MVI B,03H Set counter
4101 03
4102 21 START LXI H,4150H Initialize Memory location
4103 50
4104 41
4105 0E MVI C,03H Set counter2
4106 03
4107 7E BACK MOV A,M Get the number
4108 23 INX H
4109 BE CMP M Compare with A
410A DA JNC SKIP If A value is small go to skip
410B 15
410C 41
410D CA JZ SKIP If both are equal go to skip
410E 15
410F 41
4110 56 MOV D,M MD
4111 77 MOV M,A AM
4112 2B DCX H HLHL-1
4113 72 MOV M,D DM
4114 23 INXH H HL=HL+1
4115 0D SKIP DCR C C=C-1
Check counter2 =0 if no go to
4116 C2 JNZ BACK
back
4117 07
4118 41
4119 05 DCR B B=B-1
Check counter =0 if no go to
411A C2 JNZ START
4002
411B 02
411C 41
411D 76 HLT

RESULT:
INPUT: 03, 05, 02
OUTPUT:02, 03, 05

DESCENDING ORDER
ALGORITHM:

Step 1: Start
2: Initialize counter 1 by N-1
3: Initialize memory pointer counter 2 by N-1
4: Get the no from memory
5: Increment memory pointer
6: Check if no SWAP their position else increment counter2
7: Check counter2 is 0 if yes decrement counter1else goto 4
8: Check counter1 is 0 if yes stop else goto 3
9: Stop
PROGRAM: DESCENDING ORDER

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 06 MVI B,03H Set counter1
4101 03
4102 21 START LXI H,4150H Initialize Memory Pointer
4103 50
4104 41
4105 0E MVI C,03H Set counter2
4106 03
4107 7E BACK MOV A, M Get the number
4108 23 INX H Mcr Memory pointer
4109 BE CMP M Compare all with memory
410A D2 JC SKIP If all value is large
410B 15 go to skip
410C 41
410D CA JZ SKIP If both are equal go to skip
410E 15
410F 41
4110 56 MOV D, M MD
4111 77 MOV M, A AM
4112 2B DCX H HLHL-1
4113 72 MOV M, D DM
4114 23 JNX H HL=HL+1
4115 0D SKIP DCR C C=C-1
4116 C2 JNZ BACK Check C =0 if not go to 4007
4117 07
4118 41
4119 05 DCR B B=B-1
Check counter is 0 if not go to
411A C2 JNZ START
4007
411B 02
411C 41
411D 76 HLT

RESULT:

INPUT: 03, 07, 01


OUTPUT: 07, 03, 01

INFERENCE AND ANALYSIS


Ex No :3
ANALOG TO DIGITAL INTERFACING
INTRODUCTION

a) OBJECTIVE:
To convert the analog voltage into digital and to display the data

ACQUISITION
a) MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 8085 Microprocessor kit - - 1
2 A/D interface - - 1

b) ALGORITHM:
Step1: Start the program

2: Initialize port A&C as input port

3: Initialize PORTB as output

4: Select channel 11

5: Output port B and make ALE high

6: After assigning no operation make ALE low

PROGRAM: ANALOG TO DIGITAL INTERFACING

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 3E START MVI A,10H Select the channel
4101 10
4102 D3 OUT 0C8H Make ALE Low
4103 C8
4104 3E MVI A,18 Make ALE High
4105 18
4106 D3 OUT 0C8H
4107 C8
4108 3E MVI A,01 SOC signal high
4109 01
410A D3 OUT 0D
410B D0
410C AF XRA A Delay
410D AF XRA A
410E AF XRA A
410F 3E MVI A,00 SOC signal low
4110 00
4111 D3 OUT 0D0H
4112 D0
4113 DB IN 0D8H Check for EOC
4114 D8
4115 E6 ANI 01
4116 01
4117 FE CPI 01
4118 01
4119 C2 JNZ LOOP
411A 13
411B 41
411C DB IN 0CH Read data from ADC
411D C0
411E 32 STA 4150
411F 50
4120 41
4121 76 HLT

INFERENCE AND ANALYSIS


Analog to Digital conversion is taking place using ADC device by properly initializing the
device.
RESULT:
Thus, the analog voltage present at the input channel is converted into digital and
displayed.
Ex No :4

DIGITAL TO ANALOG INTERFACING

INTRODUCTION

a) OBJECTIVE:
To generate analog waveform - Square, Triangular and Sine wave form digital input
using the microprocessor.

ACQUISITION

a) MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 8085 Microprocessor kit - - 1
2 D/A Interface - - 1
b) ALGORITHM:
a. Generation of Square wave
1. Start the program
2. Load the accumulator with 00 and call delay
3. load the accumulator with FF and call delay
4. Repeat the process from step2.
b. Generation of Triangular wave
1. Start the program
2. Load the accumulator with 00 and set it to output port
3. Increment the accumulator value
4. Repeat the process from step2 untill A:00
5. Load the accumulator with FF and send it to output port
6. Decrement the value and repeat the process from step5 until accumulator=00.
c. Generation of Sine wave
1. Start the program
2. Initialize the register pair with an address 4110H
3. Set counter to 46H
4. Output the content of HL pair to an output port
5. Increment the HL register
6. Repeat the process from step4
7. Repeat the process from step2
Look Up Table

7F 8A 95 A0 AH B5 BF C8
D1 D9 E0 E7 ED F2 F7 FA
FC FE FF FF FC FA F7 F2
ED E7 E0 DA D1 C8 BF B5
AA A0 95 8A 7F 74 69 5F
53 49 3F 36 2D 25 1D 17
10 0B 07 04 01 00 01 04
07 0B 10 17 1D 25 2D 36
3F 49 53 5F 69 74
Formula: Sinx =128+128xSinx =Digital Value

PROGRAM: Square wave

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 3E START MVI A,00H 0 Start of square wave
4101 00
4102 D3 OUT C8
4103 C8
4104 CD CALL DELAY Have some Toff
4105 11
4106 41
4107 3E MVI A,FF 1 State of square wave
4108 FF
4109 D3 OUT C8
410A C8
410B CD CALL DELAY Have some T on
410C 11
410D 41
410E C3 JMP START Repeat cycle
410F 00
4110 41
4111 06 DELAY MVI B,05 Timing delay
4112 05
4113 0E L1 MVI C,FF
4114 FF
4115 0D L2 DCR C
4116 C2 JNZ L2
4117 15
4118 41
4119 05 DCR B
411A C2 JNZ L1
411B 13
411C 41
411D C9 RET

PROGRAM: Triangular wave

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 2E START MVI L,00 Lowest Magnitude
4101 00
Output the Increasing
4102 7D L1 MOV A, L
magnitude
4103 D3
4104 C8
4105 2C INR L
4106 C2 JNZ L1
4107 02
4108 41
4109 2E MVI L1,FF Highest magnitude
410A FF
410B 7D L2 MOV A,L
410C D3 OUT C8
410D C8
410E 2D DCR L
410F C2 JNZ L2
4110 0B
4111 41
4112 C3 JMP START Continuous with next cycle
4113 00
4114 41

PROGRAM: Sine wave


HEXADECIMAL MNEMONIC INSTRUCTION
COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 21 START LXI H,4110H First address of LUT
4101 10
4102 41
4103 0E MVI C,46 Total no of datas
4104 46
4105 7E LOOP MOV A,M
4106 D3 OUT 0C0H Output the Magnitude
4107 C8
4108 23 INX H
4109 0D DCR C
410A C2 JNZ LOOP
410B 05
410C 41
410D C3 JMP START Start the next cycle
410E 00
410F 41
4110 7F
4111 8A
4112 95
4113 A0
4114 AA
4115 B5
4116 BF
4117 C8
4118 D1
4119 D9
411A E0
411B E7
411C ED
411D F2
411E F7
411F FA
4120 FC
4121 FE
4122 FF
4123 FE
4124 FC
4125 FA
4126 F7
4127 F2
4128 ED
4129 E7
412A E0
412B D9
412C D1
412D C8
412E BF
412F B5
4130 AA
4131 A0
4132 95
4133 8A
4134 7F
4135 74
4136 69
4137 5F
4138 53
4139 49
413A 3F
413B 36
413C 2D
413D 25
413E 1D
413F 17
4140 10
4141 0B
4142 07
4143 04
4144 01
4145 00
4146 01
4147 04
4148 07
4149 0B
414A 10
414B 17
414C 1D
414D 25
414E 2D
414F 36
4150 3F
4151 49
4152 53
4153 5F
4154 69
4155 74

INFERENCE AND ANALYSIS

It is understood that the 8085 processor does not have any ports. The ports of the
device can communicate with the processor through accumulator only.

RESULT:

Thus, the various analog waveforms were generated using 8085 Microprocessor
Ex No :5
Programs using arithmetic operations-8051

INTRODUCTION:

OBJECTIVE:
To perform addition, subtraction, multiplication, division and store the result in
memory.

ACQUISITION

a) MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 8051 Microcontroller kit - - 1

b) ALGORITHM:
Step1: Start the program
2: Get operand in A
3: Add the two operands with A
4: Store the result in memory
5: Stop the program

PROGRAM: ADDITION:

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 90 MOV DPTR, #4150
4101 41
4102 50
4103 74 MOV A, #15 Data1
4104 15
4105 34 ADDC A, #20 Data 2
4106 20
4107 F0 MOVX @ DPTR,A
4108 80 HERE SJMP HERE
4109 FE
RESULT:
INPUT: 15H, 20H
OUTPUT: 35H
SUBTRACTION
ALGORITHM:

Step1: Start the program


2: Get operand in A
3: Subtract the two operands with A
4: Store the result in memory
5: Stop the program

PROGRAM: SUBTRACTION:

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 C3 CLR C
4101 74 MOV A, #20 DATA1
4102 20
4103 94 SUBB A, #10 DATA2
4104 10
DPTR,
4105 90 MOV
#4500
4106 45
4107 00
4108 F0 MOVX @ DPTR, A
4109 80 HERE SJMP HERE
410A FE

RESULT:
INPUT: 20 10
OUTPUT: 10

MULTIPLICATION
ALGORITHM:

Step1: Start the program


2: Get operand in A
3: Multiply the two operands with A
4: Store the result in memory
5: Stop the program
PROGRAM:

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS INST. LABLE OPCODE OPERAND
4100 74 MOV A, #04 DATA 1
4101 04
4102 75 MOV B, #02 DATA2
4103 F0
4104 02
4105 A4 MUL AB
4106 90 MOV DPTR, #4500
4107 45
4108 00
4109 F0 MOV X @ DPTR,A
Increment the
410A A3 INC DPTR
data pointer
410B E5 MOV A,B
410C F0
410D F0 MOV X @ DPTR,A
410E 80 HERE SJMP HERE
410F FE

RESULT:
INPUT: 04 02
OUTPUT: 08

DIVISION
ALGORITHM:

Step1: Start the program


2: Get operand in A
3: Divide the two operand with A
4: Store the result in memory
5: Stop the program
PROGRAM: DIVISION

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 74 MOV A, #0C DATA 1
4101 0C
4102 75 MOV B, #03 DATA2
4103 F0
4104 03
4105 84 DIV AB
4106 90 MOV DPTR, #4500
4107 45
4108 00
4109 F0 MOV X @ DPTR,A
Increment the
410A A3 INC DPTR
data pointer
410B E5 MOV A,B
410C F0
410D F0 MOV X @ DPTR,A
410E 80 HERE SJMP HERE
410F FE

RESULTS:

INFERENCE:
Ex No :6
Programs using control instructions-8051
INTRODUCTION:
OBJECTIVE:

To perform the following operations using control instructions


o Largest and smallest of given numbers
o Ascending and Descending order.

ACQUISITION

a) MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 8051 Microcontroller kit - - 1
PROGRAM: LARGEST OF ‘n’ NUMBERS

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 90 MOV DPTR,#4200
4101 42
4102 00
4103 75 MOV 40H, # 00
4104 40
4105 00
4106 7D MOV R5, #05H
4107 05
4108 E0 L2 MOVX A,@DPTR
4109 B5 CJNE A,40H,L1
410A 40
410B 08
410C A3 L3 INC DPTR
410D DD DJNZ R5,L2
410E F9
410F E5 MOV A,40H
4110 40
4111 F0 MOVX @DPTR,A
4112 80 HLT SJMP HLT
4113 FE
4114 40 L1 JC L3
4115 F6
4116 F5 MOV 40H, A
4117 40
4118 80 SJMP L3
4119 F2

RESULT

INPUT 4200 – 04
4201 - 01
4202 - 02
4203 - 06
4204 - 08

OUTPUT 4205 – 08

PROGRAM: SMALLEST OF ‘n’ NUMBERS

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
4100 90 MOV DPTR,#4200
4101 42
4102 00
4103 75 MOV 40H, # FF
4104 40
4105 FF
4106 7D MOV R5, #05H
4107 05
4108 E0 L2 MOVX A,@DPTR
4109 B5 CJNE A,40H,L1
410A 40
410B 08
410C A3 L3 INC DPTR
410D DD DJNZ R5,L2
410E F9
410F E5 MOV A,40H
4110 40
4111 F0 MOVX @DPTR,A
4112 80 HLT SJMP HLT
4113 FE
4114 50 L1 JNC L3
4115 F6
4116 F5 MOV 40H, A
4117 40
4118 80 SJMP L3
4119 F2

RESULT

INPUT 4200 – 04
4201 - 01
4202 - 02
4203 - 06
4204 - 08

OUTPUT 4205 – 01

ASCENDING ORDER OF AN ARRAY:

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST OPERAND
4100 7B MOV R3,#04
4101 04
4102 7C MOV R4,#04
4103 04
4104 90 MOV DPTR,#4500
4105 45
4106 00
4107 AD REPEAT1 MOV R5,DPL
4108 82
4109 AE MOV R6,DPH
410A 83
410B E0 MOVX A,@DPTR
410C F5 MOV B,A
410D F0
410E A3 REPEAT INC DPTR
410F E0 MOVX A,@DPTR
4110 F8 MOV R0,A
4111 C3 CLR C
4112 95 SUBB A,B
4113 F0
4114 50 JNC CHKNXT
4115 13
4116 C0 EXCH PUSH DPL
4117 82
4118 C0 PUSH DPH
4119 83
411A 8D MOV DPL,R5
411B 82
411C 8E MOV DPH,R6
411D 83
411E E8 MOV A,R0
411F F0 MOVX @DPTR,A
4120 D0 POP DPH
4121 83
4122 D0 POP DPL
4123 82
4124 E5 MOV A,B
4125 F0
4126 F0 MOVX @DPTR,A
4127 88 MOV B,R0
4128 F0
4129 DB CHKNXT DJNZ R3,REPEAT
412A E3
412B 1C DEC R4
412C EC MOV A,R4
412D FB MOV R3,A
412E 0C INC R4
412F 8D MOV DPL,R5
4130 82
4131 8E MOV DPH,R6
4132 83
4133 A3 INC DPTR
4134 DC DJNZ R4,REPEAT1
4135 D1
4136 80 HLT SJMP HLT
4137 FE

RESULT:

INPUT 4500 – 02
4501 - 08
4502 - 04
4503 - 03
4504 - 05

OUTPUT 4500 – 02
4501 - 03
4502 - 04
4503 - 05
4504 - 08

DESCENDING ORDER OF AN ARRAY:

HEXADECIMAL MNEMONIC INSTRUCTION


COMMENTS
ADDRESS OPCODE LABLE INST OPERAND
4100 7B MOV R3,#04
4101 04
4102 7C MOV R4,#04
4103 04
4104 90 MOV DPTR,#4500
4105 45
4106 00
4107 AD REPEAT1 MOV R5,DPL
4108 82
4109 AE MOV R6,DPH
410A 83
410B E0 MOVX A,@DPTR
410C F5 MOV B,A
410D F0
410E A3 REPEAT INC DPTR
410F E0 MOVX A,@DPTR
4110 F8 MOV R0,A
4111 C3 CLR C
4112 95 SUBB A,B
4113 F0
4114 40 JC CHKNXT
4115 13
4116 C0 EXCH PUSH DPL
4117 82
4118 C0 PUSH DPH
4119 83
411A 8D MOV DPL,R5
411B 82
411C 8E MOV DPH,R6
411D 83
411E E8 MOV A,R0
411F F0 MOVX @DPTR,A
4120 D0 POP DPH
4121 83
4122 D0 POP DPL
4123 82
4124 E5 MOV A,B
4125 F0
4126 F0 MOVX @DPTR,A
4127 88 MOV B,R0
4128 F0
4129 DB CHKNXT DJNZ R3,REPEAT
412A E3
412B 1C DEC R4
412C EC MOV A,R4
412D FB MOV R3,A
412E 0C INC R4
412F 8D MOV DPL,R5
4130 82
4131 8E MOV DPH,R6
4132 83
4133 A3 INC DPTR
4134 DC DJNZ R4,REPEAT1
4135 D1
4136 80 HLT SJMP HLT
4137 FE

RESULT:

INPUT 4500 – 02
4501 - 08
4502 - 04
4503 - 03
4504 - 05

OUTPUT 4500 – 08
4501 - 05
4502 - 04
4503 - 03
4504 - 02

INFERENCE:
Ex No :7
SPEED CONTROL OF STEPPER MOTOR
INTRODUCTION:
OBJECTIVE:
To Control the speed of stepper motor.
ACQUISITION
a) MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 8051 Microcontroller kit - - 1
2 Stepper Motor Interface - - 1

b) ALGORITHM:
Step1: Start the program
2: Initialize memory pointer
3: Initialize the counter
4: Move the first data to accumulator
5: Push higher bit address and lower bit address
6: Initialize memory pointer as FFC0
7: Initialize counter2
8: Set delay counter
9: Move the content of accumulator in to memory
10: POP the higher and Lower bit
11: POP the increment pointer
12: Jump again to 4 till counter is zero
13: Jump the step2.

That the step size is,


3600
Ns x Nr
Where
Ns is the No. of stator poles
Nr is the No. of pairs of rotor poles

There are three different schemes available for “stepping” a stepper motor. These
are:
(a) Wave scheme
(b) 2-Phase scheme and
(c) Half Stepping or Mixed Scheme.
The switching sequence for the 2-Phase scheme

Anticlockwise Clockwise
Step A A2 B1 B2 Step A1 A2 B1 B2
1
1 1 0 0 1 1 1 0 1 0
2 0 1 0 1 2 0 1 1 0
3 0 1 1 0 3 0 1 0 1
4 1 0 1 0 4 1 0 0 1

2-Phase Scheme:
In this scheme, any two adjacent stator windings are energized. There are two
magnetic fields active in quadrate and none of the rotor pole faces can be indirect
alignment with the stator poles.
PROGRAM: SPEED CONTROL OF STEPPER MOTOR:
HEXADECIMAL MNEMONIC INSTRUCTION
COMMENTS
ADDRESS OPCODE LABLE INST. OPERAND
Initialize data
4100 90 MOV DPTR,#4500H
pointer
4101 45
4102 00
4103 78 MOV R0,#04
4104 04
Data pointer to
4105 E0 JO MOVX A,@DPTR
accumulator
4106 C0 PUSH DPH
4107 83
4108 C0 PUSH DPL
4109 82
410A 90 MOV DPTR,#FFCOH
410B FF
410C C0
410D 7A MOV R2, #01H
410E 01
410F 79 MOV R1,#0FH
4110 22
4111 7B DLY 1 MOV R3,#0FH
4112 FF
4113 DB DLY DJNZ R3,DLY
4114 FE
4115 D9 DJNZ R1,DLY
4116 FC
4117 DA DJNZ R2,DLY
4118 FA
4119 F0 MOV @DPTR, A
411A D0 POP DPL
411B 82
411C D0 POP DPH
411D 83
411E A3 INC DPTR
411F D8 DJNZ R0,J0
4120 E4
4121 80 SJMP START
4122 DD
4123 END
4500 09
4501 05
4502 06
4503 0A

INFERENCE:

Thus, the program for controlling the speed of a stepper motor is written in
8051 and verified.

RESULT:
8051
PROGRAMMING
USING
EMBEDDED C
Ex No :8
LED interfacing to 8051 and Timer Programming
INTRODUCTION:
OBJECTIVE:
To develop embedded C program for LED interfacing to 8051 and Timer
programming.
ACQUISITION
MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 8051 Microcontroller kit - - 1
2 LED Interfacing Board - - 1
3 Keil Compiler installed in
PC

LED interfacing

#include<reg51.h>
void delay();
void main()
{
while(1)
{
P1=0x00;
delay();
P1=0xff;
delay();
}
}
void delay()
{
int i,j;
for(i=0;i<=2500;i++)
for(j=0;j<=0XFF;j++);
}

Timer programming

#include<reg51.h>
#include<stdio.h>
xdata char *led;
int i,j;
void delay() // Delay generation using
Timer 0 mode 1
{
i=0;
while(i!=500) //take a 1 sec timing
{
TMOD = 0x01; // Mode1 of Timer0
TH0 = 0xfc; // FC66 evaluated hex value for 1
millisecond delay
TL0 = 0x66;
TR0 = 1; // Start Timer
while(TF0 == 0); // Using polling method
TR0 = 0; // Stop Timer
TF0 = 0; // Clear flag
i++;
}

void main()
{
led=0xff23;
while(1)
{

*led=0xaa;
P1=0x00;
delay();

*led=0x55;
P1=0x01;
delay();

*led=0xff;
P1=0x00;
delay();

*led=0x00;
P1=0x01;
delay();

}
}

INFERENCE:
Ex No :9
Rolling display using LCD interface
INTRODUCTION:
OBJECTIVE:
To develop embedded C program for Rolling display using LCD interface.
ACQUISITION
MATERIALS REQUIRED

S. Apparatus Range Type Quantity


NO
1 8051 Microcontroller kit - - 1
2 LCD Interfacing Board - - 1
3 Keil Compiler installed in PC

Program:

#include<reg51.h>
#include<stdio.h>
#include<string.h>

xdata at 0xffc0 unsigned char sel174;


xdata at 0xffc4 unsigned char lcdsel;
unsigned char array[] ={" Welcome"},cmd0[]={0x80,0x81,0x82,0x83,0x84};
unsigned char array1[] ={"Vi Microsystems "};
unsigned char
i,j,k,l,cmd[]={0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0
xcd,0xce,0xcf};

void delay()
{
int i,j;
for(i=0;i<0xf;i++)
for(j=0;j<0xff;j++);
}
void delay1(int val)
{
int i,j;
for(i=0;i<val;i++)
for(j=0;j<val;j++);
}
void busycheck()
{
delay();
sel174 = 0x00;
}
void cmd_write()
{
busycheck();
lcdsel = 0x38;
busycheck();
lcdsel = 0x06;
busycheck();
lcdsel = 0x01;
busycheck();
lcdsel = 0x0f;
busycheck();
lcdsel = 0x0c;
}
void main()
{

cmd_write();
for(j=0;j<4;j++)
{
busycheck();
lcdsel = cmd0[j];

for (i=0;i<8;i++)
{
busycheck();
delay();
delay();
sel174 = 0x01;
lcdsel = array[i];
}
}

for(j=14;j>=0;--j)
{
busycheck();
lcdsel = cmd[j];

for (i=0;i<16;i++)
{
busycheck();
delay();
sel174 = 0x01;
lcdsel = array1[i];
}
if(j==0 && i==16)
{
delay1(100);
while(k!=16)
{
busycheck();
lcdsel=0xc0;
for(l=k;l<16;l++)
{
busycheck();
delay();
sel174 = 0x01;
delay();
lcdsel=array1[l];
}
k++;
}
}
if(k==16)
{
delay1(200);
busycheck();
lcdsel=0xc0;
for(i=0;i<15;i++)
{
busycheck();
delay();
sel174 = 0x01;
delay();
lcdsel=array1[i];
}
if(i==15)
break;
}
}

while(1);

INFERENCE:
Ex No :10
Serial communication
INTRODUCTION:
OBJECTIVE:
To develop embedded C program for serial communication using 8051
microcontroller.
ACQUISITION
MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 8051 Microcontroller kit - - 1
2 Keil Compiler installed
in PC

Program:
#include<reg51.h>
#include<string.h>
#include<stdio.h>

unsigned char c;

void serial_init()
{
TMOD = 0X20; // timer mode select
TH1 = 0XFD; // baud rate select
TI = 1;
TR1 = 1; // timer on
SCON = 0X53; // serial comm enable

}
void delay(int m)
{
int i,j;
for(i=0;i<m;i++)
for(j=0;j<m;j++);
}

void main()
{

serial_init();
while(1)
{
RI=0;
while(RI==0);
c=SBUF; //rx buffer

TI=0;
SBUF=c; //tx buffer
while(TI==0);
}
}

INFERENCE:
Ex No :11
PWM Generation
INTRODUCTION:
OBJECTIVE:
To develop embedded C program for generation of pulse width modulation signal for
8051 controllers.
ACQUISITION
MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 8051 Microcontroller kit - - 1
2 Keil Compiler installed
in PC

Program:
#include <reg51.h>
#include<stdio.h>

xdata at 0xff14 sw_data;


//Reg Configure
sfr at 0xD9 CMOD;
sfr at 0xDA CCAPM0;
sfr at 0xD8 CCON;
sfr at 0xFA CCAP0H;

//pin configure
sbit CEX0 = 0x93;//(0x93 is bit address)P1.3 4th Pin
int val;
void timer0()
{
TMOD=0x02;
TH0=0xFF;
TCON=0x30; // Start Timer0
}

void main()
{
timer0();
CMOD = 0x04; // PCA Count Pulse Select bit 1
CCAPM0 = 0x42; // PCA0 : Set to PWM Mode
CCON = 0x40; // PCA0 : Output Enable &amp; Run PCA

while (1)
{
val=sw_data;
CCAP0H = val; //set range between 0x00 to 0xFF 0x7F is for 50% duty
cycle
}
}

INFERENCE:
Ex No :12
Temperature Monitoring System
INTRODUCTION:
OBJECTIVE:
To develop embedded C program for generation of pulse width modulation signal for
8051 controllers.
ACQUISITION
MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 8051 Microcontroller kit - - 1
2 Keil Compiler installed
in PC

Program:
#include<reg51.h>
#include<stdio.h>
#define LOW 00;
#define HIGH 01;

sbit SCLK=P3^2;
sbit SDA =P3^3;
bit ACK;

xdata char *led;


idata unsigned char dat;
unsigned int temp_read;
unsigned char count;
int i;

void delay() // Delay generation


using Timer 0 mode 1
{
i=0;
while(i!=1000) //take a 1 sec timing
{
TMOD = 0x01; // Mode1 of Timer0
TH0 = 0xfc; // FC66 evaluated hex value
for 1 millisecond delay
TL0 = 0x66;
TR0 = 1; // Start Timer
while(TF0 == 0); // Using polling method
TR0 = 0; // Stop Timer
TF0 = 0; // Clear flag
i++;
}

}
void Delay_Time()
{ unsigned long int i;
for(i=0;i<500;i++);
}

void lcd_dispaly(unsigned int adc_data)


{

*led=0x00;
P1=0x00;
if(adc_data>0x00 && adc_data<0x0c)
{
// printf("below 30°C\r\n");
*led=0x29;
P1=0x01;
delay();
}
else if((adc_data==0x0d)||(adc_data==0x0e))
{
// printf("Temp-> 30°C\r\n");
*led=0x30;
P1=0x01;
delay();
}
else if((adc_data==0x10)||(adc_data==0x0f))
{
// printf("Temp-> 31°C\r\n");

*led=0x31;
P1=0x00;
delay();

}
else if((adc_data<=0x14)&&(adc_data>=0x11))
{

// printf("Temp-> 32°C\r\n");
*led=0x32;
P1=0x00;
delay();
}
else if((adc_data>=0x15)&&(adc_data<=0x18))
{
// printf("Temp-> 33°C\r\n");
*led=0x33;
P1=0x00;
delay();

}
else if((adc_data>=0x19)&&(adc_data<=0x1c))
{
// printf("Temp-> 34°C\r\n");
*led=0x34;
P1=0x00;
delay();
}
else
if((adc_data==0x20)||(adc_data==0x1d)||(adc_data==0x1e)||(adc_data==0x1f)
)
{
// printf("Temp-> 35°C\r\n");

*led=0x35;
P1=0x00;
delay();

}
else if((adc_data==0x22)||(adc_data==0x21))
{
// printf("Temp-> 36°C\r\n");
*led=0x36;
P1=0x00;
delay();
}
else if((adc_data==0x24)||(adc_data==0x23))
{
// printf("Temp-> 37°C\r\n");
*led=0x37;
P1=0x00;
delay();
}
else if((adc_data==0x26)||(adc_data==0x25)||(adc_data==0x27))
{
// printf("Temp-> 38°C\r\n");
*led=0x38;
P1=0x00;
delay();
}
else if((adc_data==0x28)||(adc_data==0x29)||(adc_data==0x2a))
{
// printf("Temp-> 39°C\r\n");
*led=0x39;
P1=0x01;
delay();
}
else
if((adc_data==0x2b)||(adc_data==0x2c)||(adc_data==0x2d)||(adc_data==0x2e
)||(adc_data==0x2f))
{
// printf("Temp-> 40°C\r\n");
*led=0x40;
P1=0x01;
delay();
}
else
if((adc_data==0x30)||(adc_data==0x31)||(adc_data==0x32)||(adc_data==0x33
))
{
// printf("Temp-> 41°C\r\n");
*led=0x41;
P1=0x01;
delay();
}
else if((adc_data>=0x34)&&(adc_data<0xff))
{
// printf("Above 40°C\r\n");
*led=0x42;
P1=0x01;
delay();
}
}
/////////////////////////////////I2C protocol////////////////////////////////////////////
void I2C_START()
{
SCLK =LOW;
SDA =LOW;
Delay_Time();
Delay_Time();
SCLK=HIGH;
Delay_Time();
Delay_Time();
SDA=HIGH;
Delay_Time();
Delay_Time();
SDA=LOW;
Delay_Time();
Delay_Time();
SCLK=LOW;
}

void I2C_WRITE(unsigned char j)


{
dat=j;
for(i=0;i<8;i++)
{
SDA = dat & 0x80;
dat=dat<<1;
SCLK=HIGH;
Delay_Time();
Delay_Time();
SCLK = LOW;
}
SDA=HIGH;
Delay_Time();
Delay_Time();
SCLK = HIGH;
Delay_Time();
Delay_Time();
ACK = SDA;
Delay_Time();
Delay_Time();
SCLK=LOW;
}

void I2C_STOP()
{
SCLK=LOW;
Delay_Time();
Delay_Time();
SDA=HIGH;
}

unsigned char I2C_READ()


{
unsigned char i,j;
j=0;
j=SDA;
for(i=0;i<8;i++)
{
j<<=1;
SCLK=HIGH;
j|=SDA;
Delay_Time();
SCLK=LOW;
}
Delay_Time();
Delay_Time();
SDA = LOW;
Delay_Time();
Delay_Time();
SCLK = HIGH;
Delay_Time();
Delay_Time();
SCLK = LOW;
Delay_Time();
Delay_Time();
SDA = HIGH;
return(j);
}
/*void ser_int()
{
TMOD = 0X20;
TH1 = 0XFD;
TR1 = 1;
TI = 1;
}*/

//////////////////////////////////MAIN FUN////////////////////////////////////
void main()
{

unsigned char arr[]="Temperature,";

//ser_int();
led=0xff23;

I2C_START();
I2C_WRITE(0X9e); //slave address
I2C_WRITE(0X42); //slave cmd
while(1)
{
I2C_START();
I2C_WRITE(0x9f);
temp_read= I2C_READ();
lcd_dispaly(temp_read);
I2C_STOP();

I2C_START();
I2C_WRITE(0x9f);
temp_read=I2C_READ();
lcd_dispaly(temp_read);
I2C_STOP();
}
}

INFERENCE:
PIC 16F877
PROGRAMMING
USING
EMBEEDED C
Ex No :13
PWM generation of 3 phase inverters
INTRODUCTION:
OBJECTIVE:
To develop embedded C program for generation of pulse width modulation signal for
controlling of 3 phase inverter using PIC 16F877 controllers.
ACQUISITION
MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 PIC 16 Microcontroller - - 1
kit
2 PIC C Compiler
installed in PC

Program:
INFERENCE:
Ex No :14
Speed sensing and monitoring from PC
INTRODUCTION:
OBJECTIVE:
To develop embedded C program for Speed sensing and monitoring from PC using PIC
16F877 controllers.
ACQUISITION
MATERIALS REQUIRED

S.NO Apparatus Range Type Quantity


1 PIC16 Microcontroller - - 1
kit
2 PIC C Compiler
installed in PC

Program:
INFERENCE:
2F 1 ADD A,R7
Hex Number Mnemo- Operands 30 3 JNB bit addr, code addr
Code of Bytes nic 31 2 ACALL code addr
00 1 NOP 32 1 RETI
33 1 RLC A
01 2 AJMP code addr 34 2 ADDC A,#data
02 3 LJMP code addr 35 2 ADDC A,data addr
03 1 RR A 36 1 ADDC A,@R0
04 1 INC A 37 1 ADDC A,@R1
05 2 INC data addr 38 1 ADDC A,R0
06 1 INC @R0 39 1 ADDC A,R1
07 1 INC @R1 3A 1 ADDC A,R2
08 1 INC R0 3B 1 ADDC A,R3
09 1 INC R1 3C 1 ADDC A,R4
0A 1 INC R2 3D 1 ADDC A,R5
0B 1 INC R3 3E 1 ADDC A,R6
0C 1 INC R4 3F 1 ADDC A,R7
0D 1 INC R5 40 2 JC code addr
0E 1 INC R6 41 2 AJMP code addr
0F 1 INC R7 42 2 ORL data addr,A
10 3 JBC bit addr, code addr 43 3 ORL data addr,#data
11 2 ACALL code addr 44 2 ORL A,#data
12 3 LCALL code addr 45 2 ORL A,data addr
13 1 RRC A 46 1 ORL A,@R0
14 1 DEC A 47 1 ORL A,@R1
15 2 DEC data addr 48 1 ORL A,R0
16 1 DEC @R0 49 1 ORL A,R1
17 1 DEC @R1 4A 1 ORL A,R2
18 1 DEC R0 4B 1 ORL A,R3
19 1 DEC R1 4C 1 ORL A,R4
1A 1 DEC R2 4D 1 ORL A,R5
1B 1 DEC R3 4E 1 ORL A,R6
1C 1 DEC R4 4F 1 ORL A,R7
1D 1 DEC R5 50 2 JNC code addr
1E 1 DEC R6 51 2 ACALL code addr
1F 1 DEC R7 52 2 ANL data addr,A
20 3 JB bit addr, code addr 53 3 ANL data addr,#data
21 2 AJMP code addr 54 2 ANL A,#data
22 1 RET 55 2 ANL A,data addr
23 1 RL A 56 1 ANL A,@R0
24 2 ADD A,#data 57 1 ANL A,@R1
25 2 ADD A,data addr 58 1 ANL A,R0
26 1 ADD A,@R0 59 1 ANL A,R1
27 1 ADD A,@R1 5A 1 ANL A,R2
28 1 ADD A,R0 5B 1 ANL A,R3
29 1 ADD A,R1 5C 1 ANL A,R4
2A 1 ADD A,R2 5D 1 ANL A,R5
2B 1 ADD A,R3 5E 1 ANL A,R6
2C 1 ADD A,R4 5F 1 ANL A,R7
2D 1 ADD A,R5 60 2 JZ code addr
2E 1 ADD A,R6 61 2 AJMP code addr

8051 OpCodes en Hexadecinal. 1


62 2 XRL data addr,A 95 2 SUBB A,data addr
63 3 XRL data addr,#data 96 1 SUBB A,@R0
64 2 XRL A,#data 97 1 SUBB A,@R1
65 2 XRL A,data addr 98 1 SUBB A,R0
66 1 XRL A,@R0 99 1 SUBB A,R1
67 1 XRL A,@R1 9A 1 SUBB A,R2
68 1 XRL A,R0 9B 1 SUBB A,R3
69 1 XRL A,R1 9C 1 SUBB A,R4
6A 1 XRL A,R2 9D 1 SUBB A,R5
6B 1 XRL A,R3 9E 1 SUBB A,R6
6C 1 XRL A,R4 9F 1 SUBB A,R7
6D 1 XRL A,R5 A0 2 ORL C,/bit addr
6E 1 XRL A,R6 A1 2 AJMP code addr
6F 1 XRL A,R7 A2 2 MOV C,bit addr
70 2 JNZ code addr A3 1 INC DPTR
71 2 ACALL code addr A4 1 MUL AB
72 2 ORL C,bit addr A5 reserved
73 1 JMP @A+DPTR A6 2 MOV @R0,data addr
74 2 MOV A,#data A7 2 MOV @R1,data addr
75 3 MOV data addr,#data A8 2 MOV R0,data addr
76 2 MOV @R0,#data A9 2 MOV R1,data addr
77 2 MOV @R1,#data AA 2 MOV R2,data addr
78 2 MOV R0,#data AB 2 MOV R3,data addr
79 2 MOV R1,#data AC 2 MOV R4,data addr
7A 2 MOV R2,#data AD 2 MOV R5,data addr
7B 2 MOV R3,#data AE 2 MOV R6,data addr
7C 2 MOV R4,#data AF 2 MOV R7,data addr
7D 2 MOV R5,#data B0 2 ANL C,/bit addr
7E 2 MOV R6,#data B1 2 ACALL code addr
7F 2 MOV R7,#data B2 2 CPL bit addr
80 2 SJMP code addr B3 1 CPL C
81 2 AJMP code addr B4 3 CJNE A,#data,code addr
82 2 ANL C,bit addr B5 3 CJNE A,data addr,code addr
83 1 MOVC A,@A+PC B6 3 CJNE @R0,#data,code addr
84 1 DIV AB B7 3 CJNE @R1,#data,code addr
85 3 MOV data addr, data addr B8 3 CJNE R0,#data,code addr
86 2 MOV data addr,@R0 B9 3 CJNE R1,#data,code addr
87 2 MOV data addr,@R1 BA 3 CJNE R2,#data,code addr
88 2 MOV data addr,R0 BB 3 CJNE R3,#data,code addr
89 2 MOV data addr,R1 BC 3 CJNE R4,#data,code addr
8A 2 MOV data addr,R2 BD 3 CJNE R5,#data,code addr
8B 2 MOV data addr,R3 BE 3 CJNE R6,#data,code addr
8C 2 MOV data addr,R4 BF 3 CJNE R7,#data,code addr
8D 2 MOV data addr,R5 C0 2 PUSH data addr
8E 2 MOV data addr,R6 C1 2 AJMP code addr
8F 2 MOV data addr,R7 C2 2 CLR bit addr
90 3 MOV DPTR,#data C3 1 CLR C
91 2 ACALL code addr C4 1 SWAP A
92 2 MOV bit addr,C C5 2 XCH A,data addr
93 1 MOVC A,@A+DPTR C6 1 XCH A,@R0
94 2 SUBB A,#data C7 1 XCH A,@R1

8051 OpCodes en Hexadecinal. 2


C8 1 XCH A,R0 FB 1 MOV R3,A
C9 1 XCH A,R1 FC 1 MOV R4,A
CA 1 XCH A,R2 FD 1 MOV R5,A
CB 1 XCH A,R3 FE 1 MOV R6,A
CC 1 XCH A,R4 FF 1 MOV R7,A
CD 1 XCH A,R5
CE 1 XCH A,R6
CF 1 XCH A,R7 Instruction Opcodes in Hexadecimal Order
D0 2 POP data addr
D1 2 ACALL code addr
D2 2 SETB bit addr
D3 1 SETB C
D4 1 DA A
D5 3 DJNZ data addr,code addr
D6 1 XCHD A,@R0
D7 1 XCHD A,@R1
D8 2 DJNZ R0,code addr
D9 2 DJNZ R1,code addr
DA 2 DJNZ R2,code addr
DB 2 DJNZ R3,code addr
DC 2 DJNZ R4,code addr
DD 2 DJNZ R5,code addr
DE 2 DJNZ R6,code addr
DF 2 DJNZ R7,code addr
E0 1 MOVX A,@DPTR
E1 2 AJMP code addr
E2 1 MOVX A,@R0
E3 1 MOVX A,@R1
E4 1 CLR A
E5 2 MOV A,data addr
E6 1 MOV A,@R0
E7 1 MOV A,@R1
E8 1 MOV A,R0
E9 1 MOV A,R1
EA 1 MOV A,R2
EB 1 MOV A,R3
EC 1 MOV A,R4
ED 1 MOV A,R5
EE 1 MOV A,R6
EF 1 MOV A,R7
F0 1 MOVX @DPTR,A
F1 2 ACALL code addr
F2 1 MOVX @R0,A
F3 1 MOVX @R1,A
F4 1 CPL A
F5 2 MOV data addr,A
F6 1 MOV @R0,A
F7 1 MOV @R1,A
F8 1 MOV R0,A
F9 1 MOV R1,A
FA 1 MOV R2,A

8051 OpCodes en Hexadecinal. 3

You might also like