Sunteți pe pagina 1din 66

SATHYABAMA

INSTITUTE OF SCIENCE AND TECHNOLOGY

JEPPIAAR NAGAR, RAJIV GANDHI SALAI,


CHENNAI - 600119

DEPARTMENT OF
ELECTRONICS AND TELECOMMUNICATION
ENGINEERING
LABORATORY MANUAL

SEC4066

MICROCONTROLLERS LAB

(BATCH 2017-2021)
VI SEMESTER

NAME: _______________________
ROLL NO: _____________________
REGISTER NO: _________________

Lab Conducted by Department of Electronics and Telecommunication Engineering


SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
SYLLABUS

Total
SEC4066 MICROCONTROLLERS LAB L T P Credits
Marks
( ETCE) 0 0 4 2 100

LIST OF EXPERIMENTS
I. MICROCONTROLLER LAB

SUGGESTED LIST OF EXPERIMENTS


1. Study of 8051
2. 8 Bit Addition and subtraction
3. 8 bit multiplication and division
4. Addition & Subtraction of sixteen bit numbers.
5. Transferring a Block of data - Internal to External memory, External to External memory and,
External to
Internal memory
6. 8-bit Conversion - ASCII to equivalent Hexa decimal and vice versa, Hexa to Decimal and
vice-versa
7. Largest and smallest number from the given array
8. Arrange the given numbers in ascending and descending order
9. Find the factorial of a given numbers
10. Segregation of odd and even numbers
11. Find the square root of a given numbers
12. Filling External and Internal Memory
13. DAC Interfacing
14. Stepper Interfacing
15. Servo Interfacing
16. ADC Interfacing
17. Elevator Interfacing

MICROCONTROLLER LAB III YEAR (V SEM)


2
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

I. MICROCONTROLLER LAB
LIST OF EXPERIMENTS
INDEX
SL. EXERCISE PAGE
EXPERIMENTS
NO NUMBER NUMBER
1. 1. STUDY OF 8051. 7
2. 2. 8 BIT ARITHMETIC OPERATIONS: ADDITION, SUBTRACTION,
13
MULTIPLICATION AND DIVISION
3. 3. ADDITION OF TWO SIXTEEN BIT NUMBERS. 22
4. 4. TRANSFERRING A BLOCK OF DATA FROM
(I) INTERNAL TO EXTERNAL MEMORY,
25
(II) EXTERNAL TO EXTERNAL MEMORY AND,
(III) EXTERNAL TO INTERNAL MEMORY
5. 5. 8-BIT CONVERSION
(I) ASCII TO ITS EQUIVALENT HEXADECIMAL AND 30
(II) HEXADECIMAL TO ITS EQUIVALENT ASCII
6. 6. ARRANGE THE GIVEN NUMBERS IN ASCENDING AND
33
DESCENDING ORDER
7. 7. FILLING EXTERNAL AND INTERNAL MEMORY 36

MICROCONTROLLER LAB III YEAR (V SEM)


3
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

KEYING PROCEDURE FOR 8051 KIT

1) For Assembling a Program

i) Type „A‟ followed by starting address and then press “Enter”.


Example:
-A8000
ii) Type the instruction using MNEMONICS.
iii) For keying new line press “ENTER” and type the instruction.
iv) Press “ENTER” key twice to exit after keying the program

2) For checking a program

i) Type „D‟ followed by the same starting address and then press “Enter”.
Example:
–D8000
ii) For checking next line press “SPACEBAR” key
iii) Press “ENTER” key after checking all the instructions

2) For Keying Input

i) Type „I / M‟ followed by Input memory address and then press “Enter”.


Example:
–I40 (FOR INTERNAL MEMORY)
–M9000 (FOR EXTERNAL MEMORY)

4) For Executing a Program

i) Type „G‟ followed by same starting address and then press “Enter”.
Example:
-G8000

5) For Viewing Output

i) Type „I / M‟ followed by Output memory address and then press “Enter”.


Example:
–I60 (FOR INTERNAL MEMORY)
–M9100 (FOR EXTERNAL MEMORY)

MICROCONTROLLER LAB III YEAR (V SEM)


4
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
LAYOUT OF 8051 MICROCONTROLLER KIT

MICROCONTROLLER LAB III YEAR (V SEM)


5
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
RECORD NOTEBOOK / OBSERVATION WRITING FORMAT
FOR MICROCONTROLLER LAB ONLY
LEFT HAND SIDE RIGHT HAND SIDE
(UNRULED) (RULED)
1 FLOWCHART 1 AIM
2 SAMPLE INPUT & OUTPUT 2 APPARATUS REQUIRED
3 ALGORITHM
4 PROGRAM
5 RESULT

PROGRAM:

MEMORY HEX MNEMONICS


LABEL COMMENTS
ADDRESS CODE OPCODE OPERAND

SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
MEMORY MEMORY
DATA DATA
ADDRESS ADDRESS

** The above format is tentative and can be done according to the instruction of the concerned lab
Incharge

MICROCONTROLLER LAB III YEAR (V SEM)


6
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

8051 MICROCONTROLLER PROGRAMMING


Expt. No: 1
Date:
1. STUDY OF 8051.

AIM:
To study the 8051 Microcontroller

THEORY:

The INTEL 8051 is an 8 bit microcontroller with 128 byte internal RAM and 4K bytes
internal ROM.

The 8051 is a 40 pin IC available in Dual in line package (DIP) and it requires a
single power supply of +5V.

BLOCK DIAGRAM OF 8051 MICROCONTROLLER.

Figure 1.1 8051 Block Diagram

MICROCONTROLLER LAB III YEAR (V SEM)


7
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
The 8051 architecture consists of the following special features.

 8 bit CPU with registers A and B


 16 bit Program Counter(PC) and Data Pointer(DPTR)
 8 bit Program Status Word(PSW)
 8 bit Stack Pointer(SP)
 Internal ROM or EPROM of 4K bytes
 Internal RAM of 128 bytes.
o 4 Register banks , each containing 8 registers
o 16 bytes ,which may be addressed at the bit level
o 80 bytes of general purpose memory
 32 input / output pins are arranged as four 8 bit ports : P0-P3
 Two 16 bit timer / counters : T0 and T1
 Full duplex serial data receiver / transmitter : SBUF
 Control registers :TCON,TMOD,SCON,PCON,IP and IE
 2 external and 3 internal interrupt sources
 Oscillator and Clock circuits.

The 8051 Oscillator and Clock:

 The heart of the 8051 is the circuitry that generates the clock pulses
by which all internal operations are synchronized.
 Pins XTAL1 and XTAL2 are provided for connecting a resonant
network to form an oscillator.

Program Counter (PC) and Data Pointer (DPTR):

 PC and DPTR are used to hold the address of a byte in memory.


 PC is the only register that does not have an internal address.
 The DPTR register is made up of two 8 bit registers namely DPH
and DPL.
 DPTR does not have a single internal address.

A and B CPU Registers:

 The 8051 contains 34 general purpose or working registers.


 Two of these registers A and B hold results of many instructions,
particularly math and logical operations.

MICROCONTROLLER LAB III YEAR (V SEM)


8
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
 The other 32 are arranged as part of internal RAM in four banks B0-
B3 each of 8 registers.
 The A(accumulator) register is the most versatile of the 2 CPU
registers
 The B register is used with A register for Multiplication and Division
operation.
Flags and Program Status Word(PSW):

 Flags are 1 bit registers provided to store the results of certain


program instructions.
 The 8051 has 4 math flags include Carry(C),Auxiliary
Carry(AC),Overflow(OV) and Parity(P)
 The 8051 has 2 User fags namely GF0,GF1
 The PSW contains the math flags, user program flag F0 and
register select bits that identify which of the 4 general purpose
register banks is currently in use by the program

Internal Memory:

 The 8051 has internal RAM and ROM memory.


 Additional memory can be added externally using suitable circuits.

MICROCONTROLLER LAB III YEAR (V SEM)


9
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

Figure 1.2 Internal RAM Organization

