0% found this document useful (0 votes)
120 views

Microcontrollermanual 2024

Uploaded by

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

Microcontrollermanual 2024

Uploaded by

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

DEPARTMENT

OF
ELECTRONICS AND COMMUNICATION ENGINEERING

MICROCONTROLLERS
[BECL456A]
LAB MANUAL

Semester: 4
Academic Year: 2023-24

Name:

USN

Department:
INDEX SHEET
Sl No. Program Pg N0.
I. Assembly Language Programming
Data Transfer Programs:
1 Write an ALP to move a block of n bytes of data from source (20h) to 1
destination (40h) using Internal-RAM.
2 Write an ALP to move a block of n bytes of data from source (2000h) 2
to destination (2050h) using External RAM.
3 Write an ALP To exchange the source block starting with address 20h, 3
(Internal RAM) containing N (05) bytes of data with destination block
starting with address 40h (Internal RAM).
4 Write an ALP to exchange the source block starting with address 10h 4
(Internal memory), containing n (06) bytes of data with destination
block starting at location 00h (External memory).
Arithmetic & Logical Operation Programs:
5 Write an ALP to add the byte in the RAM at 34h and 35h, store the 5
result in the register R5 (LSB) and R6 (MSB), using Indirect
Addressing Mode
6 Write an ALP to subtract the bytes in Internal RAM 34h &35h store 6
the result in register R5 (LSB) & R6 (MSB).
7 Write an ALP to multiply two 8-bit numbers stored at 30h and 31h and 7
store16- bit result in 32h and 33h of Internal RAM.
8 Write an ALP to perform division operation on 8-bit number by 8-bit 8
number.
9 Write an ALP to separate positive and negative in a given array. 9
10 Write an ALP to separate even or odd elements in a given array. 10
11 Write an ALP to arrange the numbers in Ascending & Descending 11
order.
12 Write an ALP to find Largest & Smallest number from a given array 13
starting from 20h & store it in Internal Memory location 40h.
Counter Operation Programs:
13 Write an ALP for Decimal UP-Counter 15
14 Write an ALP for Decimal DOWN-Counter. 16
15 Write an ALP for Hexadecimal UP-Counter. 16
16 Write an ALP for Hexadecimal DOWN-Counter. 17
II. C Programming
1 Write an 8051 C program to find the sum of first 10 Integer Numbers. 18
2 Write an 8051 C program to find Factorial of a given number 19
3 Write an 8051 C program to find the Square of a number (1 to 10) 20
using Look-Up Table
4 Write an 8051 C program to count the number of Ones and Zeros in 21
two consecutive memory locations.
III. Hardware Interfacing Programs
1 Write an 8051 C Program to rotate stepper motor in Clock & Anti- 22
Clockwise direction.
2 Write an 8051 C program to Generate Sine & Square waveforms using 24
DAC interface.
Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-1:

Write an ALP to move a block of N bytes of data from source (20H) to destination (40H) using
Internal RAM.

Before Execution:

After Execution:

Staff sign

Dept., of ECE, AIEMS 1|Page


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-2:

Write an ALP to move a block of N bytes of data from source (2000H) to destination (2050H) using
External RAM.

ORG 00H
SJMP 30H
ORG 30H
MOV DPH, #20H
MOV R0, 00H
MOV R1, #50H
MOV R5, #05H
L2: MOV DPL, R0
MOVX A,@DPTR
MOV DPL, R1
MOVX @DPTR,A
INC R0
INC R1
DEC R5
JNZ L2
L1: SJMP L1
END

Before Execution:

After Execution

Staff sign

Dept., of ECE, AIEMS 2|Page


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-3:

Write an ALP to exchange the source block starting with address 20H (Internal RAM) containing N
(05) bytes of data with destination block starting at location 40H (Internal RAM).

Before Execution:

After Execution

Staff Sign

Dept., of ECE, AIEMS 3|Page


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-4:
Write an ALP to exchange the source block starting with address 10H (Internal RAM) containing N
(06) bytes of data with destination block starting at location 00H (External RAM).

Before Execution:

After Execution

Staff Sign

Dept., of ECE, AIEMS 4|Page


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-5:
Write an ALP to add the byte in the RAM 34H and 35H, store the result in the register R5 (LSB) and
R6 (MSB), using indirect addressing mode.

NOTE: Observe results in R5 and R6

Staff Sign

Dept., of ECE, AIEMS 5|Page


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-6:
Write an ALP to subtract the bytes in the internal RAM 34H and 35H, store the result in the register
R5 (LSB) and R6 (MSB).

