ECPLABPROGRAM
ECPLABPROGRAM
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;
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;
tg=~tg;
void main()
{
sw=1;
TMOD=0x10;
TH0=0xFF;
TL0=0x47;
IE=0x82;
TR0=1;
while(1)
ind=sw;
#include<reg51.H>
void main(void)
TMOD=0x20;
TH1=0xFA;
SCON=0x50;
TR1=1;
while(1)
{
SBUF='A';
while(TI==0);
TI=0;
#include<reg51.H>
void main(void)
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;
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
#include<reg51.h>
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);
#include<reg51.h>
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)
}
}
#include<reg51.h>
sbit sw=P2^7;
sbit mtr=P1^0;
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);
#include<reg51.h>
sfr ldata=0x90;
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);
ldata=value;
rs=0;
rw=0;
en=1;
msdelay(1);
en=0;
return;
}
ldata= value;
rs=1;
rw=0;
en=1;
msdelay(1);
en=0;
return;
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 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;
x=value/10;
d1=value%10;
d2=x%10;
d3=x/10;
P0=d1;
msdelay(250);
P0=d2;
msdelay(250);
P0=d3;
msdelay(250);
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()
{
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;
#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;