#include<reg51.h>
sbit led=P1^0;
int main(void)
P1=0x00;
P0=0x00;
P2=0x00;
P3=0x00;
while(1)
led=0;
delay(10000);
led=1;
delay(10000);
void delay(long a)
long i;
for(i=0;i<a;i++);
PRACTICAL 2A
#include<reg51.h>
{
led=0; //output PORT
led = 1; // LED ON
Delay();
Delay();
void Delay()
TL0=0x00;
PRACTICAL 2B
MICROCONTROLLER 1 CODE:
#include <reg51.h>
void main()
{
P2 = 0x00;
while(1)
P1 = P3;
delay(1000);
unsigned int i;
for(i=0;i<time;i++);
MICROCONTROLLER 2 CODE:
//#include <reg51.h>
//void main()
//{
// P2 = 0x00;
// P3 = 0x00;
// while(1)
// {
// P1 = 0X55;
// delay2(10000);
// P1 = 0xAA;
// delay2(10000);
// }
//}
// unsigned long i;
// for(i=0;i<time;i++);
//}
PRACTICAL 3A
#include<reg51.h>
void delay();
void main()
unsigned int i;
while(1)
for(i=0;i<16;i++)
P1=i;
delay();
void delay()
for(i=0;i<8;i++)
for(j=0;j<100;j++)
for(k=0;k<100;k++);
PRACTICAL 3B
PATTERN 1
#include<reg51.h>
Delay2(1000);
Delay2(1000);
Delay2(1000);
Delay2(1000);
Delay2(1000);
Delay2(1000);
Delay2(1000);
long inc,cnt;
for( inc=0;inc<=value;inc++)
for(cnt=0;cnt<2;cnt++);
PATTERN 2
#include "REG51.h"
long int i;
void main()
for(i=0;i<10000;i++);
LED=0x00;
for(i=0;i<10000;i++);
PATTERN 3
#include "REG51.h"
#define LED P1
long int i;
void main()
while(1)
LED=0xAA;
for(i=0;i<4500;i++);
LED=0x55;
for(i=0;i<4500;i++);
PRACTICAL 3C
#include<reg51.h>
TL0 = 0XFD;
}
void main()
TL0 = 0XFD;
while(1)
// Do nothing
PRACTICAL 4A
#include <reg51.h>
void main(void)
long loopvar;
// INITIALIZE SERIAL PORT
SCON = 0x50; // SERIAL MODE 1, 8-DATA BIT 1-START BIT, 1-STOP BIT, REN ENABLED
while(1)
send('B');
for(loopvar=0;loopvar<10000;loopvar++)
{}
send('G');
void send(char x)
PRACTICAL 4B
#include<reg51.h>
for(i=0;i<ms;i++)
for(j=0;j<=1275;j++);
void main(void)
char number[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int i,j;
P2=0x00;
P3=0x00;
while(1)
for(i=0;i<=9;i++)
P2=number[i];
for(j=0;j<=9;j++)
P3=number[j];
delay(50);
PRACTICAL 4C
#include<REG51.h>
void fordelay();
void main()
P2=0x00;
while(1)
P2=0xFF;
fordelay();
P2=0x00;
fordelay();
void fordelay()
{
long i=0;
for(i=0;i<=5000;i++)
{}
PRACTICAL 5A
#include<reg51.h>
void main()
P1=0x00;
while(1)
do
while(P1<0xFF);
do
while(P1>0x00);
PRACTICAL 5B
#include<reg51.h>
void main()
int WaveValue[12]={128,192,238,255,238,192,128,64,17,0,17,64};
int i;
while(1)
{
for(i=0;i<12;i++)
P1=WaveValue[i];
PRACTICAL 6
#include<reg51.h>
#define stepper P1
void delay()
for(i=0;i<6;i++) {
for(j=0;j<255;j++)
for(k=0;k<255;k++);
void main()
while (1) {
stepper = 0x08;
delay();
stepper = 0x02;
delay();
stepper = 0x04;
delay();
stepper = 0x01;
delay();
}
//Clockwise
//void main()
//{
//while (1) {
//stepper = 0x0C;
//delay();
//stepper = 0x06;
//delay();
//stepper = 0x03;
//delay();
//stepper = 0x09;
//delay();
//}
//}
#include<reg52.h>
#include<stdio.h>
void delay(int);
void main()
do
P2=0x01; //0001
delay(1000);
P2=0x02; //0010
delay(1000);
P2=0x04; //0100
delay(1000);
P2=0x08; //1000
delay(1000);
while(1);
void delay(int k)
int i,j;
for(i=0;i<k;i++)
for(j=0;j<100;j++)
{}
#include<reg52.h>
#include<stdio.h>
void delay(int);
void main()
do
P2=0x01; //0001
delay(1000);
P2=0x03; //0011
delay(1000);
P2=0x02; //0010
delay(1000);
P2=0x06; //0110
delay(1000);
P2=0x04; //0100
delay(1000);
P2=0x0C; //1100
delay(1000);
P2=0x08; //1000
delay(1000);
P2=0x09; //1001
delay(1000);
} while(1);
void delay(int k)
int i,j;
for(i=0;i<k;i++)
for(j=0;j<100;j++)
{}
#include<reg52.h>
#include<stdio.h>
void delay(int);
void main()
{
do
P2 = 0x03; //0011
delay(1000);
P2 = 0x06; //0110
delay(1000);
P2 = 0x0C; //1100
delay(1000);
P2 = 0x09; //1001
delay(1000);
while(1);
void delay(int k)
int i,j;
for(i=0;i<k;i++)
for(j=0;j<100;j++)
{}
#include<reg51.h>
sbit red_west=P1^2;
sbit yellow_west=P1^1;
sbit green_west=P1^0;
sbit red_south=P1^4;
sbit yellow_south=P1^3;
sbit green_south=P2^7;
sbit red_north=P1^7;
sbit yellow_north=P1^5;
sbit green_north=P1^6;
sbit red_east=P2^0;
sbit yellow_east=P2^1;
sbit green_east=P2^2;
void main()
P1=0;
P2=0;
SignalWait(15000);
while(1)
red_west=1;
red_east=1;
red_north=0;
red_south=0;
green_north=1;
green_south=1;
SignalWait(15000);
green_north=0;
green_south=0;
yellow_north=1;
yellow_south=1;
SignalWait(15000);
yellow_north=0;
yellow_south=0;
red_north=1;
red_south=1;
red_west=0;
red_east=0;
green_west=1;
green_east=1;
SignalWait(15000);
green_west=0;
green_east=0;
yellow_west=1;
yellow_east=1;
SignalWait(15000);
yellow_west=0;
yellow_east=0;
long inc,cnt;
for(inc=0;inc<=time;inc++)
for(cnt=0;cnt<2;cnt++);
PRACTICAL 9 ELEVATOR
#include <REG51.h>
int GROUNDFLOOR = 0;
char number[]={0x3D,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
char motor_lookup[]={0x09,0x08,0x0C,0x04,0x06,0x02,0x03,0x01};
void main(){
P0 = P2 = P3 = 0;
CurrentFloor = GROUNDFLOOR;
DisplayValue = GROUNDFLOOR;
FloorFlag = GROUNDFLOOR;
P3 = GNDFLR;
while(1)
if( FloorG == 0 )
FloorFlag = 0;
else if(Floor1 == 0)
{
FloorFlag = 1;
else if(Floor2 == 0)
FloorFlag = 2;
else if(Floor3 == 0)
FloorFlag = 3;
else if(Floor4 == 0)
FloorFlag = 4;
else if(Floor5 == 0)
FloorFlag = 5;
else if(Floor6 == 0)
FloorFlag = 6;
else if(Floor7 == 0)
FloorFlag = 7;
do{
CurrentFloor++;
DisplayValue++;
P3 = number[DisplayValue];
P2 = motor_lookup[DisplayValue];
delay(100000);
do{
CurrentFloor--;
DisplayValue--;
P3 = number[DisplayValue];
P2 = motor_lookup[DisplayValue];
delay(100000);
}while(CurrentFloor != FloorFlag);
THANK ME LATER!!:)