Internal RAM:
 The 128 byte internal RAM address from 00h to 7Fh
 32 bytes from 00h to 1Fh - 32 working registers
 16 bytes from 20h to 2Fh - 128 addressable bits
 from 30h to 7Fh - General purpose

Internal ROM:
 An internal ROM occupies code address space 0000h to
0FFFh

Stack and Stack Pointer (SP):

 The Stack refers to an area of internal RAM that is used in


conjunction with certain opcodes to store and retrieve data quickly.

MICROCONTROLLER LAB III YEAR (V SEM)


10
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
 The 8 bit SP register is used to hold an internal RAM address that
is top of the stack.

Special Function Registers (SFR):

 The 8051 operations that do not use the internal 128 byte RAM
addresses from 00h to 7Fh are done by a group of special internal
registers each called a Special Function Register(SFR).
 It’s addresses from 80h to FFh

Interrupts:

 5 interrupts are provided in 8051


 3 interrupt Timer Flag Interrupts (FF0, TF1) and serial port
interrupts (RI or TI) are generated internally.
 2 interrupts INT0 and INT1 are generated externally.

MICROCONTROLLER LAB III YEAR (V SEM)


11
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Pin Diagram:
The 8051 is a 40 pin IC available in Dual in line package (DIP)

Figure 1.3 Pin diagram of 8051

RESULT:
Thus the 8051 was studied

MICROCONTROLLER LAB III YEAR (V SEM)


12
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Expt. No: 2
Date:

2. 8 BIT ARITHMETIC OPERATIONS:


ADDITION, SUBTRACTION, MULTIPLICATION AND DIVISION

2.1.1. Addition of two 8-bit numbers stored in internal memory


2.1.2. Subtraction of two 8-bit numbers stored in internal memory.
2.1.3. Multiplication of two 8-bit numbers stored in internal memory.
2.1.4. Division of two 8-bit numbers stored in internal memory.

2.2.1. Addition of two 8-bit numbers stored in external memory


2.2.2. Subtraction of two 8-bit numbers stored in external memory.
2.2.3. Multiplication of two 8-bit numbers stored in external memory.
2.2.4. Division of two 8-bit numbers stored in external memory.

Exercise 2.1.1:
Write a program to add two 8-bit numbers stored in internal memory of 8051.
2.1.1 AIM:

To write an ALP for 8051 kit to add two 8-bit numbers stored in its internal memory.

2.1.1 ALGORITHM:
Step 1 : Start.
Step 2 : Load the first data into Register A
Step 3 : Load the second data in register R0
Step 4 : Add the second data with first data
Step 5 : Store the result in destination address
Step 6 : Copy the Carry in Register A and then store it in destination
Step 7 : End program

2.1.1 PROGRAM:
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
9000 MOV A, 40 Copy first data in Reg A
MOV R0, 41 Copy second data in R0
ADD A, R0 Add First and second data
MOV 42, A Store the Sum in destination
MOV A, #00 Initiate Reg A with 00H
ADDC A, #00 Copy Carry into Reg A
MOV 43, A Store carry in new destination
LCALL 00BB End the program

MICROCONTROLLER LAB III YEAR (V SEM)


13
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
2.1.1 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
40 42
41 43

2.1.1 RESULT:

An assembly language program using 8051 kit to perform the addition of two 8-bit
numbers stored in internal memory is written and executed

Exercise 2.1.2:
Write a program to subtract two 8-bit numbers stored in internal memory of 8051.
2.1.2 AIM:

To write an ALP for 8051 kit to subtract two 8-bit numbers stored in its internal memory.

2.1.2 ALGORITHM:
Step 1 : Start.
Step 2 : Clear the Carry/ Borrow Flag
Step 3 : Load first data in register A
Step 4 : Load second data in register R0
Step 5 : Subtract the second data from first data
Step 6 : Store the result in destination address
Step 7 : Copy the Borrow in Register A and then store it in destination
Step 8 End program

2.1.2 PROGRAM:
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
9000 CLR C Clear Carry/Borrow
MOV A, 40 Load first data in Reg A
MOV R0, 41 Load Second data in R0
SUBB A,R0 Subtract second data from First data
MOV 42, A Store the Result
MOV A, #00 Initiate Reg A with 00H
ADDC A, #00 Copy Borrow into Reg A
MOV 43, A Store borrow in new destination
LCALL 00BB End the program
Note: If first number is smaller than second number, compliment of answer is stored and
carry shall be 1.

MICROCONTROLLER LAB III YEAR (V SEM)


14
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
2.1.2 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
40 42
41 43

2.1.2 RESULT:

An assembly language program using 8051 kit to perform the subtraction of two 8-bit
numbers stored in internal memory is written and executed

Exercise 2.1.3:
Write a program to multiply two 8-bit numbers stored in internal memory of 8051.
2.1.3 AIM:

To write an ALP for 8051 kit to multiply two 8-bit numbers stored in its internal memory.

2.1.3 ALGORITHM:
Step 1 : Start.
Step 2 : Load first data in register A
Step 3 : Load second data in register B
Step 4 : Multiply both data in A and B
Step 5 : Store the Lower byte result in A to destination address
Step 6 : Store the higher byte in reg B in next destination address through Reg A
Step 7 : End program

2.1.3 PROGRAM:
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
9000 MOV A, 40 Load first data in A
MOV 0F0, 41 Load second data in B (0F0)
MUL AB Multiply two numbers
MOV 42, A Store Lower byte Product
MOV A, 0F0 Copy higher byte into A
MOV 43, A Store higher byte into the location
LCALL 00BB End the program

2.1.3 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
40 42
41 43

MICROCONTROLLER LAB III YEAR (V SEM)


15
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
2.1.3 RESULT:

An assembly language program using 8051 kit to perform the multiplication of two 8-
bit numbers stored in internal memory is written and executed

Exercise 2.1.4:
Write a program to divide two 8-bit numbers stored in internal memory of 8051.
2.1.4 AIM:

To write an ALP for 8051 kit to divide two 8-bit numbers stored in its internal memory.

2.1.4 ALGORITHM:
Step 1 : Start.
Step 2 : Load Numerator in Reg A
Step 3 : Load Denominator in Reg B
Step 4 : Divide Numerator by Denominator
Step 5 : Quotient in reg A stored in Destination address
Step 6 : Remainder in reg B stored in Destination address through reg A
Step 7 : End program

2.1.4 PROGRAM:
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
9000 MOV A, 40 Load Numerator in Reg A
MOV 0F0, 41 Load Denominator in Reg B
DIV AB Divide Reg A by B
MOV 42, A Store Quotient in Destination address
MOV A, 0F0 Copy Remainder in A
MOV 43, A Store Remainder Destination address
LCALL 00BB End the program

2.1.4 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
40 42
41 43

2.1.4 RESULT:

An assembly language program using 8051 kit to perform the division of two 8-bit
numbers stored in internal memory is written and executed

MICROCONTROLLER LAB III YEAR (V SEM)


16
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

Exercise 2.2.1:
Write a program to add two 8-bit numbers stored in external memory of 8051.
2.2.1 AIM:

To write an ALP for 8051 kit to add two 8-bit numbers stored in its external memory.

2.2.1 ALGORITHM:
Step 1 : Start.
Step 2 : Load the first data into Register R0 through Reg A
Step 3 : Load the second data in register A
Step 4 : Add the second data with first data
Step 5 : Store the result in destination address
Step 6 : Copy the Carry in Register A and then store it in destination
Step 7 : End program

2.2.1 PROGRAM:
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
9000 MOV DPTR, #8000 Initialize the Data Pointer to Source
MOVX A,@DPTR Load the first number into Reg A
MOV R0, A Copy the first number into R0
INC DPTR Increment data pointer
MOVX A,@DPTR Load the second number in reg A
ADD A, R0 Add both numbers
INC DPTR Increment data pointer
MOVX @DPTR, A Store the sum in next location
MOV A, #00 Initialize Reg A to zero
ADDC A,#00 Copy Carry into Reg A
INC DPTR Increment DPTR
MOVX @DPTR,A Store the Carry in Next location
LCALL 00BB End the program

2.2.1 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8000 8002
8001 8003

2.2.1 RESULT:

