SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY
(AUTONOMOUS)
R. V. S NAGAR CHITTOOR-517 127
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
IV YEAR I SEMESTER B. TECH
INFORMATION TECHNOLOGY
14AEC45 EMBEDDED SYSTEMS LABORATORY MANUAL NOTE BOOK
NAME : __________________________
ROLL NO. : __________________________
LAB : __________________________
BRANCH : __________________________
LIST OF EXPERIMENT
1. AN 8051 ALP TO CLEAR A REGISTER AND ADD 3 TO IT TEN TIMES AND STORE
THE RESULT IN MEMORY.
2. DOOR SENSOR MONITORING
3. TOOGLE SWITCH
4. BLINKING LED’S
5. DANCING LED’S
6. LCD INTERFACING
7. SERIAL TRANSMISSION
8. SERIAL RECEPTION
9. TIMER 0 AS A COUNTER
10. TO TRANSFER THE DATA SERIALLY BETWEEN TWO MICROCONTROLLER KIT
USING RS232C
INDEX
Exp. No Date Name of the Experiment Signature
AN 8051 ALP TO CLEAR A REGISTER AND
1 ADD 3 TO IT TEN TIMES AND STORE THE
RESULT IN MEMORY
2 DOOR SENSOR MONITORING
3 TOOGLE SWITCH
4 BLINKING LED’S
5 DANCING LED’S
6
LCD INTERFACING
7
SERIAL TRANSMISSION
8 SERIAL RECEPTION
9
TIMER 0 AS A COUNTER
TO TRANSFER THE DATA SERIALLY
10
BETWEEN TWO MICROCONTROLLER KIT
USING RS232C
SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY
(AUTONOMOUS)
DEPT. OF ECE
Experiment-1 DATE:
______________________________________________________________________________
An 8051 ALP to clear a register and ADD 3 to it TEN times and store the result in memory
Aim: Write an 8051 ALP to a register and Add 3 to iy 10-times, and store the result in memory.
Hardware Required: Personal Computer
Software Required: Keil compiler and Proload v5.4
Procedure:
1. Write the assembly language for this task in the keil complier
2. Complier it and build target as per the procedure given above
3. Start the debug session by selecting the option from debug menu.
4. By pressing f11 we can observe the step execution of each instruction
5. Observe the changes occur in registers after execution of each instruction by selecting the
resisters option in project works space.
6. We can see the contents of memory using memory window from view menu.
7. Verify the result by observing both registers and memory window.
Program:
ORG 00H
CLR A
MOV 20H, #10
MOV R0, #20H
AGAIN: ADD A, #03
DEC @R0
CJNE @R0, #00, AGAIN
MOV 30H, A
END
Output:
Result: The program for clearing a register and adding 3 to it 10 times is compiled and verified
successfully using keil compiler.
SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY
(AUTONOMOUS)
DEPT. OF ECE
Experiment-2 DATE:
______________________________________________________________________________
DOOR SENSOR MONITORING
Aim: To write a program to monitor door sensor and sound the buzzer when the signal is
detected from sensor
Hardware Required: Personal Computer
Software Required: Keil compiler and Flash magic
Procedure:
1. Write the assembly language for this task in the keil complier and save it with “.C”
extension.
2. Complier it and build target as per the procedure given above
3. Start the debug session by selecting the option from debug menu.
4. Use the flash magic software for program dumping process.
5. Connect the port p1. 1 to light sensor
6. Connect the port p1.7 to the buzzer
7. Seeing the output reset the set the port1.1 and see the output
Program:
#include<reg51.h>
sbit dsensor=P1^1;
sbit buzzer=P1^7;
void delay(unsigned int);
void main(void)
while(1)
if(dsensor==0)
buzzer=0;
delay(200);
else
buzzer=1;
delay(200);
void delay(unsigned int itime)
{
int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++)
Output:
Result:
The program to monitor door sensor was successfully performed using keil software.
SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY
(AUTONOMOUS)
DEPT. OF ECE
Experiment-3 DATE:
______________________________________________________________________________
TOOGLE SWITCH
Aim: To write a program in embedded to toggle all the bits of portB parts continuously with a
250ms delay.
Hardware Required: Personal Computer
Software Required: Keil compiler and Flash magic
Procedure:
1. Write the assembly language for this task in the keil complier and save it with “.C”
extension.
2. Complier it and build target as per the procedure given above
3. Start the debug session by selecting the option from debug menu.
4. Use the flash magic software for program dumping process.
5. Connect the port p1. 1 to light sensor
6. Connect the port p1.7 to the buzzer
7. Seeing the output reset the set the port1.1 and see the output
Program
#include<reg51.h>
void delay(void);
void main(void)
while(1)
P1=0x55;
delay();
P1=0xAA;
delay();
void delay(void)
int i,j;
for(i=0;i<10;i++)
for(j=0;j<1000;j++)
}
Output:
Result:
The program to toggle LED was successfully performed using keil software.
SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY
(AUTONOMOUS)
DEPT. OF ECE
Experiment-4 DATE:
______________________________________________________________________________
BLINKING LED’S
Aim: To write a program in embedded to perform blinking LED’S using keil software
Hardware Required: Personal Computer
Software Required: Keil compiler and Flash magic
Procedure:
1. Write the assembly language for this task in the keil complier and save it with “.C”
extension.
2. Complier it and build target as per the procedure given above
3. Start the debug session by selecting the option from debug menu.
4. Use the flash magic software for program dumping process.
5. Connect the port p1. 1 to LED input (CN4) using 8 pin connector
6. Connect the port p2.0 to switch of CN9 using flying leads.
7. Before seeing the output reset the device to communicate the peripherals
8. Connect p1. 0 to CN4
9. Reset the device to communicate with 8 pin connector to blink LED’s as per program.
10. Seeing the output reset the set the port1.1 and see the output
Program
#include<reg51.h>
sbit led=P1^0;
void delay(void);
void main(void)
while(1)
led=0;
delay();
led=1;
delay();
void delay(void)
int i,j;
for(i=0;i<10;i++)
for(j=0;j<1000;j++)
}
}
Output:
Result:
The blinking LED’s program was successfully performed using keil software.
SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY
(AUTONOMOUS)
DEPT. OF ECE
Experiment-5 DATE:
______________________________________________________________________________
Dancing LED’S
Aim: To write a program in embedded to perform Dancing LED’S using keil software
Hardware Required: Personal Computer
Software Required: Keil compiler and Flash magic
Procedure:
1. Write the assembly language for this task in the keil complier and save it with “.C”
extension.
2. Complier it and build target as per the procedure given above
3. Start the debug session by selecting the option from debug menu.
4. Use the flash magic software for program dumping process.
5. Connect the port p1. 1 to LED input (CN4) using 8 pin connector
6. Connect the port p2.0 to switch of CN9 using flying leads.
7. Before seeing the output reset the device to communicate the peripherals
8. Connect p1. 0 to CN4
9. Reset the device to communicate with 8 pin connector to blink LED’s as per program.
10. Seeing the output reset the set the port1.1 and see the output
Program
#include<stdio.h>
#include<reg51.h>
#include<math.h>
void main()
do
int i;
for(i=0;i<10000;i++)
P1=0x01;
for(i=0;i<10000;i++)
P1=0x02;
for(i=0;i<10000;i++)
P1=0x04;
for(i=0;i<10000;i++)
{
P1=0x08;
for(i=0;i<10000;i++)
P1=0x10;
for(i=0;i<10000;i++)
P1=0x20;
for(i=0;i<10000;i++)
P1=0x40;
for(i=0;i<10000;i++)
P1=0x80;
}
while(1);
Output:
Result:
The Dancing LED’S program was successfully performed using keil software.
SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY
(AUTONOMOUS)
DEPT. OF ECE
Experiment-6 DATE:
______________________________________________________________________________
LCD INTERFACING
Aim: To write a program in embedded to write in LCD IN 8051 development kit using keil
software
Hardware Required: Personal Computer
8051 development board
Software Required: Keil compiler and Flash magic
Procedure:
1. Write the assembly language for this task in the keil complier and save it with “.C”
extension.
2. Complier it and build target as per the procedure given above
3. Start the debug session by selecting the option from debug menu.
4. Use the flash magic software for program dumping process.
5. Connect the port p0 to data pin in LCD module
6. Connect the pin p2.0, p2.1, p2.2 to the enable read/write and reset respectively in the
LCD module.
7. Before seeing the output reset the device to communicate with other peripheral.
Program
#include <reg51.h>
#include <string.h>
sbit rs = P2^7; // declare P2.7 as rs pin
sbit en = P2^5; // declare p2.5 as enable pin
sbit rw = P2^6; // declare p2.6 as read/write pin
sbit b = P0^7; // busy flag
void writecmd(unsigned char a); // function to send command to LCD
void writedat(unsigned char b); // function to send data to LCD
void busy(); // function to check LCD is busy or not
void writestr(unsigned char *s); // function to write string on LCD
void writecmd(unsigned char a)
busy(); // check for LCD is busy or not
rs = 0; // clear rs pin for command
rw = 0; // clear rw pin to write
P0 = a; // send command character
en = 1; // strob LCD
en = 0;
void writedat(unsigned char b)
busy(); // check for LCD is busy or not
rs = 1; // set rs pin for data
rw = 0; // clear rw pin to write
P0 = b; // send data character
en = 1; // strob LCD
en = 0;
void busy()
en = 0; // disable display
P0 = 0xFF; // configur P0 as input
rs = 0; // clear rs pin for command
rw = 1; // set rw pin to read
while(b==1)
en=0; // strob LCD till P0.7 is 1
en=1;
en=0;
void writestr(unsigned char *s)
unsigned char l,i;
l = strlen(s); // get the length of string
for(i=1;i<l;i++)
writedat(*s); // write every char one by one
s++;
main()
P0=0x00; // P0 and P0 as output ports
P2=0x00;
writecmd(0x3C); // initialize LCD
writecmd(0x0E);
writecmd(0x01); // clear memory and home cursor
writestr("Wel-Come to LCD"); // write message in first line
writecmd(0xC4); // move cursor to second line 4th pos
writestr("Program");
while(1); // continuous loop
Output:
Result:
The message is displayed in the LCD was successfully performed using Keil µ vision and
implemented to 8051 development board.
SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY
(AUTONOMOUS)
DEPT. OF ECE
Experiment-7 DATE:
______________________________________________________________________________
SERIAL TRANSMISSION
Aim: To write a program for the 8051 to transfer the letter ‘A’ serially with a baud rate of 9600
continuously use 8 bit data and 1 step bit.
Hardware Required: Personal Computer
8051 development board
Software Required: Keil compiler
Procedure:
1. Write the assembly language for this task in the keil complier and save it with “.C”
extension.
2. Complier it and build target as per the procedure given above
3. Start the debug session by selecting the option from debug menu.
4. Use the flash magic software for program dumping process.
5. Set the device 89V51RD2 using COM1 port with baud rate of 9600.
6. Select erase all option to erase previous program
7. Browse the program hex file location and select the program to dump to µc.
8. If the option comes like “Reset the device into ISP mode” press the reset button in 8051
development board.
9. Then the program will be dumped into the µc.
10. Go to the hyper terminal, name the connection COM1 port with baud rate of 9600 with
default options and press OK.
11. Now press RESET on the device so as to communicate with PC.
12. After pressing RESET key the device receives the character to hyper terminal using serial
port RS232.
PROGRAM
#include<reg51.h>
void sertx(unsigned char);
void main(void)
TMOD=0x20; //use timer 1, 8-bit data
TH1=0xFD; //9600 baud rate
SCON=0x50;
TR1=1;
while(1)
sertx(‘Y’);
sertx(‘E’);
sertx(‘S’);
void sertx(unsigned char x)
{
SBUF=x;
while(TI==0);
TI=0;
Output:
Result: Therefore, Sending a character serially was successfully performed using Keil µvision
and implemented to 8051 development board.
SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY
(AUTONOMOUS)
DEPT. OF ECE
Experiment-8 DATE:
______________________________________________________________________________
SERIAL RECEPTION
Aim: To write a C language program to perform serial reception in development board using keil
µvision
Hardware Required: Personal Computer
8051 development board
Software Required: Keil compiler
Procedure:
1. Write the assembly language for this task in the keil complier and save it with “.C”
extension.
2. Complier it and build target as per the procedure given above
3. Start the debug session by selecting the option from debug menu.
4. Use the flash magic software for program dumping process.
5. Set the device 89V51RD2 using COM1 port with baud rate of 9600.
6. Select erase all option to erase previous program
7. Browse the program hex file location and select the program to dump to µc.
8. If the option comes like “Reset the device into ISP mode” press the reset button in 8051
development board.
9. Then the program will be dumped into the µc.
10. Go to the hyper terminal, name the connection COM1 port with baud rate of 9600 with
default options and press OK.
11. Now press RESET on the device so as to communicate with PC.
12. After pressing RESET key the device receives the character to hyper terminal using serial
port RS232.
SERIAL RECEPTION
PROGRAM
#include<reg51.h>
unsigned char a,f=0;
sfr lcddata=0x90;
sbit rs=P3^4;
sbit rw=P3^3;
sbit en=P3^2;
sbit s=P2^1;
unsigned int cnt=-1,cnt1=0;
void delay(unsigned char a)
unsigned char i,j;
for(i=0;i<=a;i++)
for(j=0;j<=125;j++)
{}
}
void command(unsigned char dost)
lcddata=dost;
rs=0;
rw=0;
en=1;
delay(5);
en=0;
void lcddisplay(unsigned char word)
lcddata=word;
rs=1;
rw=0;
en=1;
delay(5);
en=0;
void delete1()
command(0xc0+cnt1);
command(0x10);
lcddisplay(0x20);
cnt1--;
command(0x10);
void delete()
command(0x80+cnt);
command(0x10);
lcddisplay (0x20);
cnt--;
command(0x10);
void main()
unsigned char m,f=0;
command(0x38);
command(0x0e);
command(0x80);
while(1)
TMOD=0x20;
TH1=0xfd;
SCON=0x50;
TR1=1;
while(RI==0);
m=SBUF;
RI=0;
if(m==0x80)
if(cnt>0)
if(cnt!=0)
delete1();
else
f=0;
delete();
else
if(m==0x0d)
command(0xc0);
cnt++;
f=1;
else
if(cnt==-1)
command(0x80);
cnt++;
if(cnt==16&&f==0)
command(0xc0);
f=1;
command(0x60);
lcddisplay(m);
if(f==0)
cnt++;
else
{
cnt1++;
Output:
Result: Thus, the serial reception was performed successfully by using keil µvision and
hyperterminal.
SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY
(AUTONOMOUS)
DEPT. OF ECE
Experiment-9 DATE:
______________________________________________________________________________
TIMER 0
Aim: Write a program to use the TIMER 0 as a counter.
Apparatus required:
8051 Microcontroller kit
CRO (cathode ray oscilloscope)
Procedure:
1. Set timer in mode1 position
2. Set B as P1.6 in B Register
3. Clear TR0 and TF0
4. Move the data for counting and giving the time to that data.
5. Back instruction is used at two steps of the program
6. Finally the result is stored that is displayed on the Cathode Ray Oscilloscope.
Program:
MOV TMOD,#01H
NEXT: SETB P1.6 (96)
CLR TR0(8C)
CLR TF0
MOV TH0,#0FFH
MOVTL0,#1AH
SETB TR0
BACK1:MOV C,TF0
JNC BACK1
CLR P1.6
CLR TR0
CLRTF0
MOV TH0,#0FDH
MOV TL0,#04DH
SETB TR0
BACK2:MOV C,TF0
JNC BACK2
SJMP NEXT
(SQUARE WAVE)
MOV TMOD,#03H
BACK1:CLR TR1
CLR TF1
MOV TH0,#04AH
SETB TR1
BACK2:MOV C,TF1
JNC BACK2
MOV C,P1.5
CPL C
MOV P1.5,C
SJMP BACK1
Output
Rectangular wave:
Amplitude=
Time period=
T=
Frequency=
Square wave:
Amplitude=
Time period=
T=
Frequency=
Result:
Thus, the program to use Timer `0` as counter has been verified successfully