Documente Academic
Documente Profesional
Documente Cultură
DEPARTMENT OF
ELECTRONICS AND TELECOMMUNICATION
ENGINEERING
LABORATORY MANUAL
SEC4066
MICROCONTROLLERS LAB
(BATCH 2017-2021)
VI SEMESTER
NAME: _______________________
ROLL NO: _____________________
REGISTER NO: _________________
Total
SEC4066 MICROCONTROLLERS LAB L T P Credits
Marks
( ETCE) 0 0 4 2 100
LIST OF EXPERIMENTS
I. MICROCONTROLLER LAB
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
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
i) Type „G‟ followed by same starting address and then press “Enter”.
Example:
-G8000
PROGRAM:
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
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.
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.
Internal Memory:
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
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:
RESULT:
Thus the 8051 was studied
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
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.
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
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
40 42
41 43
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
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
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
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
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.
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
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
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
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:
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
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
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
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:
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:
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:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8001 8101
8002 8102
8003 8103
8004 8104
8005 8105
4.4 RESULT:
5.1 PROGRAM:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
41 42
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:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
43 44
5.2 RESULT:
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
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:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8000 8000
8001 8001
8002 8002
8003 8003
8004 8004
6.1 RESULT:
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:
INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8000 8000
8001 8001
8002 8002
8003 8003
8004 8004
6.2 RESULT:
7.1 PROGRAM:
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.
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:
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.
5. 12 ELEVATOR INTERFACE 60
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
WORKING PROCEDURE:
Open the Keil IDE through the desktop icon as shown below
A new window appears. Select a location to save the project. In that create a new folder
Then right click the Target folder under the Project workspace window and select Options
for Target
Then select Output tab under the options window and check Create hex file and give OK.
A text file appears, in that type the program for stepper motor
Then expand the Target folder under project workspace window and select add files to
group
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
Again it shows as 0 errors, if there are no errors. If there are errors check the project
creation procedure
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 appears in that open the location where the hex fils has been created. Select the
hex file and give open.
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.
ORG 00h
MOV TMOD,#01h
amp: MOV P1,#07fh
ACALL Delay
MOV P1,#00h
ACALL Delay
ljmp amp
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 30h
main: setb TCON.2 ; enabling edge detection
mov tmod,#01h ; using timer 0 mode 1
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.
RESULT:
An ALP to rotate a servo motor using uVision in Keil IDE is written and executed.
void main()
{ P0 = 0xFF; // Input declaration
P1 = 0x00; // Output declaration
P2 = 0x00;
P3 = 0x00;
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
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.
RESULT:
An ALP to control a miniature traffic light control model kit using uVision in Keil IDE is
written and executed.
#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 *);
bit ST3=1;
bit ST2=1;
bit ST1=1;
bit ST0=1;
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)
{
2. After creating a new project, right click the target folder under project workspace
window 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.
RESULT:
An ALP to control a miniature elevator model kit using uVision in Keil IDE is written and
executed.