An assembly language program using 8051 kit to perform the addition of two 8-bit
numbers stored in external memory is written and executed

MICROCONTROLLER LAB III YEAR (V SEM)


17
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

Exercise 2.2.2:
Write a program to subtract two 8-bit numbers stored in external memory of 8051.
2.2.2 AIM:

To write an ALP for 8051 kit to subtract two 8-bit numbers stored in its external
memory.

2.2.2 ALGORITHM:
Step 1 : Start.
Step 2 : Clear the Carry/ Borrow Flag
Step 3 : Load first data in register A
Step 4 : Load second data in register R0
Step 5 : Subtract the second data from first data
Step 6 : Store the result in destination address
Step 7 : Copy the Carry in Register A and then store it in destination
Step 8 End program

2.2.2 PROGRAM:
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
9000 CLR C Reset the Carry/ Borrow Flag
MOV DPTR, #8000 Initialize the Data Pointer to Source
MOVX A,@DPTR Load the first number into Reg A
MOV R0, A Copy the first number into R0
INC DPTR Increment data pointer
MOVX A,@DPTR Load the second number in reg A
XCH A, R0 Swap that first number comes in reg A
SUBB A, R0 Subtract second number from first
number
INC DPTR Increment data pointer
MOVX @DPTR, A Store the sum in next location
MOV A, #00 Initialize Reg A to zero
ADDC A,#00 Copy Carry into Reg A
INC DPTR Increment DPTR
MOVX @DPTR,A Store the Carry in Next location
LCALL 00BB End the program

Note: If first number is smaller than second number, compliment of answer is stored and
carry shall be 1.

MICROCONTROLLER LAB III YEAR (V SEM)


18
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
2.2.2 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8000 8002
8001 8003

2.2.2 RESULT:

An assembly language program using 8051 kit to perform the subtraction of two 8-bit
numbers stored in external memory is written and executed

Exercise 2.2.3:
Write a program to multiply two 8-bit numbers stored in external memory of 8051.
2.2.3 AIM:

To write an ALP for 8051 kit to multiply two 8-bit numbers stored in its external memory.

2.2.3 ALGORITHM:
Step 1 : Start.
Step 2 : Load first data in register A
Step 3 : Load second data in register B
Step 4 : Multiply both data in A and B
Step 5 : Store the Lower byte result in A to destination address
Step 6 : Store the higher byte in reg B in next destination address through Reg A
Step 7 : End program

2.2.3 PROGRAM:
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
9000 CLR C Reset the Carry/ Borrow Flag
MOV DPTR, #8000 Initialize the Data Pointer to Source address
MOVX A,@DPTR Load the first number into Reg A
MOV 0F0, A Copy the first number into B
INC DPTR Increment data pointer
MOVX A,@DPTR Load the second number in reg A
MUL AB Multiply both the numbers
INC DPTR Increment data pointer
MOVX @DPTR, A Store the product in next location
MOV A, 0F0 Store the Carry in A from B
INC DPTR Increment DPTR
MOVX @DPTR,A Store the Carry in Next location
LCALL 00BB End the program

MICROCONTROLLER LAB III YEAR (V SEM)


19
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
2.2.3 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8000 8002
8001 8003

2.2.3 RESULT:

An assembly language program using 8051 kit to perform the multiplication of two 8-
bit numbers stored in external memory is written and executed

Exercise 2.2.4:
Write a program to divide two 8-bit numbers stored in external memory of 8051.
2.2.4 AIM:

To write an ALP for 8051 kit to divide two 8-bit numbers stored in its external memory.

2.2.4 ALGORITHM:
Step 1 : Start.
Step 2 : Load Numerator in Reg A
Step 3 : Load Denominator in Reg B
Step 4 : Divide Numerator by Denominator
Step 5 : Quotient in reg A stored in Destination address
Step 6 : Remainder in reg B stored in Destination address through reg A
Step 7 : End program

2.2.4 PROGRAM:
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
9000 CLR C Reset the Carry/ Borrow Flag
MOV DPTR, #8000 Initialize the Data Pointer to Source
MOVX A,@DPTR Load the first number into Reg A
MOV 0F0, A Copy the first number into B
INC DPTR Increment data pointer
MOVX A,@DPTR Load the second number in reg A
XCH A, 0F0 Load Numerator in Reg A
DIV AB Divide first number by second number
INC DPTR Increment data pointer
MOVX @DPTR, A Store the Quotient in next location
MOV A, 0F0 Copy the Remainder in A from B
INC DPTR Increment DPTR
MOVX @DPTR,A Store the Remainder in Next location
LCALL 00BB End the program

MICROCONTROLLER LAB III YEAR (V SEM)


20
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
2.2.4 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8000 8002
8001 8003

2.2.4 RESULT:

An assembly language program using 8051 kit to perform the division of two 8-bit
numbers stored in external memory is written and executed

MICROCONTROLLER LAB III YEAR (V SEM)


21
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Expt. No: 3
Date:
3. ADDITION OF TWO SIXTEEN BIT NUMBERS.
Exercise 3.1:
Write a program to add two 16-bit numbers stored in internal memory of 8051.
3.1 AIM:

To write an ALP for 8051 kit to add two 16-bit numbers stored in its internal memory.

3.1 ALGORITHM:
Step 1 : Start.
Step 2 : Copy the Lower byte of first data to register R0
Step 3 : Copy the Higher byte of first data to register R1
Step 4 : Copy the Lower byte of second data to register R2
Step 5 : Copy the Higher byte of second data to register R3
Step 6 : Add the lower bytes of both data in register R0 and R2
Step 7 : Store the lower byte sum in output address
Step 8 : Add the higher bytes of both data in register R1 and R3 with carry generated by
previous addition
Step 9 : Store the higher byte sum in output address
Step 10 : Copy the Carry generated into Reg A and store it in output address
Step 11 : End program

3.1 PROGRAM:
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
9000 MOV R0,40 Load Lower byte of first data in R0
MOV R1, 41 Load Higher byte of first data in R1
MOV R2, 42 Load Lower byte of Second data in R2
MOV R3, 43 Load Higher byte of second data in R3
MOV A,R0 Copy First Lower byte to Reg A
ADD A,R2 Add Both Lower Bytes
MOV 44,A Store the Lower byte SUM.
MOV A, R1 Copy First the Higher Byte to Reg A
ADDC A, R3 Add Both Higher Bytes with carry
MOV 45, A Store Higher Byte SUM
MOV A,#00 Initiate Reg A
ADDC A, #00 Copy CARRY into Reg A
MOV 46, A Store CARRY
LCALL 00BB End the program
3.1 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
40 44
41 45
42 46
43
3.1 RESULT:

MICROCONTROLLER LAB III YEAR (V SEM)


22
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
An assembly language program using 8051 kit to perform the addition of two 16-bit
numbers stored in internal memory is written and executed

Exercise 3.2:
Write a program to add two 16-bit numbers stored in external memory of 8051.
3.2 AIM:

To write an ALP for 8051 kit to add two 16-bit numbers stored in its external memory.

3.2 ALGORITHM:
Step 1 : Start.
Step 2 : Initiate first data address with DPTR as pointer
Step 3 : Copy the Lower byte of first data to register R0 through DPTR
Step 4 : Copy the Higher byte of first data to register R1 through DPTR
Step 5 : Copy the Lower byte of second data to register R2 through DPTR
Step 6 : Copy the Higher byte of second data to register R3 through DPTR
Step 7 : Add the lower bytes of both data in register R0 and R2
Step 8 : Store the lower byte sum in output address
Step 9 : Add the lower bytes of both data in register R1 and R3 with carry generated by
previous addition
Step 10 : Store the higher byte sum in output address
Step 11 : Copy the Carry generated into Reg A and store it in output address
Step 12 : End program
3.2 PROGRAM:
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
9000 MOV DPTR, #8000 Initiate DPTR for first address
MOVX A, @DPTR Load First Lower byte in A
MOV R0, A Copy it to R0
INC DPTR Move DPTR to next address
MOVX A, @DPTR Load First Higher byte in A
MOV R1, A Copy it to R1
INC DPTR Move DPTR to next address
MOVX A, @DPTR Load Second Lower byte in A
MOV R2, A Copy it to R2
INC DPTR Move DPTR to next address
MOVX A, @DPTR Load Second Higher byte in A
MOV R3, A Copy it to R3
MOV A, R0 Copy First Lower byte to A
ADD A, R2 Add two Lower bytes
INC DPTR Move DPTR to Next Location
MOVX @DPTR, A Store Lower byte SUM
MOV A, R1 Copy First Higher byte in A
ADDC A, R3 Add Higher bytes with carry
INC DPTR Move DPTR to next location
MOVX @DPTR, A Store Higher Byte SUM
MOV A, #00 Initiate A
ADDC A, #00 Copy Carry in Reg A
INC DPTR Move DPTR to next location
MOVX @DPTR, A Store CARRY
LCALL 00BB End the program

