TRAFFIC LIGHT CONTROL USING PIC16F877A




The normal function of traffic lights requires more than slight control and coordination to ensure that traffic moves as smoothly and safely as possible and that pedestrians are protected when they cross the roads. A variety of different control systems are used to accomplish this, ranging from simple clockwork mechanisms to sophisticated computerized control and coordination systems that self-adjust to minimize delay to people using the road.
OBJECTIVE:
The objective of this project is to design a traffic light control system for a Y or T junction .
A three way traffic light control system with count down timers is to be designed and constructed. The system is to be developed with the PIC16f877A chip being the microcontroller that is programmed to do the task of controlling. Figure shows the drawing of the 3-way junction, where each way has its traffic light and counter.
Low power LEDs are used for every traffic light with different colors, namely red, yellow and green. The red LED indicates “stop driving”, the yellow LED indicates “start stopping” and the green LED indicates “drive”. The sequence of altering the LEDs according to their color is as shown in the figure below: Green-Yellow-Red-Green. Twelve LEDs are used; three to each traffic light.
7-segment LED displays are used to show the current count value. Since all of the traffic lights are working simultaneously, each one is to display a different digit than the other. When a traffic light is tuned green, its corresponding  pair 7-segment displays start counting down from a specific value and decrements until zero is reached. After this the counter starts by a new count value at the moment the yellow light turns on. When the red light turns on after the yellow took its time, the count continues to decrement until reaching zero. This means that the same 7-segments, on each traffic light, are used to display the count when cars are allowed and not allowed to pass. In terms of counting, the yellow and red are considered one set while the green is another set.

CIRCUIT DIAGRAM:



CODE SECTION:



Embedded C Code
// Name : SLTECH
// Purpose : T JUNCTION TRAFFIC LIGHT CONTROLL
// Date : 04/09/2017
// Website : www.slltechservices.com.ng


#include <htc.h>
#include <pic.h>
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 4E6
#endif
void d();void dd();
void count();
void count7();void count8();



void main(void) {

 TRISB =0x00;            
 TRISC=0x00;        
 TRISD=0x00;
 TRISA=0b000000;TRISE=0b000;
INTCON=0b00000000;
ADCON1=0x06;CMCON=7;
T1CON=0b00000010;T2CON=0b00000000;

PORTA=PORTB=PORTC=PORTD=PORTE=PORTD=0;;
PORTB=PORTC=PORTD=0X3F;d();
  while(1){ADCON1=0x06;


 count();
 count7();
 count8();
    
    }
}

void d(){__delay_ms(20);}
void dd(){__delay_ms(5);}

void count(){
RA2=1;RA4=1;RE0=1;
PORTB=0x6F;d();
PORTB=0x7F;d();



}
void count7(){
RA0=1;RA5=1;RE1=1;


PORTC=0x3F;d();
RA0=0;RA5=0;RE1=0;
}
void count8(){
RE2=1;RA1=1;RA3=1;
PORTD=0x6F;d();


PORTD=0x3F;d();
RE2=RA1=RA3=0;
}
 

1 comment: