0% found this document useful (0 votes)
75 views49 pages

Microcontroller and Interfacing Lab

This document contains a lab file for experiments with microcontrollers and interfacing. It includes 14 experiments involving programming 8051 and 8085 microcontrollers to perform tasks like addition, subtraction, multiplication, and interfacing with devices. The first 4 experiments involve writing programs to perform 8-bit and 16-bit addition and subtraction using the 8051 and 8085 microcontrollers. The remaining experiments involve programming the 8085 for multiplication, division, square root calculation, comparison, interfacing with an ADC, controlling LEDs and motors, and displaying characters on an 8x8 LED matrix.

Uploaded by

Akshat Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
75 views49 pages

Microcontroller and Interfacing Lab

This document contains a lab file for experiments with microcontrollers and interfacing. It includes 14 experiments involving programming 8051 and 8085 microcontrollers to perform tasks like addition, subtraction, multiplication, and interfacing with devices. The first 4 experiments involve writing programs to perform 8-bit and 16-bit addition and subtraction using the 8051 and 8085 microcontrollers. The remaining experiments involve programming the 8085 for multiplication, division, square root calculation, comparison, interfacing with an ADC, controlling LEDs and motors, and displaying characters on an 8x8 LED matrix.

Uploaded by

Akshat Mishra
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 49

MICROCONTROLLERS

AND INTERFACING LAB FILE


CONTENTS
S. Experiments
No.
Write a program using 8051 for Addition of two 8-bit numbers.

2. Write a program using 8051 for Addition of two 16-bit numbers.

3. Write a program using 8085 for Subtraction of two 8-bit


numbers.
4. Write a program using 8085 for Subtraction of two 16-bit
numbers.
5. Write a program using 8085 for Multiplication of Two 8-Bit
Numbers by Bit Rotation Method.
6. Write a program using 8085 for Division of Two 8-Bit Numbers
by Repeated Subtraction Method.
7. Write a program using 8085 for finding square-root of a number
& verify.
8. Write a program using 8085 and verify Smallest of two 8-bit
numbers.
9. Write a Program to Interface ADC with 8051.

10. Write a Program to Turn ‘ON’ and ‘OFF’ LEDs connected to


Port0.
11. Write a Program to alternate blink LEDs connected to Port1.

12. Write a Program to Interface D.C Motor to Microcontroller.

13. Write a Program to Interface Stepper Motor to Microcontroller.

14. Write a Program to display various characters on 8x8 LED


Matrix Display.
EXPERIMENT NO. 1
AIM
Write a program using 8051 for Addition of two 8-bit numbers.

THEORY
Intel 8051 is an 8-bit microcontroller. It has many powerful instructions and IO
accessing techniques. In this section, we will see one of the simplest program
using 8051.
Here we will add two8-bit numbers using this microcontroller. The register
A(Accumulator) is used as one operand in the operations. There are seven
registers R0 – R7 in different register banks. We can use any of them as the
second operand.
We are taking two number 5FH and D8H at location 20H and 21H, After adding
them, the result will be stored at location 30H and 31H.

Address Value

20H 5FH

21H D8H

30H 00H

31H 00H

PROGRAM
MOVR0,#20H;set source address 20H to R0
MOVR1,#30H;set destination address 30H to R1
MOVA,@R0; take the value from source to register A
MOVR5,A; Move the value from A to R5
MOVR4,#00H; Clear register R4 to store carry
INCR0; Point to the next location
MOVA,@R0; take the value from source to register A
ADDA,R5;Add R5 with A and store to register A
JNC SAVE
INCR4; Increment R4 to get carry
MOVB,R4;Get carry to register B
MOV@R1,B; Store the carry first
INCR1; Increase R1 to point to the next address
SAVE: MOV@R1,A;Store the result
HALT: SJMP HALT ;Stop the program
So by adding 5FH + D8H, the result will be 137H. The 01H will be stored at 30H,
and 37 is stored at 31H.

OUTPUT

Address Value

20H 5FH

21H D8H

30H 01H

31H 37H

EXPERIMENT NO. 2
AIM
Write a program using 8051 for Addition of two 16-bit numbers.

THEORY
As there is only one 16-bit Register in 89C51, 16-bit addition is performed by
using ADDC instruction twice, i.e. adding LSD first and MSD next.
DATAM1 – 12; DATAM2 = 56.
DATAM1 – MSD OF DATA1,
DATAM2 – MSD OF DATA2,
DATAL1 – LSD OF DATA1,
DATAL2 – LSD OF DATA2.