MICROCONTROLLER LAB III YEAR (V SEM)


23
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
3.2 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8000 8004
8001 8005
8002 8006
8003
3.2 RESULT:

An assembly language program using 8051 kit to perform the addition of two 16-bit
numbers stored in external memory is written and executed

MICROCONTROLLER LAB III YEAR (V SEM)


24
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Expt. No: 4
Date:
4. BLOCK DATA TRANSFER
4.1. Transferring a Block of data from internal memory to internal memory
4.2. Transferring a Block of data from internal memory to external memory
4.3. Transferring a Block of data from external memory to external memory
4.4. Transferring a Block of data from external memory to internal memory

Exercise 4.1:
Write a program to transfer a block of data stored in internal memory address
41H-45H to internal memory address 51H to 55 H.
4.1 AIM:

To write an ALP for 8051 kit to transfer a Block of data from internal memory (41H-45H
) to internal memory (51H to 55 H).

4.1 ALGORITHM:
Step 1 : Start.
Step 2 : Load the count of the block data into bank register R2
Step 3 : Load the starting source address into bank register R1
Step 4 : Load the starting destination address into bank register R0
Step 5 : Copy the data from source address by using R1 as pointer into register A
Step 6 : transfer the data from register A into destination address by using R0 as pointer
Step 7 : Increment the content of registers R0 and R1, for choosing next source and
destination for next data
Step 8 : Repeat the steps 5 to 7 until count is zero until all the contents of the block are
transferred.
Step 9 : End program.

4.1 PROGRAM:
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
9000 MOV R2,#05H Size of the array
MOV R1,#41H Starting addr of source
MOV R0,#51H Starting addr of destination
NEXT MOV A,@R1 Copy data byte
MOV R0,A transfer to destination
INC R1 Increment Source address
INC R0 Increment Destination address
DJNZ R2,NEXT Do until Count is zero
LCALL 00BB End Program

MICROCONTROLLER LAB III YEAR (V SEM)


25
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
4.1 SAMPLE INPUT & OUTPUT:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
41 51
42 52
43 53
44 54
45 55

Exercise 4.2:
Write a program to transfer a block of data stored in internal memory address
41H-45H to external memory address 8001H to 8005 H.
4.2 AIM:
To write an ALP for 8051 kit to transfer a Block of data from internal memory (41H-45H
) to external memory (8001H to 8005) H.
4.2 ALGORITHM:
Step 1 : Start.
Step 2 : Load the size of the array into bank register R2
Step 3 : Load the starting source address into bank register R1
Step 4 : Load the starting destination address into bank register DPTR
Step 5 : Copy the data from source address by using R1 as pointer into register A
Step 6 : transfer the data from register A into destination address by using DPTR as
pointer
Step 7 : Increment the content of registers DPTR and R1, for choosing next source and
destination for next data
Step 8 : Repeat the steps 5 to 7 until count is zero until all the contents of the block are
transferred.
Step 9 : End program.

4.2 PROGRAM:

Memory Hex Mnemonics


Label Comments
Address code Opcode Operand
9000 MOV R2,#05H Size of the array
MOV R1,#41H Starting addr of source
MOV DPTR,#8001H Starting addr of destination
NEXT MOV A,@R1 Copy data byte
MOVX @DPTR,A transfer to destination
INC R1 Increment Source address
INC DPTR Increment Destination address
DJNZ R2,NEXT Do until Count is zero
LCALL 00BB End Program

MICROCONTROLLER LAB III YEAR (V SEM)


26
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
4.2 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
41 8001
42 8002
43 8003
44 8004
45 8005

Exercise 4.3:
Write a program to transfer a block of data stored in external memory address
8001H to 8005 H to internal memory address 51H-55H.
4.3 AIM:
To write an ALP for 8051 kit to transfer a Block of data from external memory (8001H to
8005 H) to internal memory (51H-55H)
4.3 ALGORITHM:
Step 1 : Start.
Step 2 : Load the size of the array into bank register R2
Step 3 : Load the starting source address into bank register DPTR
Step 4 : Load the starting destination address into bank register R0
Step 5 : Copy the data from source address by using DPTR as pointer into register A
Step 6 : transfer the data from register A into destination address by using R0 as
pointer
Step 7 : Increment the content of registers R0 and DPTR, for choosing next source and
destination for next data
Step 8 : Repeat the steps 5 to 7 until count is zero until all the contents of the block are
transferred.
Step 9 : End program.

4.3 PROGRAM:

Memory Hex Mnemonics


Label Comments
Address code Opcode Operand
9000 MOV R2,#05H Size of the array
MOV dptr,#8001H Starting addr of source
MOV R0,#51H Starting addr of destination
NEXT MOV A,@R1 Copy data byte
MOV @R0,A transfer to destination
INC DPTR Increment Source address
INC R0 Increment Destination address
DJNZ R2,NEXT Do until Count is zero
LCALL 00BB End Program

MICROCONTROLLER LAB III YEAR (V SEM)


27
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
4.3 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8001 51
8002 52
8003 53
8004 54
8005 55

Exercise 4.4:
Write a program to transfer a block of data stored in external memory address
8001H to 8005 H to external memory address 8101H-8105H.
4.4 AIM:
To write an ALP for 8051 kit to transfer a Block of data from external memory (8001H to
8005 H) to internal memory (8101H-8105H)
4.4 ALGORITHM:
Step 1 : Start.
Step 2 : Load the size of the array into bank register R2
Step 3 : Load the starting source address into bank register DPTR
Step 4 : Load the starting destination address into bank register R0
Step 5 : Copy the data from source address by using DPTR as pointer into register A
Step 6 : transfer the data from register A into destination address by using R0 as pointer
Step 7 : Increment the content of registers R0 and DPTR, for choosing next source and
destination for next data
Step 8 : Repeat the steps 5 to 7 until count is zero until all the contents of the block are
transferred.
Step 9 : End program.

4.4 PROGRAM:

Memory Hex Mnemonics


Label Comments
Address code Opcode Operand
9000 MOV R2,#05H Size of the array
MOV 82,#01H Starting addr of source
LOOP MOV 83,#80H Starting addr of destination
MOVX A,@DPTR Copy data byte
MOV 83,#81H transfer to destination
MOVX @DPTR,A Increment Source address
INC DPTR Increment Destination address
DJNZ R2,LOOP Do until Count is zero
LCALL 00BB End Program

MICROCONTROLLER LAB III YEAR (V SEM)


28
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
4.4 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8001 8101
8002 8102
8003 8103
8004 8104
8005 8105

4.4 RESULT:

An assembly language program to perform Block Transfer operation between


memories using 8051 is written and executed.

MICROCONTROLLER LAB III YEAR (V SEM)


29
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Expt. No: 5
Date:
5. 8-BIT CONVERSION
(i) ASCII to its equivalent hexadecimal and
(ii) Hexadecimal to its equivalent ASCII
Exercise 5.1:
Write a program to convert ASCII to its equivalent Hexadecimal number.
5.1 AIM:
To write an ALP for 8051 kit to transfer an ASCII to its equivalent Hexadecimal number
5.1 ALGORITHM:
Step 1 : Start.
Step 2 : Initialize R1 to input address
Step 3 : Load Reg A with Input ASCII through R1
Step 4 : Increment R1 to next address for output Hexadecimal
Step 5 : Call the Subroutine for R1 to Hexadecimal Conversion
Step 6 : Check for Number 0 to 9. if its more than 9 then do CONV subroutine
Step 7 : ELSE do NUM subroutine
Step 8 Store the Result in Output address through R1.
Step 9 : End program.

