1. Simulate the program to toggle all bits of P0,P1 and P2 every 0.
25 of a
second and verify it. Assume crystal frequency of 11.0592 Hz.
#include<reg51.h>
void delay(void);
void main()
while(1)
P0=0x00;
P1=0x00;
P2=0x00;
delay();
P0=0xFF;
P1=0xFF;
P2=0xFF;
delay();
void delay(void)
int i;
TMOD=0x01;
for(i=0;i<1000;i++)
TL0=0x1A;
TH0=0xFF;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
2. Simulate a 8051 C program to toggle all bits of P0 and P2 continuously
with 250 ms delay and verify it.
#include<reg51.h>
void delay(void);
void main()
while(1)
P0=0x00;
P2=0x00;
delay();
P0=0xFF;
P2=0xFF;
delay();
void delay(void)
int i;
TMOD=0x01;
for(i=0;i<1000;i++)
TL0=0x1A;
TH0=0xFF;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
3. Apply the concept of interrupt and simulate a C program that continuously
gets a single bit of data from P1.7 and sends it to P1.0. While
simultaneously create a square wave of 200 micro seconds period on pin
2.5. Use timer 0 to create square wave. Assume crystal frequency of
11.0592 Hz.
#include<reg51.h>
sbit sw=P1^7;
sbit ind=P1^0;
sbit tg=P2^5;
void timer0() interrupt 1
tg=~tg;
void main()
{
sw=1;
TMOD=0x10;
TH0=0xFF;
TL0=0x47;
IE=0x82;
TR0=1;
while(1)
ind=sw;
4. Simulate a program by applying the concept of Serial communication on
8051 to transmit bytes of data serially and put them in P1 . Set the baud
rate as 4800, 8 bit data and 1 stop bit. List out the calculations in setting
the baud rate calculations.
#include<reg51.H>
void main(void)
unsigned char mybyte;
TMOD=0x20;
TH1=0xFA;
SCON=0x50;
TR1=1;
while(1)
{
SBUF='A';
while(TI==0);
TI=0;
5. Simulate a program by applying the concept of Serial communication on
8051 to receive bytes of data serially and put them in P1 . Set the baud rate
as 9600, 8 bit data and 1 stop bit. List out the calculations in setting the
baud rate.
#include<reg51.H>
void main(void)
unsigned char mybyte;
TMOD=0x20;
TH1=0xFD;;
SCON=0x50;
TR1=1;
while(1)
while(RI==0);
mybyte=SBUF;
P1=mybyte;
RI=0;
}
6. Simulate a Embedded C program in which a switch is connected to pin 2.7
and to monitor the status of SW(switch) and perform the following (a) If
SW=0, the stepper motor moves clockwise (b) If SW=1, the stepper motor
moves Anti-clockwise
#include<reg51.h>
sbit ind=P2^7;
void msdelay(unsigned int value)
unsigned int i,j;
for(i=0;i<1275;i++)
for (j=0;j<value;j++);
void main()
ind=1;
while(1)
if(ind==0)
P1=0x66;
msdelay(100);
P1=0xCC;
msdelay(100);
P1=0x99;
msdelay(100);
P1=0x33;
msdelay(100);
else
P1=0x66;
msdelay(100);
P1=0x33;
msdelay(100);
P1=0x99;
msdelay(100);
P1=0xCC;
msdelay(100);
7. Simulate the following two programs on the stepper motor (a) Clockwise
using 4 step sequence (b) Anticlockwise using 8 step sequence
//a.clockwise using four step sequence
#include<reg51.h>
void msdelay(unsigned int itime)
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
void main(void)
while(1)
P1=0x08;
msdelay(200);
P1=0x04;
msdelay(200);
P1=0x02;
msdelay(200);
P1=0x01;
msdelay(200);
//b.counterclockwise using eight step sequence
#include<reg51.h>
void msdelay(unsigned int itime)
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
void main(void)
while(1)
P1=0x09;
msdelay(200);
P1=0x01;
msdelay(200);
P1=0x03;
msdelay(200);
P1=0x02;
msdelay(200);
P1=0x06;
msdelay(200);
P1=0x06;
msdelay(200);
P1=0x04;
msdelay(200);
P1=0x0C
msdelay(200);
P2=0x08
msdelay(200)
}
}
8. Apply the concept of PWM, Simulate a program by monitoring the status
of SW(switch), (a) If SW=0, the DC motor moves with 50% Duty cycle
(b) If SW=1, the DC motor moves with 25% Duty cycle Assume
SW(switch) is connected to port 2.7 and the MOTOR is connected to Port
1.0
#include<reg51.h>
sbit sw=P2^7;
sbit mtr=P1^0;
void msdelay(unsigned int value)
unsigned int i,j;
for(i=0;i,value;i++)
for(j=0;j<1275;j++);
void maun(void)
sw=1;
mtr=0;
if(sw==1)
mtr=1;
msdelay(25);
mtr=0;
msdelay(75);
}
else
mtr=1;
msdelay(50);
mtr=0;
msdelay(50);
9. Simulate 8051 based embedded C program interfaced with LCD to send
letters “M” , “D”, “E” to the 16x2 LCD display.
#include<reg51.h>
sfr ldata=0x90;
void msdelay(unsigned int itime);
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
void main()
lcdcmd(0x38);
msdelay(250);
lcdcmd(0x0E);
msdelay(250);
lcdcmd(0x01);
msdelay(250);
lcdcmd(0x06);
msdelay(250);
lcdcmd(0x86);
msdelay(250);
lcddata('M');
msdelay(250);
lcddata('D');
msdelay(250);
lcddata('E');
msdelay(250);
void lcdcmd(unsigned char value)
ldata=value;
rs=0;
rw=0;
en=1;
msdelay(1);
en=0;
return;
}
void lcddata( unsigned char value)
ldata= value;
rs=1;
rw=0;
en=1;
msdelay(1);
en=0;
return;
void msdelay(unsigned int itime)
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
10. Write a C code to read the temperature value from ADC0848 and convert
it in to decimal and put it in to P0 with a delay of 10 milli seconds.
#include<reg51.h>
sbit rd=P2^5;
sbit wr=P2^6;
sbit intr=P2^7;
sfr mydata=0x90;
void convertanddisplay(unsigned char value);
void msdelay(unsigned int value);
unsigned char value;
void main()
mydata=0xFF;
intr=1;
rd=1;
wr=1;
while(1)
wr=0;
wr=1;
while(intr==1);
rd=0;
value=mydata;
convertanddisplay(value);
rd=1;
void convertanddisplay(unsigned char value)
unsigned char x,d1,d2,d3;
x=value/10;
d1=value%10;
d2=x%10;
d3=x/10;
P0=d1;
msdelay(250);
P0=d2;
msdelay(250);
P0=d3;
msdelay(250);
void msdelay(unsigned int value)
unsigned char x,i,j;
for(x=0;x<9216;x++)
for(i=0;i<value;i++)
for(j=0;j<1275;j++);
11. C program to interface ADC 0808 with 8051 and verify the same by
connecting the LEDs in Port 1.
#include<reg51.h>
//SBIT RD=P^0;
//SBIT WR=P1^1;
//SBIT INTR=PI^2;
void main()
{
unsigned char value;
P3=0xFF;
P0=0xFF;
P1=0x04;
P1=0x01;
P1=0x02;
while (1)
P1=0x00;
WR=0x01;
while (P1=0x04);
P1-0x00;
value=P3;
P0=value;
P1=0x01;
12. Simulate a 8051 based embedded program to toggle all bits of P2
continuously every 500 milli seconds . Use timer 1 , mode 1 to create the
delay
#include<reg51.h>
void msdelay(void);
unsigned int x;
void main(void)
{
while(1)
P2=~P2;
msdelay();
void msdelay(void)
TMOD=0x10;
for(x=0;x<1000;x++)
TL1=0x33;
TH1=0xFE;
TR1=1;
while(TF1==0);
TR1=0;
TF1=0;