PROGRAM
MOV DPTR,#8501H
MOVX A,@DPTR
MOV B,A
MOV DPTR,#8503H
MOVX A,@DPTR
ADDC A,B
MOV DPTR,#8601H
MOVX @DPTR,A
MOV DPTR,#8500H
MOVX A,@DPTR
MOV B,A
MOV DPTR,#8502H
MOVX A,@DPTR
ADDC A,B
MOV DPTR,#8600H
MOVX @DPTR,A
E: SJMP E

RESULT
[8550] = AC (LSB);
[8551] = 68 (MSB).
DATAL1 – 34;
DATAL2 = 78.
Thus the Addition of two 16 bit numbers is stored in the resultant memory.
EXPERIMENT NO. 3
AIM
Write a program using 8085 for Subtraction of two 8-bit numbers.

INTRODUCTION

Microprocessor 8085
Microprocessor: A silicon chip that contains a CPU. In the world of personal
computers, the terms microprocessor and CPU are used interchangeably. A
microprocessor (sometimes abbreviated µP) is a digital electronic component
with miniaturized transistors on a single semiconductor integrated circuit (IC).
One or more microprocessors typically serve as a central processing unit (CPU)
in a computer system or handheld device. Microprocessors made possible the
advent of the microcomputer. At the heart of all personal computers and most
working stations sits a microprocessor. Microprocessors also control the logic
of almost all digital devices, from clock radios to fuel-injection systems for
automobiles.
Three basic characteristics differentiate microprocessors:
Instruction set: The set of instructions that the microprocessor can execute.
Bandwidth: The number of bits processed in a single instruction.
Clock speed: Given in megahertz (MHz), the clock speed determines how many
instructions per second the processor can execute.

THEORY
1. ORG Addr. Directive reserves the starting address for Program Code or data
in specified memory array,
2. LXI H (LOAD REGISTER PAIR IMMEDIATELY) loads 16 bit data in register pair
designated by operand.
3. LHLD Addr. (LOAD HL PAIR DIRECT) loads 16 bit data from specified address
to designate in register pair.
4. MOV A, M copies the data byte into accumulator from the memory specified
by the address in H-L pair.
5. MVI (MOVE IMMEDIATE DATA) moves immediate value to specified register.
6. SBB instruction subtracts specified register content and carry flag to
Accumulator and store results into Accumulator.
7. JNC Addr. Instruction jump the execution to the specified Address if carry
flag is reset.
8. INR instruction increment the specified register content by 1.
9. INX H (INCREMENT REGISTER PAIR) increments the contents of the register
pair by one.
10. SUB M (SUBTRACTION) subtracts the contents of register to accumulator.
11. STA address (STORE ACCUMULATOR DIRECT) copies the contents of the
accumulator to the memory location specified in the instruction
12. SHLD Addr. (STORE HL DIRECT) instruction store HL pair content to
specified address.

 
PROGRAM
# ORG 7000H
LXI H, 7501 // Get address of ist no. in HL pair
MOV A, M // Move no. into accumulator
INX H // HL points 7502 H.
SBB M // Substract 2nd no. from Ist no.
INX H //HL points 7503 H.
MOV M, A // Move contents of acc. to memory
RST 1 // Terminate
#ORG 7501H // Store no. at address
#DB 20,10 // Get the two 8 bit no. at successive location

RESULT
Input: 7501- 20H, 7502- 10H ;
Output: 7503- 10H
EXPERIMENT NO. 4
AIM
Write a program using 8085 for Subtraction of two 16-bit numbers.

INTRODUCTION

Microprocessor 8085
Microprocessor: A silicon chip that contains a CPU. In the world of personal
computers, the terms microprocessor and CPU are used interchangeably. A
microprocessor (sometimes abbreviated µP) is a digital electronic component
with miniaturized transistors on a single semiconductor integrated circuit (IC).
One or more microprocessors typically serve as a central processing unit (CPU)
in a computer system or handheld device. Microprocessors made possible the
advent of the microcomputer. At the heart of all personal computers and most
working stations sits a microprocessor. Microprocessors also control the logic
of almost all digital devices, from clock radios to fuel-injection systems for
automobiles.
Three basic characteristics differentiate microprocessors:
Instruction set: The set of instructions that the microprocessor can execute.
Bandwidth: The number of bits processed in a single instruction.
Clock speed: Given in megahertz (MHz), the clock speed determines how many
instructions per second the processor can execute.

