0% found this document useful (0 votes)
16 views2 pages

Code

The document outlines a traffic light control system implemented in C programming. It defines the control pins for four traffic lights and includes a main function that cycles through different traffic light states with specified delays. The system manages the red, amber, and green lights for each traffic signal in a sequential manner.
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)
16 views2 pages

Code

The document outlines a traffic light control system implemented in C programming. It defines the control pins for four traffic lights and includes a main function that cycles through different traffic light states with specified delays. The system manages the red, amber, and green lights for each traffic signal in a sequential manner.
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

//TRAFFIC LIGHT SYSTEM LAB BECE GROUP 2

sbit red1 at RB0_bit; // Controls the RED light of the 1ST traffic light
sbit amber1 at RB1_bit; // Controls the AMBER light of the 1ST traffic light
sbit green1 at RB2_bit; // Controls the GREEN light of the 1ST traffic light

sbit red2 at RB3_bit; // Controls the R light of the 2ND traffic light
sbit amber2 at RB4_bit; // Controls the A light of the 2ND traffic light
sbit green2 at RB5_bit; // Controls the G light of the 2ND traffic light

sbit red3 at RB6_bit; // Controls the R light of the 3RD traffic light
sbit amber3 at RB7_bit;// Controls the R light of the 3RD traffic light
sbit green3 at RC0_bit; // Controls the G light of the 3RD traffic light

sbit red4 at RC1_bit;// Controls the R light of the 4TH traffic light
sbit amber4 at RC2_bit; // Controls the A light of the 4TH traffic light
sbit green4 at RC3_bit; // Controls the G light of the 4TH traffic light

void main() {
TRISB=0x00; // Sets all pins on port B to output mode.
TRISC=0x00;

while(1)
{

// TRAFFIC 1 G1=ON R2,R3,R4=ON

red1=0;amber1=0;green1=1;
red2=1;amber2=0;green2=0;
red3=0;amber3=0;green3=1;
red4=1;amber4=0;green4=0;
delay_ms(10000);

//TRAFFIC 2 R3,R4=ON A1,A2=ON

red1=0;amber1=1;green1=0;
red2=1;amber2=0;green2=0;
red3=0;amber3=1;green3=0;
red4=1;amber4=0;green4=0;
delay_ms(2000);

//TRAFFIC 3 R1,R3,R4=ON A2,A3=ON G2=ON

red1=1;amber1=0;green1=0;
red2=0;amber2=0;green2=1;
red3=1;amber3=0;green3=0;
red4=0;amber4=0;green4=1;
delay_ms(10000);

//TRAFFIC 4 R1,R4=ON A3=ON

red1=1;amber1=0;green1=0;
red2=0;amber2=1;green2=0;
red3=1;amber3=0;green3=0;
red4=0;amber4=1;green4=0;
delay_ms(2000);

}
}

You might also like