5.1 PROGRAM:

Memory Hex Mnemonics


Label Comments
Address code Opcode Operand
9000 MOV R1,#41 Input thro R1
MOV A, @R1 Copy the Input in A
INC R1 Increment R1 to Output address
LCALL CONV LCALL 9100
LCALL 00BB End Program

9100 CONV CLR C Clear Carry/Borrow Register


SUBB A, #41 Subtract 10d from the Input
JC NUM If Borrow is there then Goto NUM
CLR C Copy R0 in A
SUBB A, #37 ASCII TO CHAR
MOV @R1, A Store the Result
RET
NUM CLR C Clear Carry/Borrow
SUBB A, #30
MOV @R1, A ASCII TO NUMBER
RET

5.1 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
41 42

MICROCONTROLLER LAB III YEAR (V SEM)


30
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
5.1 RESULT:

An assembly language program to transfer an ASCII to its equivalent Hexadecimal


number using 8051 is written and executed.

Exercise 5.2:
Write a program to convert Hexadecimal number to its equivalent ASCII.
5.2 AIM:
To write an ALP for 8051 kit to transfer a Hexadecimal number to an ASCII equivalent

5.2 ALGORITHM:
Step 1 : Start.
Step 2 : Initialize R1 to input address
Step 3 : Load Reg A with Input HEXA through R1
Step 4 : Increment R1 to next address for output Hexadecimal
Step 5 : Call the Subroutine for Hexadecimal to ASCII Conversion
Step 6 : Check for Number 0 to 9. if its more than 9 then do CONV subroutine
Step 7 : ELSE do NUM subroutine
Step 8 Store the Result in Output address through R1.
Step 9 : End program.

5.2 PROGRAM:

Memory Hex Mnemonics


Label Comments
Address code Opcode Operand
9000 MOV R1,#43 Input through R1
MOV A, @R1 Copy the Input in A
MOV R0, A Copy the input in R0
INC R1 Increment R1 to Output address
LCALL CONV LCALL 9100
LCALL 00BB End Program

9100 CONV CLR C Clear Carry/Borrow Register


SUBB A, #0A Subtract 10d from the Input
JC NUM If Borrow is there then Goto NUM
MOV A,R0 Copy R0 in A
ADD A, #37 CHAR TO ASCII
MOV @R1, A Store the Result
RET
NUM CLR C Clear Carry/Borrow
ADD A, #30 NUMBER TO ASCII
MOV @R1, A Store the Result
RET

5.2 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
43 44

5.2 RESULT:

MICROCONTROLLER LAB III YEAR (V SEM)


31
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

An assembly language program to transfer a Hexadecimal number to an ASCII


equivalent using 8051 is written and executed.

TABLE- ASCII-HEXADECIMAL

ASCII HEXA ASCII HEXA ASCII HEXA ASCII HEXA ASCII HEXA
30 0 41 A 50 P 61 a 70 p
31 1 42 B 51 Q 62 b 71 q
32 2 43 C 52 R 63 c 72 r
33 3 44 D 53 S 64 d 73 s
34 4 45 E 54 T 65 e 74 t
35 5 46 F 55 U 66 f 75 u
36 6 47 G 56 V 67 g 76 v
37 7 48 H 57 W 68 h 77 w
38 8 49 I 58 X 69 i 78 x
39 9 4A J 59 Y 6A j 79 y
4B K 5A Z 6B k 7A z
4C L 6C l
4D M 6D m
4E N 6E n
4F O 6F o

MICROCONTROLLER LAB III YEAR (V SEM)


32
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Expt. No: 6
Date:
6. ARRANGE THE GIVEN NUMBERS IN ASCENDING AND
DESCENDING ORDER

Exercise 6.1:
Write a program to arrange the given array of numbers in ascending order.
6.1 AIM:
To write an ALP for 8051 kit to arrange the given array of numbers in ascending order
6.1 ALGORITHM:
Step 1 : Start.
Step 2 : Copy Count of array in two registers
Step 3 : Initialize Input address through DPTR
Step 4 : Load first two numbers in A and another register
Step 5 : Compare both numbers
Step 6 : If First is less than second number, Leave as it is.
Step 7 : If First is greater than second number, swap the places of numbers and
again do it from first
Step 8 Do this until the array count becomes zero
Step 9 End program.

6.1 PROGRAM:

Memory Hex Mnemonics


Label Comments
Address code Opcode Operand
9000 MOV R0, #05 Initialize COUNT value to R0
NXT5 MOV R1, R0 Copy COUNT to R1
MOV DPTR, #8000 Initialize DPTR
NXT4 MOVX A, @DPTR Load the first number to A
MOV R2, A Copy First number in R2
INC DPTR Move DPTR to NEXT location
MOVX A, @DPTR Load the second Number in A
CJNE A,R2,NXT1 Compare A & R2 and go to NXT1
when not equal
NXT1 JC NXT2 When A is less than R2 go to NXT2
AJMP NXT3 Go to NXT3
NXT2 XCH A, R2 Exchange A and R2 contents
MOVX @DPTR,A Store Content in A to Destination
DEC 82 Decrement DPL
MOV A, R2 Copy Content of R2 to A
MOVX @DPTR, A Store Content in A to Destination
INC 82 Increment DPL
NXT3 DJNZ R1, NXT4 Decrement R1 and Go to NXT4 if not
Zero
DJNZ R0, NXT5 Decrement R0 and Go to NXT4 if not
Zero
LCALL 00BB End Program

MICROCONTROLLER LAB III YEAR (V SEM)


33
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
6.1 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8000 8000
8001 8001
8002 8002
8003 8003
8004 8004
6.1 RESULT:

An assembly language program to arrange the given array of numbers in ascending


order using 8051 is written and executed.

Exercise 6.2:
Write a program to arrange the given array of numbers in descending order.
6.2 AIM:
To write an ALP for 8051 kit to arrange the given array of numbers in descending order
6.2 ALGORITHM:
Step 1 : Start.
Step 2 : Copy Count of array in two registers
Step 3 : Initialize Input address through DPTR
Step 4 : Load first two numbers in A and another register
Step 5 : Compare both numbers
Step 6 : If First is greater than second number, Leave as it is.
Step 7 : If First is less than second number, swap the places of numbers and again
do it from first
Step 8 Do this until the array count becomes zero
Step 9 End program.

6.2 PROGRAM:

Memory Hex Mnemonics


Label Comments
Address code Opcode Operand
9000 MOV R0, #05 Initialize COUNT value to R0
NXT5 MOV R1, R0 Copy COUNT to R1
MOV DPTR, #8000 Initialize DPTR
NXT4 MOVX A, @DPTR Load the first number to A
MOV R2, A Copy First number in R2
INC DPTR Move DPTR to NEXT location
MOVX A, @DPTR Load the second Number in A
CJNE A,R2,NXT1 Compare A & R2 and go to NXT1
when not equal
NXT1 JNC NXT2 When A is More than R2 go to NXT2
AJMP NXT3 Go to NXT3
NXT2 XCH A, R2 Exchange A and R2 contents
MOVX @DPTR,A Store Content in A to Destination
DEC 82 Decrement DPL
MOV A, R2 Copy Content of R2 to A
MOVX @DPTR, A Store Content in A to Destination
INC 82 Increment DPL
NXT3 DJNZ R1, NXT4 Decrement R1 and Go to NXT4 if not

MICROCONTROLLER LAB III YEAR (V SEM)


34
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Memory Hex Mnemonics
Label Comments
Address code Opcode Operand
Zero
DJNZ R0, NXT5 Decrement R0 and Go to NXT4 if not
Zero
LCALL 00BB End Program

6.2 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8000 8000
8001 8001
8002 8002
8003 8003
8004 8004

6.2 RESULT:

An assembly language program to arrange the given array of numbers in ascending