THEORY
1. ORG Addr. Directive reserves the starting address for Program Code or data
in specified memory array,
2. LXI H (LOAD REGISTER PAIR IMMEDIATELY) loads 16 bit data in register pair
designated by operand.
3. LHLD Addr. (LOAD HL PAIR DIRECT) loads 16 bit data from specified address
to designate in register pair.
4. MOV A, M copies the data byte into accumulator from the memory specified
by the address in H-L pair.
5. MVI (MOVE IMMEDIATE DATA) moves immediate value to specified register.
6. SBB instruction subtracts specified register content and carry flag to
Accumulator and store results into Accumulator.
7. JNC Addr. Instruction jump the execution to the specified Address if carry
flag is reset.
8. INR instruction increment the specified register content by 1.
9. INX H (INCREMENT REGISTER PAIR) increments the contents of the register
pair by one.
10. SUB M (SUBTRACTION) subtracts the contents of register to accumulator.
11. STA address (STORE ACCUMULATOR DIRECT) copies the contents of the
accumulator to the memory location specified in the instruction
12. SHLD Addr. (STORE HL DIRECT) instruction store HL pair content to
specified address.
PROGRAM
# ORG 7000H
LHLD 7501 // Get 1st 16 bit no. in HL pair
XCHG // Exchange HL pair with DE.
LHLD 7503 // Get 2nd 16 bit no. in HL pair
MOV A, E // Get lower byte of ist no.
SUB L // Subtract lower byte of 2nd no.
MOV L, A // Store the result in reg. L
MOV A, D // Get higher byte of Ist no.
SBB H // Subtract higher byte of 2nd no. with borrow
MOV H,A // Move from acc. To H
SHLD 7505 // Store 16 bit result at 7505 H &7506 H
RST 1 // Terminate
# ORG 7501H // Store inputs at the address
# DB 30,40,10,20 // Get two 16 bit no. from successive locations

RESULT
Input: 7501- 30H, 7502- 40H, 7503- 10H, 7504- 20H ;
Output: 7505- 20H, 7506- 20H
EXPERIMENT NO. 5
AIM
Write a program using 8085 for Multiplication of Two 8-Bit Numbers by Bit
Rotation Method.

INTRODUCTION

Microprocessor History:
A microprocessor is also known as a CPU or central processing unit – a
complete computation engine that is fabricated on a single chip. The first
microprocessor was the Intel 4004 (4-bit CPU, 4k bit memory locations, 45
instructions, Speed 50KIPS), introduced in 1971. The 4004 was not very
powerful - all it could do was add and subtract, and it could only do that 4 bits
at a time. But it was amazing that everything was on one chip. Prior to the
4004, engineers built computers either from collections of chips or from
discrete components (transistors wired one at a time). The 4004 powered one
of the first portable electronic calculators.
In the world of personal computers, the terms microprocessor and CPU are
used interchangeably. At the heart of all personal computers and most
workstations sits a microprocessor. Microprocessors also control the logic of
almost all digital devices, from clock radios to fuel-injection systems for
automobiles.
8008 (later in 1971) : and extended 8-bit version of 4004, memory size: 16k
bytes, 48 instructions, 50KIPS.
8080 (1973) : 8-bit CPU, 64k byte memory, 500KIPS.
8088/8086 (1977,1978 ) : 16bit CPU, 1M byte memory, 2.5MIPS.
80186 : a similar version of 8086, it has more instructions.
80286 (1983) : an extended 16M-byte memory of 8086, 8MHz CPU, 4MIPS.
80386 (1986) : fully 32-bit CPU, up to 4G byte memory, hardware memory
management and memory assignment. Pipelined instruction execution
33MIPS. 80486 (DX, SX) (1989).
THEORY
1. LXI H (LOAD REGISTER PAIR IMMEDIATELY) loads 16 bit data in register pair
designated by operand.
2. XCHG (EXCHANGE) exchange HL with DE pair.
3. LDA (LOAD ACCUMULATOR) copies the address content to accumulator.
4. LHLD Addr. (LOAD HL PAIR DIRECT) loads 16 bit data from specified address
to designate in register pair.
5. MOV A, M copies the data byte into accumulator from the memory specified
by the address in H-L pair.
6. MVI (MOVE IMMEDIATE DATA) moves immediate value to specified register.
7. DAD instruction Add specified register pair content to HL pair content and
store results into HL pair.
8. SUB (SUBTACTION) subtracts register content to accumulator and stores
result into accumulator.
9. CMP (COMPARE WITH ACCUMULATOR) compares the register/memory
content to accumulator
If (A) < (Reg/Mem) ; carry flag is set and zero flag is reset.
If (A) = (Reg/Mem) ; carry flag is reset and zero flag is set.
If (A) > (Reg/Mem) ; both carry flag and zero flag are reset.
10. JNC Addr. Instruction jump the execution to the specified Address if carry
flag is reset.
11. RAL (ROTATE ACCUMULATOR LEFT THROUGH CARRY)
12. DCR instruction decrement the specified register content by 1.
13. STA address (STORE ACCUMULATOR DIRECT) copies the contents of the
accumulator to the memory location specified in the instruction
14. SHLD Addr. (STORE HL DIRECT) instruction store HL pair content to
specified address.
15. JNC Addr. (JUMP IF NO CARRY) jump to specified address if carry flag reset.
PROGRAM
# ORG 7000H
LHLD 7501 // Get Multiplicand in H-L pair.
XCHG // Exchange HL pair with DE pair
LDA 7503 // Get 2nd no. in acc.
LXI H,0000 // Initial product in HL=00
MVI C,08 // Count=08 in reg .C
up:DAD H // Shift partial product left by 1 bit
RAL // Rotate multi. by 1 bit. Is multiplier = 1?
JNC down // No, go to ahead
DAD D // Product=Product + Multiplicand
down:DCR C // Decrement Count
JNZ up // Jump until C=0
SHLD 7504 // Store result
RST 1 // Terminate
#ORG 7501H // Store inputs at the address
# DB 25,00,05 // Get the numbers from successive locations

RESULT
Input: 7501- 25H, 7502- 00H, 7503- 05H ;
Output: 7504- B9H, 7505- 00H
EXPERIMENT NO. 6
AIM
Write a program using 8085 for Division of Two 8-Bit Numbers by Repeated
Subtraction Method.

INTRODUCTION

Microprocessor History:
A microprocessor is also known as a CPU or central processing unit – a
complete computation engine that is fabricated on a single chip. The first
microprocessor was the Intel 4004 (4-bit CPU, 4k bit memory locations, 45
instructions, Speed 50KIPS), introduced in 1971. The 4004 was not very
powerful - all it could do was add and subtract, and it could only do that 4 bits
at a time. But it was amazing that everything was on one chip. Prior to the
4004, engineers built computers either from collections of chips or from
discrete components (transistors wired one at a time). The 4004 powered one
of the first portable electronic calculators.
In the world of personal computers, the terms microprocessor and CPU are
used interchangeably. At the heart of all personal computers and most
workstations sits a microprocessor. Microprocessors also control the logic of
almost all digital devices, from clock radios to fuel-injection systems for
automobiles.
8008 (later in 1971) : and extended 8-bit version of 4004, memory size: 16k
bytes, 48 instructions, 50KIPS.
8080 (1973) : 8-bit CPU, 64k byte memory, 500KIPS.
8088/8086 (1977,1978 ) : 16bit CPU, 1M byte memory, 2.5MIPS.
80186 : a similar version of 8086, it has more instructions.
80286 (1983) : an extended 16M-byte memory of 8086, 8MHz CPU, 4MIPS.
80386 (1986) : fully 32-bit CPU, up to 4G byte memory, hardware memory
management and memory assignment. Pipelined instruction execution
33MIPS.
80486 (DX, SX) (1989) : an improvement of 80386, 50MIPS, with built-in math
processor (for floating-point and extended-precision number operations).

THEORY
1. LXI H (LOAD REGISTER PAIR IMMEDIATELY) loads 16 bit data in register pair
designated by operand.
2. XCHG (EXCHANGE) exchange HL with DE pair.
3. LDA (LOAD ACCUMULATOR) copies the address content to accumulator.
4. LHLD Addr. (LOAD HL PAIR DIRECT) loads 16 bit data from specified address
to designate in register pair.
5. MOV A, M copies the data byte into accumulator from the memory specified
by the address in H-L pair.
6. MVI (MOVE IMMEDIATE DATA) moves immediate value to specified register.
7. DAD instruction Add specified register pair content to HL pair content and
store results into HL pair.
8. SUB (SUBTACTION) subtracts register content to accumulator and stores
result into accumulator.
9. CMP (COMPARE WITH ACCUMULATOR) compares the register/memory
content to accumulator
If (A) < (Reg/Mem) ; carry flag is set and zero flag is reset.
If (A) = (Reg/Mem) ; carry flag is reset and zero flag is set.
If (A) > (Reg/Mem) ; both carry flag and zero flag are reset.
10. JNC Addr. Instruction jump the execution to the specified Address if carry
flag is reset.
11. RAL (ROTATE ACCUMULATOR LEFT THROUGH CARRY)
12. DCR instruction decrement the specified register content by 1.
13. STA address (STORE ACCUMULATOR DIRECT) copies the contents of the
accumulator to the memory location specified in the instruction
14. SHLD Addr. (STORE HL DIRECT) instruction store HL pair content to
specified address.
15. JNC Addr. (JUMP IF NO CARRY) jump to specified address if carry flag reset.

