0% found this document useful (0 votes)
4 views

Elec Practical

Uploaded by

Sid1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Elec Practical

Uploaded by

Sid1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <reg52.

h>

#define ON 0 // Define ON as logic low (0V)


#define OFF 1 // Define OFF as logic high (+5V)

// Define control bits for North traffic lights


sbit NG = P3^2; // North Green light
sbit NY = P3^1; // North Yellow light
sbit NR = P3^0; // North Red light

// Define control bits for East traffic lights


sbit EG = P3^3; // East Green light
sbit EY = P3^4; // East Yellow light
sbit ER = P3^5; // East Red light

// Define control bits for South traffic lights


sbit SG = P2^2; // South Green light
sbit SY = P2^1; // South Yellow light
sbit SR = P2^0; // South Red light

// Define control bits for West traffic lights


sbit WG = P2^3; // West Green light
sbit WY = P2^4; // West Yellow light
sbit WRed = P2^5; // West Red light

// Function declaration for a millisecond delay


void Delayms(unsigned int msec);
void Delayms(unsigned int msec)
{
unsigned int x, y;
for (x = 0; x <= msec; x++)
{
for (y = 0; y <= 110; y++)
{
// Empty loop for delay
}
}
}

void main(void)
{
P3 = 0xFF; // Set all P3 pins high initially
P2 = 0xFF; // Set all P2 pins high initially

// Initialize all directions to red


NR = ON;
WRed = ON;
SR = ON;
ER = ON;
Delayms(6000); // Initial delay

while(1)
{
// North direction traffic light sequence
NR = OFF;
NG = ON;
Delayms(2000); // North green light for 2 seconds

NG = OFF;
NY = ON;
Delayms(800); // North yellow light for 800 milliseconds
NY = OFF;
NR = ON;

// East direction traffic light sequence


ER = OFF;
EG = ON;
Delayms(2000); // East green light for 2 seconds

EG = OFF;
EY = ON;
Delayms(800); // East yellow light for 800 milliseconds
EY = OFF;
ER = ON;

// South direction traffic light sequence


SR = OFF;
SG = ON;
Delayms(2000); // South green light for 2 seconds

SG = OFF;
SY = ON;
Delayms(800); // South yellow light for 800 milliseconds
SY = OFF;
SR = ON;

// West direction traffic light sequence


WRed = OFF;
WG = ON;
Delayms(2000); // West green light for 2 seconds

WG = OFF;
WY = ON;
Delayms(800); // West yellow light for 800 milliseconds
WY = OFF;
WRed = ON;
}
}

You might also like