order using 8051 is written and executed.

MICROCONTROLLER LAB III YEAR (V SEM)


35
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Expt. No: 7
Date:
7. FILLING EXTERNAL AND INTERNAL MEMORY
Exercise 7.1:
Write a program to fill the external memory with same data.
7.1 AIM:
To write an ALP for 8051 kit to fill the external memory with same data
7.1 ALGORITHM:
Step 1 : Start.
Step 2 : Initialize R0 to Count address
Step 3 : Initialize DPTR to the input & output address
Step 4 : Copy Data to be filled in Reg A
Step 5 : Increment the external Memory address using DPTR
Step 6 : Copy the data in Reg A to New address using DPTR
Step 7 : Repeat the above step 5 & 6 until Count in R0 is zero
Step 8 End program.

7.1 PROGRAM:

Memory Hex Mnemonics


Label Comments
Address code Opcode Operand
9000 MOV DPTR,#8500 Initialize Count in R0
MOVX A, @DPTR Initialize Input Data thro DPTR
MOV R0, A Copy Data in Reg A
INC DPTR Next Address
MOVX A, @DPTR
LOOP INC DPTR
MOVX @DPTR, A Fill Data in Address
DJNZ R0, LOOP Till Count is zero
LCALL 00BB End Program

7.1 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8500 05 (COUNT)** 8502
8501 34 (DATA)** 8503
8504
8505
8506
7.1 RESULT:

An assembly language program to fill the external memory with same data using 8051
is written and executed.

MICROCONTROLLER LAB III YEAR (V SEM)


36
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

Exercise 7.2:
Write a program to fill the internal memory with same data.
7.2 AIM:
To write an ALP for 8051 kit to fill the internal memory with same data
7.2 ALGORITHM:
Step 1 : Start.
Step 2 : Initialize R0 to Count address
Step 3 : Initialize R1 to the input & output address
Step 4 : Copy Data to be filled in Reg A
Step 5 : Increment the Internal Memory address using R1
Step 6 : Copy the data in Reg A to New address using R!
Step 7 : Repeat the above step 5 & 6 until Count in R0 is zero
Step 8 End program.

7.2 PROGRAM:

Memory Hex Mnemonics


Label Comments
Address code Opcode Operand
9000 MOV R0, 40 Initialize Count in R0
MOV R1, #41 Initialize Input Data thro R1
MOV A, @R1 Copy Data in Reg A
LOOP INC R1 Next Address
MOV @R1, A Fill Data in Address
DJNZ R0, LOOP Till Count is zero
LCALL 00BB End Program

7.2 SAMPLE INPUT & OUTPUT:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
40 05 (COUNT)** 42
41 2F (DATA)** 43
44
45
46
7. 2 RESULT:

An assembly language program to fill the internal memory with same data using 8051
is written and executed.
** Sample Data is given and any other data can be used with proper suggestions from the lab
incharge.

MICROCONTROLLER LAB III YEAR (V SEM)


37
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

II. EMBEDDED SYSTEMS LAB


LIST OF EXPERIMENTS
INDEX

SL. EXERCISE PAGE


EXPERIMENTS
NO NUMBER NUMBER
1. 8 STEPPER MOTOR INTERFACE 39

2. 9 DIGITAL TO ANALOG CONVERSION INTERFACE 53

3. 10 SERVO MOTOR INTERFACE 54

4. 11 TRAFFIC LIGHT CONTROLLER INTERFACE 56

5. 12 ELEVATOR INTERFACE 60

RECORD NOTEBOOK / OBSERVATION WRITING FORMAT


FOR EMBEDDED SYSTEM LAB ONLY
LEFT HAND SIDE RIGHT HAND SIDE
(UNRULED) (RULED)
1 PROGRAM 1 AIM
2 APPARATUS REQUIRED
3 RESULT

NOTE: ** WINDOWS DRAWING USED TO EXPLAIN THE SOFTWARE USAGE IS NOT


TO BE DRAWN.

MICROCONTROLLER LAB III YEAR (V SEM)


38
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Expt. No: 8
Date:
8. STEPPER MOTOR INTERFACE
Exercise 8:
Write and execute an ALP to rotate a stepper motor in both directions using
uVision in Keil IDE.
8. AIM:
To Write and execute an ALP to rotate a stepper motor in both directions using uVision
in Keil IDE
APPARATUS REQUIRED:
Keil IDE with uVision Software loaded in PC, Stepper motor with Interface kit.
PROGRAM FOR CLOCKWISE ROTATION:
org 00H
Pulse: mov P1, #05h
acall Delay
mov P1, #06h
acall Delay
mov P1, #0ah
acall Delay
mov P1, #09h
acall Delay
ljmp Pulse

Delay:
mov r2,100
l1: mov r3,225
l2: djnz r3,l2
djnz r2,l1
ret
end
PROGRAM FOR ANTI CLOCKWISE ROTATION:
org 00H
Pulse: mov P1, #05h
acall Delay
mov P1, #09h
acall Delay
mov P1, #0ah
acall Delay
mov P1, #06h
acall Delay
ljmp Pulse

Delay:
mov r2,100
l1: mov r3,225
l2: djnz r3,l2
djnz r2,l1
ret
end

MICROCONTROLLER LAB III YEAR (V SEM)


39
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

WORKING PROCEDURE:

Open the Keil IDE through the desktop icon as shown below

The window appears as follows

MICROCONTROLLER LAB III YEAR (V SEM)


40
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
In that create a new project through the option project -> New uVision project

A new window appears. Select a location to save the project. In that create a new folder

MICROCONTROLLER LAB III YEAR (V SEM)


41
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Give a name to that folder

Then give a name to that project and save it

MICROCONTROLLER LAB III YEAR (V SEM)


42
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
A window appears as shown. In that choose Atmel family controllers

And choose AT89S52 as the controller

MICROCONTROLLER LAB III YEAR (V SEM)


43
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Give No in the following window

Then right click the Target folder under the Project workspace window and select Options
for Target

MICROCONTROLLER LAB III YEAR (V SEM)


44
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
A window appears in that give the crystal frequecny as 11.0592

Then select Output tab under the options window and check Create hex file and give OK.

MICROCONTROLLER LAB III YEAR (V SEM)


45
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Go to File and Select new

A text file appears, in that type the program for stepper motor

MICROCONTROLLER LAB III YEAR (V SEM)


46
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Then save the file with extension .asm

Then expand the Target folder under project workspace window and select add files to
group

MICROCONTROLLER LAB III YEAR (V SEM)


47
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Then a window appears in that drop down the files of type option and select asm source as
shown

The asm file appears. Select the file and give add and then close the window. The file will
be added to the Source group as shown. Then select the translate option as shown

MICROCONTROLLER LAB III YEAR (V SEM)


48
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
If there are no errors, it shows as 0 errors under the Build window. If there are errors
correct the errors and translate it again. Then give build option

Again it shows as 0 errors, if there are no errors. If there are errors check the project
creation procedure

MICROCONTROLLER LAB III YEAR (V SEM)


49
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Then give rebuild all targets option. It too shows 0 errors if all the above procedures are
correct

Now connect the kit with PC through the USB cable provided. Check whether the toggle
switch is in program mode. Power ON the kit Then open the Progisp.exe icon on the
desktop.

A window as shown. In that select the controller as AT89S52 as shown

MICROCONTROLLER LAB III YEAR (V SEM)


50
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Select Load Flash option as shown

A window appears in that open the location where the hex fils has been created. Select the
hex file and give open.

MICROCONTROLLER LAB III YEAR (V SEM)


51
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
Then check whether Program flash and verify flash options are selected and then select
Auto option to program the controller. In case if any error occurs, check whether the USB
connection is proper and the kit is Powered ON.

Now unplug the USB cable. Power off the kit. Change the toggle switch to Run mode.
Connect the Embedded board with Stepper motor interface Card and also connect Motor
and Supply to the interface card.
Power On the kit. Now the motor runs.
For the anti clockwise operation follow the above same procedures. Change the program
for the Anticock wise Direction.

RESULT:

An ALP to rotate a stepper motor in both directions using uVision in Keil IDE has been
written and executed.