Staff Sign

Dept., of ECE, AIEMS 6|Page


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-7:
Write an ALP to multiply two 8 bit numbers stored at 30H and 31H and store 16 bit result in 32H
and 33H of Internal RAM.

Before Execution: Enter the Numbers in location 30H & 31H

After Execution, check Results in 32H & 33H

FFxFF= 01FEH

Staff Sign

Dept., of ECE, AIEMS 7|Page


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-8:
Write an ALP to perform Division operation on 8 bit number by 8 bit number.

Result:

DIV AB ; A / B, Quotient stored in Reg A, Remainder in Reg B

Ex; 56H / 31H

Q= 01H & R =25H

Observe the Results in Reg A and Reg B also in memory location 30H and 31H

Staff Sign

Dept., of ECE, AIEMS 8|Page


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-9:
Write an ALP to separate positive and negative in a given array.

NOTE: - Observe results in Reg R1 and R2.

Staff Sign

Dept., of ECE, AIEMS 9|Page


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-10:
Write an ALP to separate Even and Odd in a given array.

NOTE:- Observe results in Reg R1 and R2.

Staff Sign

Dept., of ECE, AIEMS 10 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-11:
Write an ALP to arrange the numbers in Ascending & Descending order.

RESULTS:

Before Execution:

After Execution:

Dept., of ECE, AIEMS 11 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

Descending order:

RESULTS:
Before Execution:

After Execution:

Staff Sign

Dept., of ECE, AIEMS 12 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-12:
Write an ALP to find Largest & Smallest number from a given array.

Before Execution:

After Execution:

See the largest number in the location in 9007H.

Staff Sign

Dept., of ECE, AIEMS 13 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

Smallest number
// Change JC to JNC

Before Execution:

After Execution:

Observe the smallest number in the location 9007h.

Staff Sign

Dept., of ECE, AIEMS 14 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-13: Write an ALP for Decimal UP counter


ORG 00H
SJMP 30H
ORG 30H
MOV A, #00H
BACK: ACALL DELAY
ADD A, #01H
DA A
JNZ BACK
HERE: SJMP HERE

DELAY: MOV r1, #0FFH


DECR1: MOV r2,#0FFH
DECR: MOV r3, #0FFH
DJNZ r3, $
DJNZ r2, DECR
DJNZ r1, DECR1
RET
END

OBSERVATION & RESULT: check the result in watch and call stack window. The count is
incremented by 1. Count is displayed from 00 t0 99 on watch#1 window.

Dept., of ECE, AIEMS 15 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-14: Write an ALP for Decimal Down counter


ORG 00H
SJMP 30H
ORG 30H
MOV A, #00H
BACK: ACALL DELAY
ADD A, #99H
DA A
JNZ BACK
HERE: SJMP HERE

DELAY: MOV r1, #0FFH


DECR1: MOV r2,#0FFH
DECR: MOV r3, #0FFH
DJNZ r3, $
DJNZ r2, DECR
DJNZ r1, DECR1
RET
END

OBSERVATION & RESULT: check the result in watch and call stack window.
The count is decremented by 1. Count is displayed from 99 to 00 on watch#1 window.

PROGRAM-15: Write an ALP for Hexadecimal UP counter


ORG 0000H
LJMP 8000H
ORG 8000H
MOV A, #00H
BACK: ACALL DELAY
INC A
JNZ BACK
HERE: SJMP HERE

DELAY: MOV r1, #0FFH


DECR1: MOV r2, #0FFH
DECR: MOV r3, #OFFH
DJNZ r3, $
DJNZ r2, DECR
DJNZ r1, DECR1
RET
END

OBSERVATION & RESULT: check the result in watch and call stack window. The count is
incremented by 1. Count is displayed from 00 to FF on watch#1 window.

Dept., of ECE, AIEMS 16 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

PROGRAM-16: Write an ALP for Hexadecimal Down counter


ORG 0000H
LJMP 8000H
ORG 8000H
MOV A, #00H
BACK: ACALL DELAY
DEC A
JNZ BACK
HERE: SJMP HERE

DELAY: MOV r1, #0FFH


DECR1: MOV r2, #0FFH
DECR: MOV r3, #OFFH
DJNZ r3, $
DJNZ r2, DECR
DJNZ r1, DECR1
RET
END

OBSERVATION & RESULT: check the result in watch and call stack window.
The count is decremented by 1. Count is displayed from FF to 00 on watch#1 window.

