Microcontrollermanual 2024
Microcontrollermanual 2024
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
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
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
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
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.
Staff Sign
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
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.
FFxFF= 01FEH
Staff Sign
PROGRAM-8:
Write an ALP to perform Division operation on 8 bit number by 8 bit number.
Result:
Observe the Results in Reg A and Reg B also in memory location 30H and 31H
Staff Sign
PROGRAM-9:
Write an ALP to separate positive and negative in a given array.
Staff Sign
PROGRAM-10:
Write an ALP to separate Even and Odd in a given array.
Staff Sign
PROGRAM-11:
Write an ALP to arrange the numbers in Ascending & Descending order.
RESULTS:
Before Execution:
After Execution:
Descending order:
RESULTS:
Before Execution:
After Execution:
Staff Sign
PROGRAM-12:
Write an ALP to find Largest & Smallest number from a given array.
Before Execution:
After Execution:
Staff Sign
Smallest number
// Change JC to JNC
Before Execution:
After Execution:
Staff Sign
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.
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.
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.
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
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
Program-2:
Write an 8051 C program to find factorial of a given number.
#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
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:
Staff Sign
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
#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);
}
}
}
}
Staff Sign
2. Write an 8051 C program to Generate Sine & Square waveforms using DAC interface.
0 0 5 128
90 1 10 255
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
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.
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?