PROGRAM
# ORG 7000H
LDA 7501 // [7501]=>A (Divisor)
MOV B,A // Take divisor in reg,B
LDA 7502 // Take dividend in reg,A
MVI C,00 // Quotient=00
CMP B // Compare A to B
JC down // Jump if carry
up:SUB B // Dividend-divisor=>A
INR C // C=C+1
CMP B // Is dividend < divisor
JNC up // If not,go back
down:STA 7503 // Store Remainder
MOV A,C // C=>A
STA 7504 // Store Quotient
RST 1 // Terminate
# ORG 7501H // Store the inputs at the address
# DB 06,26 // Get the numbers from successive loc.

RESULT
Input: 7501- 06H, 7502- 26H ;
Output: 7503- 02H, 7504- 06H
EXPERIMENT NO. 7
AIM
Write a program using 8085 for finding square-root of a number & verify.

INTRODUCTION
Microprocessor 8085 Interrupts:
Interrupt is a mechanism by which an I/O or an instruction can suspend the
normal execution of processor and get itself serviced. Generally, a particular
task is assigned to that interrupt signal. In the microprocessor based system
the interrupts are used for data transfer between the peripheral devices and
the microprocessor. The processor will check the interrupts always at the 2nd
T-state of last machine cycle.
Interrupt Service Routine (ISR):-A small program or a routine that when
executed services the corresponding interrupting source is called as an ISR.
Maskable/Non-Maskable Interrupt :- An interrupt that can be disabled by
writing some instruction is known as Maskable Interrupt otherwise it is called
Non-Maskable Interrupt.
There are 6 pins available in 8085 for interrupt:
TRAP
RST 7.5
RST6.5
RST5.5
INTR
INTA
Execution of Interrupts:-
When there is an interrupt requests to the Microprocessor then after
accepting the interrupts Microprocessor send the INTA (active low) signal to
the peripheral. The vectored address of particular interrupt is stored in
program counter. The processor executes an interrupt service routine (ISR)
addressed in program counter.
THEORY
1. MOV A, M copies the data byte into accumulator from the memory specified
by the address in H-L pair.
2. MVI (MOVE IMMEDIATE DATA) moves immediate value to specified register.
3. DAD instruction Add specified register pair content to HL pair content and
store results into HL pair.
4. SUB (SUBTACTION) subtracts register content to accumulator and stores
result into accumulator.
5. CMP (COMPARE WITH ACCUMULATOR) compares the register/memory
content to accumulator
If (A) < (Reg/Mem) ; carry flag is set and zero flag is reset.
If (A) = (Reg/Mem) ; carry flag is reset and zero flag is set.
If (A) > (Reg/Mem) ; both carry flag and zero flag are reset.
6. JZ Addr. instruction jump the execution to the specified Address if zero flag
is set.
7. JMP (JUMP UNCONDITIONAL) instruction jump the execution to the
specified Address
8. RAL (ROTATE ACCUMULATOR LEFT THROUGH CARRY)
9. DCR instruction decrement the specified register content by 1.
10. ADD M (ADDTION) adds the contents of memory to accumulator.
11. STA address (STORE ACCUMULATOR DIRECT) copies the contents of the
accumulator to the memory location specified in the instruction
12. SHLD Addr. (STORE HL DIRECT) instruction store HL pair content to
specified address.
13. JNC Addr. (JUMP IF NO CARRY) jump to specified address if carry flag reset.
14. RST 1 (RESET) finishes the execution of the current instruction and stops
any further execution.
15. DB Directive is defined to store values in specified memory array.
PROGRAM
# ORG 2000H
MVI C,01 // Place 01 in reg.C
MVI B,01 // Place odd number 1 in reg.B
MVI A,24 // Load accumulator with the given number
up:SUB B // Subtract odd number from the accumulator
JZ down // If accumulator contents are zero, go to Ahead
INR C // Increment reg. C
INR B // Increment odd number
INR B // Increment odd number
JMP up // Repeat subtraction
down:MOV A,C // Move the contents of C to A
STA 2050 // Store the result in the memory location 2050H.
RST 1 // Stop

RESULT
Input: A-24 H ;
Output: A-06, 2050- 06 H
EXPERIMENT NO. 8
AIM
Write a program using 8085 and verify Smallest of two 8-bit numbers.

THEORY
This checking is done by using the CMP instruction. This instruction is very
similar to the SUB instruction. The only difference is that it does not update the
value of Accumulator after executing. So after comparing, if the CY flag is set, it
means that the first number is smaller, and the second one is larger
Inputs

First Input:

Address Data

8000 FD

8001 23

Second Input:

Address Data

8000 59

8001 75

. .
. .
. .

Flow Diagram
PROGRAM

Address HEX Label Mnemonics Comments


Codes

F000 21, 00, 80 LXI Point to the first number


H,8000H

F003 46 MOV B,M Load the first number to B

F004 23 INX H Point to next location


Address HEX Label Mnemonics Comments
Codes

F005 7E MOV A,M Get the second number to A

F006 B8 CMP B Compare B with A

