Microcontroller Lab Manual
Microcontroller Lab Manual
Staff in Charge
Dr. Shankariah
Prof. Renuka B S
LAB EXPERIMENTS:
MICROCONTROLLER LAB
Set of experiments
SET I
1. Write an 8051 assembly level program to add 10 bytes of data.
2. Write an 8051 assembly level program to transfer 10 bytes of data from external RAM location starting with
2000h to internal RAM starting from 30h.
3. Write an 8051 assembly level program to transfer 10 bytes of data from location starting at 30h to location 35h.
4. Write an 8051 assembly level program to transfer 10 bytes of data from location starting at 35h to location 30h.
5. Write an 8051 assembly level program to exchange 10 bytes of data from location starting at 30h with data
from location starting from 1000h.
6. Write an 8051 assembly level program to transfer 10 bytes of data starting from location 8000h to location
9000h within the external memory.
SET II
1. Write an 8051 assembly level program to add ‘N’ bytes of data taking into account the possible carry output.
2. Write an 8051 assembly level program to add ‘N’ bytes of BCD numbers taking into account the possible carry
output.
3. Write an 8051 assembly level program to find the average of ‘N’ bytes of data.
4. Write an 8051 assembly level program to subtract two BCD numbers.
5. Write an 8051 assembly level program to add two multi-byte numbers.
SET III
1. Write an 8051 assembly level program to count the number of even numbers and number of odd numbers in
an array of ‘N’ bytes of data.
2. Write an 8051 assembly level program to count the number of +ve numbers and number of -ve numbers in an
array of ‘N’ bytes of data.
3. Check whether the given byte of data is present in an array of ‘N’ bytes of data. If present send 00 in Port 0 else
send FF in Port 0.
4. Read the data from Port 1. If P1.1 is at logic 0, find the largest number in an array of ‘N’ bytes of data and store
in location 40h. If P1.0 is at logic 1, find the smallest number in the array and store in the location 40h.
SET IV
1. Write an 8051 assembly level program to arrange an array of ‘N’ bytes of data in ascending order.
2. Write an 8051 assembly level program to arrange an array of ‘N’ bytes of data in descending order.
3. Write an 8051 assembly level program to find whether the given number is prime or not. If prime send FF to
Port 0 else send 00 to Port 0.
4. Write an 8051 assembly level program to find the factorial of a given number (using recursive procedure).
5. Write an 8051 assembly level program for BCD up counter. Show each count in Port 0 with appropriate delay.
6. Write an 8051 assembly level program for BCD down counter. Show each count in Port 0 with appropriate
delay.
SET V
1. Write an 8051 assembly level program to check whether the given byte of data is palindrome. If ‘yes’ send 00
to Port 0 else send FF to Port 0.
2. Write an 8051 assembly level program to check whether the lower nibble is greater than higher nibble of A. If
‘yes’ send 00 to Port 0 else send FF to Port 0.
3. Write an 8051 assembly level program to convert 2 digit BCD to ASCII numbers and store them in location
30h(LSB) and 31h(MSB).
4. Write an 8051 assembly level program to find the square of a number using look up table technique.
5. Write an 8051 assembly level program to find the square root of a number.
SET VI
1. Write an 8051 assembly level program to find LCM and HCF of two numbers.
2. Write an 8051 assembly level program to check whether the given number is 2 out of 5 code. If ‘yes’ send 00 to
Port 0 else send FF to Port 0.
3. Write an 8051 assembly level program to generate Fibonacci series.
SET VII
1. Write an 8051 assembly level program to generate square wave on P1.5 with 50% duty cycle. Program timers in
mode 0, mode1 and mode2 to generate the delay.
2. Write an 8051 assembly level program to generate square wave with ON period of 20ms and OFF period of
40ms. Use timers in mode 0, mode 1 and mode 2 to generate the delay.
3. Repeat the problems with interrupt for timers.
4. Repeat the above problems by writing programs in embedded C.
SET VIII
1. A switch is connected to P2.5. write an 8051 assembly level program to read the status of switch and if switch is
closed send serially ‘HELLO’, else send ‘WELCOME’ at baud rate 9600.
2. Write an 8051 assembly level program to transfer a message SJCE serially by programming serial
communication in interrupt mode with baud rate 9600.
3. Repeat the problem 1 & 2 using embedded C program.
SET IX
1. Interface 4 digit multiplexed 7 segments LED and writes a program to display the message SJCE.
2. Interface 4x4 hex keyboards and write a program to read the key closure and display hex code for key pressed
on 7 segment display.
SET X
1. Interface LCD module and write program to display a message.
2. Interface ADC a write a program to sample the signal and convert it into digital
3. Interface DAC and write program to generate various waveforms.
SET 1 PROGRAMS
Before Execution:
After Execution:
2 Write an 8051 assembly level program to transfer 10 bytes of
data from external RAM location starting with 2000h to internal
RAM starting from 30h
Before Execution:
After Execution:
3.Write an 8051 assembly level program to transfer 10 bytes of
data from location starting at 30h to location 35h.
Before Execution :
After Execution:
4.Write an 8051 assembly level program to transfer 10 bytes of
data from location starting at 35h to location 30h.
Before Execution:
After execution:
3. Writean 8051 assembly level program to exchange 10 bytes of
data from location starting at 30h with data from location starting
from 1000h.
Before Execution
1000h:0BH,17H,2DH,41,4AH,53,52H,0FH,1CH,0AH
30H: 01H,02H,3H,4H,5H,6H,7H,8H,9H,0AH
After Execution:
30H: 0BH, 17H, 2DH, 41, 4AH, 53, 52H, 0FH, 1CH, 0AH
1000H:01H,02H,3H,4H,5H,6H,7H,8H,9H,0AH
4. Write an 8051 assembly level program to transfer 10 bytes of data
starting from location 8000h to location 9000h within the external
memory.
Before Execution:
After Execution:
SET 2 PROGRAMS
Before Execution:
After Execution:
2. Write an alp to add N bytes of BCD numbers talking into
account the possible carry output.
Before Execution:
After Execution:
3. Write an alp to find the average of N bytes of data.
Before Execution:
After Execution
4. Write an alp to subtract two BCD numbers.
Before Execution:
After Execution:
5. Write an alp to add 2 multibyte numbers. Numbers starts from
location with address 30h and 40h. Store the results starting
from location 30h.
Before Execution:
After Execution:
SET 3 PROGRAMS
Before execution
After Execution
2.Write an 8051 assembly level program to count the number of +ve
numbers and number of –ve numbers in an array of ‘N’ bytes of data.
Before execution:
After execution
3. Check whether the given byte of data is present in an array of ‘N’ bytes of data. If
present send 00 in Port 0 else send FF in Port 0
Before execution:
After Execution:
4.Read the data from Port1. IfP1.1 is at logic0, find the largest
number in an array of ‘N’ bytes of data and store in location 40h.
If P1.0 is at logic1, find the smallest number in the array and store
in the location 40h
Before execution:
After execution:
SET 4 PROGRAMS
Before Execution:
After Execution:
2. Write an 8051 assembly level program to arrange an array of ‘N’ bytes of
data in descending order.
Before Execution:
After Execution:
3. Write an 8051 assembly level program to find whether the given number
is prime or not. If prime send FF to Port 0 else send 00 to Port 0.
After Execution:
4. Write an 8051 assembly level program to find the factorial of a given
number (using recursive procedure).
After Execution:
5. Write an 8051 assembly level program for BCD up counter. Show each
count in Port 0 with appropriate delay.
After Execution:
6. Write an 8051 assembly level program for BCD down counter. Show
each count in Port 0 with appropriate delay.
After Execution:
SET 5 PROGRAMS
Before execution
After execution
3. Write an 8051 assembly level program to convert 2 digit BCD to ASCII
numbers and store them in location 30h(LSB) and 31h(MSB)
Before execution
After execution
4. Write an 8051 assembly level program to find the square of a number
using look up table technique
Before execution
After execution
4.Write an 8051 assembly level program to find the square root of a
number
Before execution
After execution
SET 6 PROGRAMS
After Execution:
2.Write a assembly level program to find the Fibonacci series.
Before Execution:
After Execution:
3. Write an assembly level program to find LCM and HCF of 2 numbers.
Before Execution:
After Execution:
SET 7 PROGRAMS
1. WAP to generate a square wave on P1.5 with 50% Duty
Cycle. Program timers in mode0, mode1 and mode2 to generate
delay.
Mode 0
After execution
Mode 1
After execution
Mode 2
After execution
2. WAP to generate a rectangular wave with T(on)=20ms and
T(off)=40ms. Use Timer0 in mode0, mode1 and mode2 to
generate delay.
Mode 0
After Execution:
Mode 1
After execution
Mode 2
1. Repeat above problems to generate square wave with
interrupts for timers
Mode 0
After execution
Mode 1
After execution
Mode 2
After execution
Question Number - 1
Interface a Multichannel ADC to 8051 and develop a program to read
the analog data, Convert into digital value and display the digitized
value on port 0 connected to leds
Circuit Diagram :
Program
Result :
LCD routine:
/* LCD related functions. */
#include "at89c51ed2.h"
#include <intrins.h> //For _nop_();
temp1 = 0x01;
lcd_comm ();
delay(500);
}
wr_cn ();
delay (60);
}
delay(60);
}
P2 = temp1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
for(i=0;i<count;i++);
}
/*
void lcd_data_cmnd(char cmnd, char l_data)
{
char check;
check =cmnd;
var = l_data;
delay(60);
}
KEYBOARD INTERFACE:
/*
#include "at89c51xd2.h"
void scan(void);
void get_key(void);
void display(void);
void delay_ms(int i);
void uart_init(void);
while(1)
{
get_key();
display();
P3 = 0xFF;
}
} //end of main()
if(flag == 0xff)
break;
} // end of while
}
} // end of get_key();
void scan(void) // will return the scan code for the key pressed
{ // Both row lines and column lines are connected to
unsigned char t; //Port 0 only.Columns are connected to P0.0-P0.3
temp4 = P0; // P0.4-P0.7 are connected to rows
temp4 = temp4 & 0xF0; //read port0 ,mask with 0xF0h
}
}
// end of scan()
void display(void)
{
P1 = result;
}
void delay_ms(int i)
{
int j;
for(j=0;j<i;j++);
}
DAC INTERFACE:
1. Interfacing DAC with 8051 and developing an algorithm to generate the following
outputs
I) Square wave with 50% duty cycle
II) Square wave with 75% duty cycle
III) Triangle wave.
IV) Ramp(+ve &-ve)
V) Sine wave
VI) Staircase
VII) Staircase triangle
Solution:
Interfacing Circuit:
I) Generation of square wave with 50%duty cycle.
➢ Solution:
RESULT:
2.Generation of square wave with 75%duty cycle.
➢ Solution:
RESULT:
Generation of Triangular wave.
➢ ALGORITHM
RESULT:
II) A. Generation of positive Ramp with signal.
➢ ALGORITHM
RESULT:
B. Generation of negative Ramp with signal.
➢ ALGORITHM
RESULT:
➢ GENERATION OF SINE WAVE
➢ ALGORITHM
RESULT
III) Generation of the following waveform.
➢ ALGORITHM
RESULT
Assignment question:
1. Write an 8051 ALP to send message HELLO serially once in every 2 sec.
Program timer and serial communication in interrupt mode
RESULT:
END