Staff Sign

Dept., of ECE, AIEMS 17 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

PART-II: C Programming
Program-1:
Write an 8051 C program to find the sum of first 10 integer numbers.

#include <reg51.h>
void main ()
{
unsigned int i, sum, a[10]={0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0x10};
for (i=0;i<10;i++)
{
sum=sum + a[i];
}
P1=sum;
P2=sum>>8;
}

RESULTS: Observe the Results on Port1 (lower byte) and Port2 (upper byte)

Staff Sign

Dept., of ECE, AIEMS 18 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

Program-2:
Write an 8051 C program to find factorial of a given number.

// Enter numbers of range 01H-0CH

#include <reg51.h>
void main ()
{
unsigned long int fact =1, m;
unsigned int i, num;
num=0x0c;
for (i=1;i<=num; i++)
{
fact= fact*i;
}
}
RESULT: Check the Results in D: 04H
Example-1: 5! =78H
Example-2: 0xC! =1C8CFC00H

Staff Sign

Dept., of ECE, AIEMS 19 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

Program-3:
Write an 8051 C program to find the square of a number (1 to 10) using look-up
table.

#include <regx51.h>
unsigned int lookup_table[] = {1, 4, 9, 16, 25, 36, 49, 64, 81, 100};
void main() {
unsigned int number,i,j;
unsigned int square;
for (number = 1; number <= 10; number++)
{
square = lookup_table[number - 1];
P0 = number;
P1 = square;
for( i = 0; i < 50000; i++)
{
for ( j = 0; j < 100; j++)
{
}
}
}

RESULT:

Observe the results in Port 0 and Port1

Staff Sign

Dept., of ECE, AIEMS 20 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

Program-4:
Write an 8051 C program to count number of ones and zeros in two consecutive
memory locations.

Result:
3C= 0011 1100 and F5=1111 0101
Total Number of ones=0A and zeros= 06
Observe Results on Port0 and Port1

Staff Sign

Dept., of ECE, AIEMS 21 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

III. Hardware Interfacing Programs


1. Write an 8051 C Program to rotate stepper motor in Clock & Anti-Clockwise direction.

#include <REG51xD2.H>
#include "lcd.h"
static bit Dir=0;
void delay(unsigned int x) /* Delay Routine */
{
for(;x>0;x--);
}
void ChangeDir(void) interrupt 0 /* Int Vector at 000BH, Reg Bank 1 */
{
Dir = ~Dir; /* Complement the Direction flag */
ClrLcd();
if(Dir)
{ WriteString("Clockwise");
delay(32000);
}
else
{WriteString("Anti Clockwise");
delay(32000);
}
}
main()
{
unsigned char Val,i;
EA=0x1; /* Enable Interrupt flag and Interrupt 0 & Serial Interrupt */
EX0=0x1;
ES=0x1;
P0=0x00; /*since the monitor is using the serial interrupt it has to be enabled*/
InitLcd(); /* Initialise LCD */
WriteString("Anti Clockwise"); /* Write to LCD */
Dept., of ECE, AIEMS 22 | P a g e
Microcontrollers Lab [BECL456A] 2023-24

while(1)
{
if(Dir) /* If Dir Clockwise */
{
Val = 0x88;
for(i=0;i<4;i++)
{
P0 = Val; /* Write data for clock wise direction*/
Val = Val>>1;
delay(575);
}
}
else /* AntiClockwise Direction */
{
Val = 0x11;
for(i=0;i<4;i++)
{
P0 = Val; /* Write data for anticlock wise direction*/
Val = Val<<1;
delay(575);
}
}
}
}

Result: Observe the waveforms on the CRO.

Staff Sign

Dept., of ECE, AIEMS 23 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

2. Write an 8051 C program to Generate Sine & Square waveforms using DAC interface.

Program for triangular wave:


#include <REG51xD2.H>
main()
{
unsigned char i=0;
P0 = 0x00; /* P0 as Output port */
while(1)
{
for(i=0;i<0xff;i++)
{ /* Generate ON pulse */
P1 = i;
P0 = i;
}
for(i=0xfe;i>0x00;i--) /* Generate OFF pulse */
{
P0 = i;
P1 = i;
}
}

Result: Observe the waveforms on the CRO.

Dept., of ECE, AIEMS 24 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

Program for Ramp waveform


#include <REG51xD2.H>
main ()
{ Unsigned char i=0;
P0 = 0x00; /* P0 as Output port */
while (1)
{
for (i=0;i<0xff;i++) /* Generate ON pulse */
{
P1 = i;
P0 = i;
}
}
}
Result: Observe the waveforms on the CRO.
Program for sine wave
➢ Compute different step values (θ = 0o,30o…) of sine using the equation
V= 2.5V +2.5Vsinθ. . Output the values thro P0.
➢ More the steps, smoother will be the sine wave.

Angle sinθ V= 2.5V +2.5Vsinθ. value sent to


(θ) DAC(V*25.6)

0 0 5 128

30 0.5 7.5 192

60 0.866 4033 238

90 1 10 255

120 0866 9033 238

. . . .
. . . .
. . . .
. . . .

Dept., of ECE, AIEMS 25 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

. . . .
. . . .

330 -0.5 2.5 64

360 0 5 128

#include <REG51xD2.H>
main()
{
static int a[13]={128,192,238,255,238,192,128,64,17,0,17,64,128};
unsigned char i=0;
P0 = 0x00; /* P0 as Output port */
while (1)
{
for(i=0;i<13;i++) /* Output different values */
{ P0 = a[i]; }
}
}
Result: Observe the waveforms on the CRO.

Dept., of ECE, AIEMS 26 | P a g e


Microcontrollers Lab [BECL456A] 2023-24

VIVA QUESTIONS
1. List few differences between a microcontroller and a microprocessor.
2. Why ROMless versions of microcontrollers exist.
3. Name the ways to speed up digital computers.
4. What is the size of internal RAM?
5. What is the size of internal ROM in 8031?
6. What is the Execution time of a single cycle instruction for a 6MHz crystal?
7. Name few registers that can do division.
8. Name the ports used for external memory access.
9. What is the address of the stack when 8051 is reset?
10. How many register banks are available in 8051?
11. How may I/O pin can be both input and output.
12. Which bits in which register must be set to give the serial data interrupt the highest priority?
13. Why a low address byte latch for external memory is needed.
14. What is the baud rate for the serial port in mode 0 for a 6MHz crystal?
15. Which bits in which register must be set to make INTO level generated interrupts.
16. Name the register containing GFO and GF1.
17. What is the address of PCON register?
18. What is the address of the interrupt program for the INTO level generated interrupt.
19. Which bits in which registers must be set to have timer 0 count input pulses on pin TO in
timer mode.
20. Name 2 conditions under which program opcodes are fetched from external rather than
internal memory.
21. Name the signal that reads external ROM
22. When used in multiprocessing which bit in which register is used by a transmitting 8051 to
signal receiving 8051s that an interrupt should be generated.
23. What is instruction syntax?
24. What is the significance of a testing program?
25. Why are high level languages machine independent.
26. What is software?
27. Why are high level languages machine independent.
28. Write an instruction sequence to rotate DPTR one place left.
29. What is the difference between signed and unsigned operations?
30. How do you perform signed subtraction
31. Why mode 0 not suitable for 8051 communications.
32. How is memory organized in 8051?
33. Write the interrupt priority sequence.
34. What are the flags stored in PSW.
35. Which register holds the serial data interrupt bits T1 and R1.
36. What are the bits that determine timer modes and the register that holds these bits?
37. What are the different ports of 8051?
38. What is the advantage in connecting external memory to 8051?
39. What is TCON register
40. What is SCON register?
41. What is PCON register?
42. Name the different Time modes of operation
43. What is SCON register?
44. How is Transmission and reception of data done in 8051
45. When is it required use the control signals WR and RD?
46. How do you compare the flash PROM, EPROM & ROM versions of 8051 microcontrollers
why selecting device for product device?
47. What are the constraints on frequency counting, pulse width measurements using 89C2051?
Dept., of ECE, AIEMS 27 | P a g e
Microcontrollers Lab [BECL456A] 2023-24

48. What is power-up of reset and what is watch dog timer reset?
49. Compare b/w LJMP, AJMP & SJMP?
50. Compare b/w LCALL, ACALL & SCALL?
51. Define addressing mode. List them?
52. How RETI & RET instruction differ.
53. Why is the coding done in assembly language of being written in the machine codes directly
by a programmer?
54. What are the different components in an instruction?
55. How do you compare program, routine and interrupt service routine?
56. What are the limitation in designing frequency counter using 89C51 as per as the operating
frequency concerned?
57. List the instructions of 8051 in which use of accumulator and not any register for the
accumulating the result must?

Dept., of ECE, AIEMS 28 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy