Code
Code
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)
{
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);
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);
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);
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);
}
}