MICROCONTROLLER LAB III YEAR (V SEM)


52
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
EXP No. 9
Date:
DIGITAL TO ANALOG CONVERSION INTERFACE
Exercise 9:
Write and execute an ALP to produce square wave in CRO using DAC interface
with uVision in Keil IDE.
9. AIM:
To Write and execute an ALP to produce square wave in CRO using DAC interface with
uVision in Keil IDE
APPARATUS REQUIRED:
Keil IDE with uVision Software loaded in PC, DAC Interface kit, CRO
PROGRAM:

ORG 00h
MOV TMOD,#01h
amp: MOV P1,#07fh
ACALL Delay
MOV P1,#00h
ACALL Delay
ljmp amp

Delay: MOV TH0,#0F8H


MOV TL0,#0CDH
SETB TR0
Here: JNB TF0,Here
CLR TR0
CLR TF0
ret
END
PROCEDURE:
1. The project creation procedure for digital to analog conversion is same as the
Stepper motor procedure.
2. After creating and building the project, check whether the toggle switch is in pogram
mode. Connect the USB cable from PC to the kit. Download the hex file to the kit.
3. Power off the kit. Change the toggle switch to RUN mode. Connect the dac interface
card with controller board.
4. Connect an oscilloscope probe to the respective positive ad negative terminal
connectors of the DAC card
5. Now power On the kit. The square wave from the dac card can be seen in the
oscilloscope.
NOTE: After choosing the controller a window appears. In that choose Yes option. Then
follow the same procedures of stepper motor experiment after that.
RESULT:
An ALP to produce square wave in CRO using DAC interface with uVision in Keil IDE
has been written and executed.

MICROCONTROLLER LAB III YEAR (V SEM)


53
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
EXP No. 10
Date:
SERVO MOTOR INTERFACE
Exercise 10:
Write and execute an ALP to rotate servo motor using uVision in Keil IDE.
10. AIM:
To Write and execute an ALP to rotate servo motor using uVision in Keil IDE

APPARATUS REQUIRED:
Keil IDE with uVision Software loaded in PC, Servo motor with Interface kit.
PROGRAM:
org 00h
ljmp main ; jump to main routine

org 0013h ; interrupt address for external interrupt


inc r0
RETI

org 30h
main: setb TCON.2 ; enabling edge detection
mov tmod,#01h ; using timer 0 mode 1

mov ie,#84h ; enabling external interrupt 1


mov r0,#00h
back: cjne r0,#255,pwm ; value for number of rotations(0-255)
setb P3.2
cont: sjmp cont

pwm: setb P3.2


acall delay
clr P3.2
acall delay1
ljmp back

delay: mov th0,#0ffh ; timer routine for PWM ON time


mov tl0,#0f7h
setb tr0
here: jnb tf0,here
clr tr0
clr tf0
ret

delay1: mov th0,#0feh ; timer routine for PWM off time


mov tl0,#03dh
setb tr0
here1: jnb tf0,here1
clr tr0
clr tf0
ret
end

MICROCONTROLLER LAB III YEAR (V SEM)


54
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

WORKING PROCEDURE:
1. The project creation procedure for servo motor is same as the Stepper motor
procedure.

2. After creating and building the project. Check whether the toggle switch is in
program mode. Connect the USB cable to the kit. Download the hex file to the kit

3. Power off the kit. Connect the servo motor interface card with controller board.
Change the switch to run mode.

4. Now power On the kit. Now the motor runs for the given value of number of
rotations.

5. Now change the value for number of rotations in the program instruction cjne
r0,#255,pwm. The value can be from 1 to 255.

6. After changing the program, build the project and download the hex file to the kit.

7. Now again follow the steps 3 and 4 to run the program.

RESULT:
An ALP to rotate a servo motor using uVision in Keil IDE is written and executed.

MICROCONTROLLER LAB III YEAR (V SEM)


55
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
EXP No. 11
Date:
TRAFFIC LIGHT CONTROLLER INTERFACE
Exercise 11:
Write and execute an ALP to control a miniature traffic light control model kit
using uVision in Keil IDE.
11. AIM:
To Write and execute an ALP to control a miniature traffic light control model kit using
uVision in Keil IDE
APPARATUS REQUIRED:
Keil IDE with uVision Software loaded in PC, Traffic Light Control miniature model kit
with relevant Interface.
PROGRAM:
#include<reg52.h>

void msdelay(int num);

sbit NR = P3^2; // North Red


sbit NY = P2^0; // North Yellow
sbit NG = P2^1; // North Green
sbit NP = P2^2; // North Pedestrian crossing
sbit SR = P2^3; //
sbit SY = P3^3; //
sbit SG = P3^0; //
sbit StP = P3^1; // South Pedestrian crossing
sbit WtR = P1^0; // West Red
sbit WY = P1^1; //
sbit WG = P1^2; //
sbit WP = P1^3; //
sbit ER = P1^4; //
sbit EY = P1^5; //
sbit EG = P1^6; //
sbit EP = P1^7; //

sbit sw1 = P0^4; // switch for ON or OFF


sbit sw2 = P0^5; // switch for Day or Night
sbit sw3 = P0^6; // switch for Busy or Normal

void msdelay(int num)


{
unsigned int x,y;
for(x=0;x<1275;x++)
for(y=0;y<num;y++);
}