F007 DA, 0B, JC STORE Is CY = 1,jump to Store


F0

F00A 78 MOV A,B Load A with second number

F00B 32, 50, 80 STORE STA 8050H Store the number into memory

F00E 76 HLT Terminate the program

OUTPUT
First Output:

Address Data

8050 23

Second Output:

Address Data

8050 59

EXPERIMENT NO. 9
AIM
Write a Program to Interface ADC with 8051.

THEORY
Most modern microcontrollers with 8051 IP cores have an inbuilt ADC. Older
versions of 8051 like the MCS-51 and A789C51 do not have an on-chip ADC.
Therefore to connect these microcontrollers to analog sensors like
temperature sensors, the microcontroller needs to be hooked to an ADC. It
converts the analog values to digital values, which the microcontroller can
process and understand.

PROGRAM
Assembly language program to interface ADC with 8051:
ORG 0000H; Starting address
MOV P1,#0FFH; Makes port 1 input port
SETB P2.7; Makes EOC pin high
CLR P2.4; Clears ALE pin
CLR P2.6; Clears Start pin
CLR P2.5; Clears OE pin
BACK: CLR P2.2; Clears ADD C
SETB P2.1; Sets ADD B
CLR P2.0; Clears ADD A (this selects the second address line)
ACALL DELAY
SETB P2.4; Sets ALE high
ACALL DELAY
SETB P2.6; sends a command to start conversion
ACALL DELAY
CLR P2.4; makes ALE low
CLR P2.6; makes Start pin low
HERE: JB P2.7,HERE; waits for low pulse at EOC
HERE1: JNB P2.7,HERE1; waits for low pulse to finish
SETB P2.5; enables OE pin to extract data from ADC
ACALL DELAY
MOV A,P1; moves acquired data to accumulator
CLR P2.5; clears OE
SJMP BACK; repeatedly gets data from ADC
DELAY: MOV R3,#50
HERE2: MOV R4,#255
HERE3: DJNZ R4,HERE3
DJNZ R3,HERE2
RET
END

C program to interface ADC 0808 with 8051:


#include <reg51.h>
sbit ALE = P2^4;
sbit OE = P2^5;
sbit SC = P2^6;
sbit EOC = P2^7;
sbit ADDR_A = P2^0;
sbit ADDR_B = P2^1;
sbit ADDR_C = P2^2;
sfr MYDATA =P1;
sfr SENDDATA =P3;
void MSDelay(unsighned int) // Function to generate time delay
{
unsighned int i,j;
for(i=0;i<delay;i++)
for(j=0;j<1275;j++);
}
void main()
{
unsigned char value;
MYDATA = 0xFF;
EOC = 1;
ALE = 0;
OE = 0;
SC = 0;
while(1)
{
ADDR_C = 0;
ADDR_B = 0;
ADDR_A = 0;
MSDelay(1);
ALE = 1;
MSDelay(1);
SC = 1;
MSDelay(1);
ALE = 0;
SC = 0;
while(EOC==1);
while(EOC==0);
OE=1;
MSDelay(1);
value = MYDATA;
SENDDATA = value;
OE = 0 ;
}
}

RESULT
The program to Interface ADC with 8051 has been successfully written &
executed.
EXPERIMENT NO. 10
AIM
Write a Program to Turn ‘ON’ and ‘OFF’ LEDs connected to Port0.

THEORY
The circuit diagram for interfacing push button switch to 8051 is shown below.
AT89S51 is the microcontroller used here. The circuit is so designed that when
push button S1 is depressed the LED D1 goes ON and remains ON until push
button switch S2 is depressed and this cycle can be repeated. Resistor R3,
capacitor C3 and push button S3 forms the reset circuitry for the
microcontroller. Capacitor C1, C2 and crystal X1 belongs to the clock circuitry.
R1 and R2 are pull up resistors for the push buttons. R4 is the current limiting
resistor for LED.
PROGRAM
MOV P0,#83H // Initializing push button switches and initializing LED in OFF
state.
READSW: MOV A,P0 // Moving the port value to Accumulator.
RRC A // Checking the vale of Port 0 to know if switch 1 is ON or not
JC NXT // If switch 1 is OFF then jump to NXT to check if switch 2 is ON
CLR P0.7 // Turn ON LED because Switch 1 is ON
SJMP READSW // Read switch status again.
NXT: RRC A // Checking the value of Port 0 to know if switch 2 is ON or not
JC READSW // Jumping to READSW to check status of switch 1 again (provided
switch 2 is OFF)
SETB P0.7 // Turning OFF LED because Switch 2 is ON
SJMP READSW // Jumping to READSW to read status of switch 1 again.
END
The Logic:
The first instruction – MOV P0 #83H – is to turn LED off (Hex 83 in binary =
10000011) and to initialize switches 1 and 2. Switch 1 is connected to port 0.0
and switch 2 is connected to port 0.1. Also note that LED is connected to port
0.7.

