Tribhuvan University Institute of Engineering Pulchowk, Lalipur A Lab Report On Embedded System
Tribhuvan University Institute of Engineering Pulchowk, Lalipur A Lab Report On Embedded System
INSTITUTE OF ENGINEERING
Pulchowk, Lalipur
A
Lab Report
On
Embedded System
Lab1
MICROCONTROLLER 8051
1) Central Processor Unit (CPU): The CPU controls as well as monitors all the
operations being performed in the Microcontroller. The CPU reads program
written in ROM memory and executes them and do the expected task of that
application.
SIMULATION SOFTWARE
A. Keil Vision
It is an embedded development tool. It is used for programming in both assembly
and c programming. It is also used for generating the hex file required for burning
in the hardware implementation or hardware simulation.
END
Problem 9:
Assembly Code:- C Code:-
ORG 00h #include<regx51.h>
MOV 55H,#25H unsigned int nums[10] _at_ 0x55;
MOV 56H,#3DH void delay(int i){
MOV 57H,#0F7H unsigned int j,k;
MOV 58H,#13H for(j=0; j<i; j++)
MOV 59H,#0C9H for(k=0; k<1200; k++);
MOV 5AH,#4EH }
MOV 5BH,#62H void main(void){
MOV 5CH,#77H int i,j,seq[10],num1,num2,count,count2=0;
MOV 5DH,#0B8H nums[0]=0x25;
MOV 5EH,#0EBH nums[1]=0x3D;
MOV R0,#55H nums[2]=0xF7;
MOV R1,#60H nums[3]=0x13;
MOV R3,#00H nums[4]=0xC9;
CONT: MOV R2,#07H nums[5]=0x4E;
MOV A,@R0 nums[6]=0x62;
GO: MOV B,A nums[7]=0x77;
ANL A,#03H nums[8]=0xB8;
CJNE A,#03H,NXT nums[9]=0xEB;
MOV A,@R0 for(i=0; i<10; i++){
MOV @R1,A num1=nums[i];
INC R1 count=0;
INC R3 for(j=0; j<8; j++){
JMP AGN num2 = num1 & 0x03;
NXT: MOV A,B if(num2==0x03){
RR A count=1;
DJNZ R2,GO break;
AGN: INC R0 }
CJNE R0,#60H,CONT num1 = num1 >> 1;
MOV 70H,R3 }
PRINT: MOV R0,#60H if(count==1){
PRINT1: MOV R3,70H seq[count2]=nums[i];
MOV P0,@R0 count2++;
ACALL DELAY }
INC R0 }
DJNZ R3,PRINT1 while(1){
SJMP PRINT for(i=0; i<count2; i++){
DELAY: MOV R6,#25 P0=seq[i];
HERE1: MOV R4,#255 delay(250);
HERE2: MOV R5,#255 }
HERE3: DJNZ R5,HERE3 }
DJNZ R4,HERE2 }
DJNZ R6,HERE1
RET
END
Outputs:
1.
897F9AH + 34BC48H = BE3B2EH
2.
Output: 6BH, B6H
3.
[19H] = DDH and [1AH] = 22H
4.
R4 = Quotient = 09H ; R5 = Remainder = 0DH
5.
Largest Number = FAH ; Smallest Number = A8H
6.
Ascending
6.
Descending
7.
Prime Numbers: 2,3,5,7,11,13,17,19,23
8.
78H(120)
9.
Ans: 3DH, F7H, 13H, C9H, 4EH, 62H, 77H, B8H, EBH
Discussion:
Assignment – 1:
In this assignment, we carried out addition of two three-bytes numbers 897F9AH
and 34BC48H and saved the result in internal RAM starting at 40H. When two
numbers are added, the carry cannot be greater than 1 so if there was carry, it would
have been stored in location 43H. Then the result was displayed continuously on the
LEDs of the development board starting from the LSB with proper delay between
each byte. Port 0 of the microcontroller was used to interface with the LEDs. When
port 0 is used for interfacing purpose, we need to used pull-up resistor before getting
output at the LEDs since all the other ports have internal pull ups but not port 0.
Assignment – 2:
Although we have SWAP A instruction set for swapping the nibbles within the
accumulator, we used rotate right instruction to swap the nibbles of the accumulator
content. The original number contained in the accumulator is 6BH which was
displayed in the LEDs, then the nibbles were swapped and displayed in the LEDs.
Assignment – 3:
Though we have MUL AB instruction set to multiply two one-byte numbers stored
in accumulator A and register B, we used looping and successive addition
mechanism to perform multiplication operation. The multiplicand FFH was stored
in the RAM location 22H and multiplier DEH was stored in 15H. Then the result
was stored in the RAM location 19H (low byte) and 1AH (high byte). The multiplier
was used as counter and successive addition of multiplicand was carried out until
the multiplier is reduced to zero. Finally, the result i.e. high byte and low byte were
displayed continuously on the LEDs of the development board one by one with an
appropriate delay between them.
Assignment – 4:
We have DIV AB instruction set to carry out division of two one-byte numbers
provided that B doesn’t contain 0. However, we are using looping and successive
subtraction mechanism to perform the division operation. The dividend AFH was
stored in the memory location 3EH and the divisor was 12H. Then the quotient and
remainder were stored in the register R4 and R5 respectively. The divisor was
subtracted from the dividend if dividend didn’t come out to be negative. Finally, the
quotient and remainder were displayed continuously on the LEDs of the
development board one by one with an appropriate delay between them.
Assignment – 5:
Out of ten hexadecimal numbers stored in the internal RAM starting from memory
location 50H, we have to determine the largest and the smallest number. For this
purpose, at first, we considered the first number as the smallest number and the
largest. Then it was compared with every other numbers and replaced the number in
case the other number came out to be smaller than the smallest number assumed.
Assignment – 6:
For Ascending Order sorting we implemented Bubble sort and for descending order
we implemented Selection sort algorithm.
Assignment -7:
The numbers from 00H to 20H were stored in the internal RAM starting from
memory location 40H and we are to implement a subroutine such as to extract only
the prime numbers and display them continuously in the development board one by
one with appropriate delay between them. 0 and 1 are neither prime nor composite,
hence these were not displayed.
Assignment – 8:
To find the factorial of the number stored in register R3 where value in R3 could be
any number in the range from 00H to 05H only. We implemented a subroutine to
calculate factorial of the number in which we stored the value of the number stored
in R3 in R2 and decremented it in each iteration to multiply them continuously until
the number was reduced to 0. If the number is equal to 0 on comparison directly 1 is
assigned. Then another subroutine was defined to convert the factorial of the number
so obtained in hexadecimal format to decimal format. Hence, the so obtained
factorial of the number in both hexadecimal and decimal format were displayed
continuously on the LEDs of the development board one by one with an appropriate
delay between them.
Assignment -9:
Ten hexadecimal numbers are stored in the RAM and the subroutine is created that
searches the number having binary sequence (11)2. Those numbers are continuously
displayed in the LEDS.
Conclusion:
In this lab we learnt about the 8051 microcontroller. We gained knowledge about
different instructions and how to use them to make the microcontroller do a
particular task. After doing this lab we were able to write programs in assembly
language and C language for 8051 microcontrollers that can perform operation such
as data manipulation, branching and looping and subroutine calls. We used Proteus
for the simulation of circuit design.