void main()
{ P0 = 0xFF; // Input declaration
P1 = 0x00; // Output declaration
P2 = 0x00;
P3 = 0x00;

MICROCONTROLLER LAB III YEAR (V SEM)


56
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
while(1)
{
if(sw2==1 && sw3==0) // Day & Normal
{
NG=1; SG=1; EG=0; WG=0;
NY=0; SY=0; EY=0; WY=0;
NR=0; SR=0; ER=1; WtR=1;
NP=1; StP=1;EP=0; WP=0;
msdelay(700);
NG=0; SG=0; EG=0; WG=0;
NY=1; SY=1; EY=0; WY=0;
NR=0; SR=0; ER=1; WtR=1;
NP=1; StP=1;EP=1; WP=1;
msdelay(200);
NG=0; SG=0; EG=1; WG=1;
NY=0; SY=0; EY=0; WY=0;
NR=1; SR=1; ER=0; WtR=0;
NP=0; StP=0;EP=1; WP=1;
msdelay(700);
NG=0; SG=0; EG=0; WG=0;
NY=0; SY=0; EY=1; WY=1;
NR=1; SR=1; ER=0; WtR=0;
NP=1; StP=1;EP=1; WP=1;
msdelay(200);
}
if(sw2==0 && sw3==0) // Night & Normal
{
NR=0; SR=0; ER=0; WtR=0; NG=0; SG=0; EG=0; WG=0;
NP=1; StP=1;EP=1; WP=1;
NY=~NY; SY=~SY; EY=~EY; WY=~WY;
msdelay(25);
}
if(sw3==1 && sw1==0) // Busy & OFF
{
NR=0; SR=0; ER=1; WtR=1; NG=1; SG=1; EG=0; WG=0;
NY=0; SY=0; EY=0; WY=0; NP=1; StP=1;EP=0; WP=0;
}
if(sw3==1 && sw1==1) // Busy & ON
{
NR=1; SR=1; ER=0; WtR=0; NG=0; SG=0; EG=1; WG=1;
NY=0; SY=0; EY=0; WY=0; NP=0; StP=0;EP=1; WP=1;
}
}

MICROCONTROLLER LAB III YEAR (V SEM)


57
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE

WORKING PROCEDURE:
1. The project creation procedure for Traffic Light Controller is same as the Stepper
motor procedure except with few changes

2. After selecting the controller while creating a new project, a window appears as
follows in that select yes.

3. After that type the program for traffic light and save the file with extension .c

MICROCONTROLLER LAB III YEAR (V SEM)


58
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
4. After that right click the soure target folder under the Project workspace window, add
the traffic light source file as shown below and close it.

5. Now build the project

6. After building the project. Check whether the toggle switch is in program mode.
Connect the USB cable to the kit. Download the hex file to the kit

7. Power off the kit. Connect the traffic light interface card with controller board.
Change the switch to run mode.

8. Now power On the kit. Now the traffic light works.

RESULT:
An ALP to control a miniature traffic light control model kit using uVision in Keil IDE is
written and executed.

MICROCONTROLLER LAB III YEAR (V SEM)


59
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
EXP No. 12
Date:
ELEVATOR INTERFACE
Exercise 12:
Write and execute an ALP to control a miniature elevator model kit using uVision
in Keil IDE.
12. AIM:
To Write and execute an ALP to control a miniature elevator model kit using uVision in
Keil IDE
APPARATUS REQUIRED:
Keil IDE with uVision Software loaded in PC, elevator miniature model kit with relevant
Interface.
PROGRAM:
/*THIS EXPERIMENT WILL SIMULATE THE MOVEMENT OF ELEVATOR
USING RTOS, THE ELEVATOR MOVEMENT IS IMPLEMENTED IN SINGLE TASK
THE PORT ASSIGNED ARE EXPLAINED AS FOLLOWS */
// P1 FOR 1 st floor & 2 nd floor MOVING LED
// P2 FOR 3 rd floor MOVING LED
// P3 FOR FLOOR LED

#include<reg51.h>
#include<absacc.h>
#include<rtx51tny.h>

void delay(void);
int status,count,ref_count;
int val1,val2,val3;
void forward(void);
void reverse(void);
void display( char *);

sbit SW3 = P0^3; // SWITCH FOR 0 FLOOR


sbit SW2 = P0^2; // SWITCH FOR 1 FLOOR
sbit SW1 = P0^1; // SWITCH FOR 2 FLOOR
sbit SW0 = P0^0; // SWITCH FOR 3 FLOOR

bit ST3=1;
bit ST2=1;
bit ST1=1;
bit ST0=1;

sbit FLOOR0 = P3^0; // LED FOR 0 FLOOR


sbit FLOOR1 = P3^1; // LED FOR 1 FLOOR
sbit FLOOR2 = P3^2; // LED FOR 2 FLOOR
sbit FLOOR3 = P3^3; // LED FOR 3 FLOOR

void process0 (void) _task_ 0


{
os_create_task(1);
os_create_task(2);

MICROCONTROLLER LAB III YEAR (V SEM)


60
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
os_delete_task(0);
}

void movement (void) _task_ 1


{
int i;
count =1;
P1 =0;P2 =0xF0;P3 =0; //CLEAR ALL THE PORT
FLOOR0 =1;
for(i=0;i<5;i++)
delay();

while(1)
{
if(!ST3) //switch of 3rd floor,if pressed
{
delay();
ref_count=13;
if(count < ref_count)
forward();
}
if(!ST2) //switch of 2nd floor
{ //switch open stage as "1"
delay();
ref_count=9;
if(count < ref_count)
forward();
if(count >ref_count)
reverse();
}
if(!ST1) //switch of 1st floor
{
delay();
ref_count=5;
if(count < ref_count)
forward();
if(count >ref_count)
reverse();
}
if(!ST0) //switch of gnd floor
{
delay();
ref_count=1;
if(count >ref_count)
reverse();
}
}
}
void status_update(void) _task_ 2
{
while(1)
{
if(SW0==0)
{

MICROCONTROLLER LAB III YEAR (V SEM)


61
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
FLOOR0 =1;
delay();
FLOOR0 =0;
ST0 = 0;
}
if(SW1==0)
{
FLOOR1 =1;
delay();
FLOOR1 =0;
ST1 = 0;
}
if(SW2==0)
{
FLOOR2 = 1;
delay();
FLOOR2 = 0;
ST2 = 0;
}
if(SW3==0)
{
FLOOR3 = 1;
delay();
FLOOR3 = 0;
ST3 = 0;
}
}
}

void forward(void) //function for moving forward direction


{
int temp1,temp2,temp3,i;
temp1 =0x01; temp2 =0x10,temp3=0x01;
count=count+1;
for(;count<ref_count;count++)
{
if(count<=4)
{
P1=temp1; //port 1 (lower )connection in gnd to 1st floor
led(green)
delay();
FLOOR0 =0; //(P3.0)connection in 2nd floor led(RED)
delay();
temp1=temp1<<1; //To make a right shift for LED moving
}
if(count ==4)
{
P1 =0;
FLOOR1 =1; //(P3.6)connection in 1 st floor led(RED)
if(ST1==0) //cheak for the second floor if any key
{ //has pressed
for(i=0;i<10;i++)
delay();
ST1 =1;

MICROCONTROLLER LAB III YEAR (V SEM)


62
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
}
delay();
}
if(count<=8 && count >=5)
{
P1 =temp2; //port 1 (higher )connection in 1st to 2nd
floor led(green)
delay();
FLOOR1=0;
delay();
temp2=temp2<<1;
}
if(count==8)
{
P1=0;
FLOOR2=1; //P3.2 connection in 2nd floor led(RED)
if(ST2==0) //cheak for the second floor if any key
{ //has pressed
for(i=0;i<10;i++)
delay();
ST2 =1;
}
delay();
}
if(count>=9)
{
P2=temp3|0xF0; //port 2 connection in 2nd to 3rd floor led(green)
delay();
FLOOR2=0;
delay();
temp3=temp3<<1;
}
if(count==12)
{
P2=0xF0;
FLOOR3=1; //(P3.3)connection in 3rd floor led(RED)
if(ST3==0) //cheak for the second floor if any key
{ //has pressed
for(i=0;i<10;i++)
delay();
ST3 =1;
}
delay();
}
}
}

void reverse(void) //function for moving reverse direction


{
int temp1,temp2,temp3,i;
temp1 = 0x08, temp2 =0x80,temp3 =0x08; //it is the reverse value of green led
count=count-1;
for(;count >=ref_count;count--)
{

MICROCONTROLLER LAB III YEAR (V SEM)


63
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
if(count<=4)
{
P1=temp3;
delay();
FLOOR1=0;
delay();
temp3 = temp3 >>1;
}
if(count ==1)
{
P1 =0;
FLOOR0=1;
if(ST0==0) //cheak for the second floor if any key
{ //has pressed
for(i=0;i<10;i++)
delay();
ST0 =1;
}
delay();
}
if(count<=8 && count >=5)
{
P1=temp2;
delay();
FLOOR2=0;
delay();
temp2 = temp2 >>1;
}
if(count==5)
{
P1 =0;
FLOOR1=1;
if(ST1==0) //cheak for the second floor if any key
{ //has pressed
for(i=0;i<10;i++)
delay();
ST1 =1;
}
delay();
}
if(count>=9)
{
P2=temp1|0xF0;
delay();
FLOOR3=0;
delay();
temp1 = temp1 >>1;
}
if(count==9)
{
P2 =0xF0; //eprom = 1;
FLOOR2=1;
if(ST2==0) //cheak for the second floor if any key
{ //has pressed

MICROCONTROLLER LAB III YEAR (V SEM)


64
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
for(i=0;i<10;i++)
delay();
ST2 =1;
}
delay();
}
}
}
void delay(void)
{
int i;
for(i=0;i<10;i++)
{
TMOD =0x10;
TH1 =0xD1;
TL1 =0x1F;
TR1 =1;
while(!TF1);
TF1 =0;
}
}
WORKING PROCEDURE:
1. The project creation procedure for Elevator is same as the Traffic Light Controller
procedure except with few changes

2. After creating a new project, right click the target folder under project workspace
window as shown.

MICROCONTROLLER LAB III YEAR (V SEM)


65
SATHYABAMA Institute of Science and Technology DEPT. OF ETCE
3. In the appearing window give the crytal frequency and under the Operating System
option choose RTX-51 Tiny as shown.

4. After building the project. Check whether the toggle switch is in program mode.
Connect the USB cable to the kit. Download the hex file to the kit

5. Power off the kit. Connect the elevator interface card with controller board. Change
the switch to run mode.

6. Now power On the kit. Now the elevator works.

RESULT:
An ALP to control a miniature elevator model kit using uVision in Keil IDE is written and
executed.

MICROCONTROLLER LAB III YEAR (V SEM)


66

S-ar putea să vă placă și