RESULT
The Program to Turn ‘ON’ and ‘OFF’ LEDs connected to port 0 has been
successfully written and executed.
EXPERIMENT NO. 11
AIM
Write a Program to alternate blink LEDs connected to Port1.

THEORY
The microcontroller used here is AT89S51 In the circuit, push button switch S1,
capacitor C3 and resistor R3 forms the reset circuitry. When S1 is pressed,
voltage at the reset pin (pin9) goes high and this resets the chip. C1, C2 and X1
are related to the on chip oscillator which produces the required clock
frequency. P1.0 (pin1) is selected as the output pin. When P1.o goes high the
transistor Q1 is forward biased and LED goes ON. When P1.0 goes low the
transistor goes to cut off and the LED extinguishes. The transistor driver circuit
for the LED can be avoided and the LED can be connected directly to the P1.0
pin with a series current limiting resistor(~1K). The time for which P1.o goes
high and low (time period of the LED) is determined by the program. The
circuit diagram for blinking 1 LED is shown below.
Blinking 2 LED alternatively using 8051:
This circuit can blink two LEDs alternatively. P1.0 and P1.1 are assigned as the
outputs. When P1.0 goes high P1.0 goes low and vice versa and the LEDs follow
the state of the corresponding port to which it is connected. Here there is no
driver stage for the LEDs and they are connected directly to the corresponding
ports through series current limiting resistors (R1 & R2). Circuit diagram is
shown below.

PROGRAM
Program for Blinking LED 1:
START: CPL P1.0
ACALL WAIT
SJMP START
WAIT: MOV R4,#05H
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
RET

Program for Blinking LED 2:


START: CPL P1.0
ACALL WAIT
CPL P1.0
CPL P1.1
ACALL WAIT
CPL P1.1
SJMP START
WAIT: MOV R4,#05H
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
RET

RESULT
The program to alternate blink LEDs has been successfully written & executed.
EXPERIMENT NO. 12
AIM
Write a Program to Interface D.C Motor to Microcontroller.

THEORY
Interfacing DC motor to 8051 forms an essential part in designing embedded
robotic projects. A well designed 8051-DC motor system has essentially two
parts. Firstly an 8051 with the required software to control the motor and
secondly a suitable driver circuit. Most of the DC motors have power
requirements well out of the reach of a microcontroller and more over the
voltage spikes produced while reversing the direction of rotation could easily
damage the microcontroller. So it is not wise to connect a DC motor directly to
the microcontroller. The perfect solution is to use a motor driver circuit in
between the microcontroller and the DC motor.
L293 Motor Driver:
L293 is a dedicated quadruple half H bridge motor driver IC available in 16 pin
package. To know more about H bridge, check this link. H bridge motor driver
circuit. L293 has a current capacity of 600mA/channel and has supply voltage
range from 4.5 to 36V DC. They are fitted with internal high speed clamp
diodes for inductive spike protection. Other good features of L293 are high
noise immunity, internal ESD protection, thermal shutdown, separate input
supply for each channel etc. The pinout and truth table of an L293 motor driver
is shown in the figure below.
Bi Directional D.C Motor using 8051:
This project describes a bidirectional DC motor that changes its direction
automatically after a preset amount of time (around 1S). AT89S51 is the
microcontroller used here and L293 forms the motor driver. Circuit diagram is
shown below.

In the circuit components R1, S1 and C3 forms a debouncing reset circuitry. C1,
C2 and X1 are related to the oscillator. Port pins P1.0 and P1.1 are connected
to the corresponding input pins of the L293 motor driver. The motor is
connected across output pins 3 and 6 of the L293. The software is so written
that the logic combinations of P1.0 and P1.1 controls the direction of the
motor. Initially when power is switched ON, P1.0 will be high and P1.1 will be
low. This condition is maintained for a preset amount of time (around 1S) and
for this time the motor will be running in the clockwise direction (refer the
function table of L293). Then the logic of P1.0 and P1.1 are swapped and this
condition is also maintained for the same duration . This makes the motor to
run in the anti clockwise direction for the same duration and the entire cycle is
repeated.
PROGRAM
ORG 00H // initial starting address
MAIN: MOV P1,#00000001B // motor runs clockwise
ACALL DELAY // calls the 1S DELAY
MOV P1,#00000010B // motor runs anti clockwise
ACALL DELAY // calls the 1S DELAY
SJMP MAIN // jumps to label MAIN for repaeting the cycle
DELAY: MOV R4,#0FH
WAIT1: MOV R3,#00H
WAIT2: MOV R2,#00H
WAIT3: DJNZ R2,WAIT3
DJNZ R3,WAIT2
DJNZ R4,WAIT1
RET
END

RESULT
The Program to Interface D.C Motor to Microcontroller has been successfully
written & executed.
EXPERIMENT NO. 13
AIM
Write a Program to Interface Stepper Motor to Microcontroller.

THEORY
Stepper Motor:
Stepper motor is a brush less motor which converts electrical pulses into
mechanical rotation. As the name indicates it rotates in steps according to the
input pulses. A stepper motor usually have a number of field coils (phases) and
a toothed rotor. The step size of the motor is determined by the number of
phases and the number of teeth on the rotor. Step size is the angular
displacement of the rotor in one step. If a stepper motor has 4 phases and 50
teeth, it takes 50×4=200 steps to make one complete rotation. So step angle
will be 360/200=1.8°.

The stepper motor we are using has 4 poles and a 1/64 reduction gear
mechanism for increasing torque. The step angle of the motor is 5.64°. But
when considering the reduction gear, the step angle of the output shaft is
5.64/64°. The internal schematic of the stepper motor is given below.
The stepper motor is rotated by switching individual phases ON for a given
time one by one. The sequence is given in the graph below.
Circuit Diagram:

PROGRAM
A1 EQU P1.0
A2 EQU P1.1
A3 EQU P1.2
A4 EQU P1.3
ORG 00H
MOV TMOD,#00000001B
MAIN:
CLR A1
ACALL DELAY
SETB A1
CLR A2
ACALL DELAY
SETB A2
CLR A3
ACALL DELAY
SETB A3
CLR A4
ACALL DELAY
SETB A4
SJMP MAIN
DELAY:MOV R6,#1D
BACK: MOV TH0,#00000000B
MOV TL0,#00000000B
SETB TR0
HERE2: JNB TF0,HERE2
CLR TR0
CLR TF0
DJNZ R6,BACK
RET
END

RESULT
The Program to Interface Stepper Motor to Microcontroller has been
successfully written & executed.
EXPERIMENT NO. 14
AIM
Write a Program to display various characters on 8x8 LED Matrix Display.

THEORY
LED Dot Matrix Display:
An LED Dot Matrix Display consists of a matrix of LED’s arranged in a
rectangular configuration. The desired character or graphics can be displayed
by switching ON /OFF a desired configuration of LED’s. Common display
configurations available are 7×5, 8×8, 7×15, etc. LED dot matrix can be used in
simple display applications where the resolution is not a big concern. The
figure below shows the arrangement of LEDs in a typical 7×5 dot matrix
display.

Any individual LED or a group of LEDs in the matrix can be activated by


switching the required number of rows and columns. For example, in the
above figure if Row1 is made high and Column1 is made low, the top left LED
(address R1C1) will glow. As a demonstration, lets see how we can display
letter “A” using the display. The tables given below shows the logic levels at
each pin for displaying A.
In the above diagram you can see that only one LED in a row will be ON at a
time but any number of LEDs in a column can be ON at a time. That means
the microcontroller’s port pin can directly drive a row but it requires
additional circuit for driving the column lines. The circuit diagram for
interfacing dot matrix display and 8051 microcontroller is shown below.

Circuit Diagram:

ULN2003A Driver IC:

The purpose of ULN2003A here is to drive the column lines of the display.
ULN2003A is a high voltage (50V), high current (500mA per channel) darlington
transistor array. Each IC has 7 channels with individual output clamp diodes.
ULN2003A an active high device, which means a logic high must be applied to
the input to make the corresponding output high. The input pins are
designated as 1B, 2B, 3B, 4B, 5B, 6B, 7B while corresponding output pins are
designated as 1C, 2C, 3C, 4C, 5C, 6C, 7C. The pin configuration and simplified
internal logic of ULN2003A is shown in the figure below.
PROGRAM
ORG 00H
MOV P3,#00000000B // initializes port 3 as output port
MOV P1,#00000000B // initializes port 1 as output port
MAIN: MOV P3,#01111110B
MOV P1,#11111110B
ACALL DELAY
MOV P3,#00010001B
MOV P1,#11111101B
ACALL DELAY
MOV P3,#00010001B
MOV P1,#11111011B
ACALL DELAY
MOV P3,#00010001B
MOV P1,#11110111B
ACALL DELAY
MOV P3,#01111110B
MOV P1,#11101111B
ACALL DELAY
SJMP MAIN // jumps back to the main loop
DELAY: MOV R6,#255D // 1ms delay subroutine
HERE: DJNZ R6,HERE
RET
END

RESULT
The program to display various characters on 8x8 LED Matrix Display has been
successfully written & executed.

You might also like