Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
257 views3 pages

Traffic Lights - Using PIC16F877

This document describes a traffic light control project using a PIC16F877 microcontroller. It connects 12 LEDs across 4 traffic lights to two ports of the PIC. The MikroC code cycles through 3 cases, setting the state of the LEDs on each port to simulate the traffic light sequences. It uses direct port manipulation and delays to control the lights in a repeating cycle.

Uploaded by

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

Traffic Lights - Using PIC16F877

This document describes a traffic light control project using a PIC16F877 microcontroller. It connects 12 LEDs across 4 traffic lights to two ports of the PIC. The MikroC code cycles through 3 cases, setting the state of the LEDs on each port to simulate the traffic light sequences. It uses direct port manipulation and delays to control the lights in a repeating cycle.

Uploaded by

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

Traffic Lights – using PIC16F877

This is one of the easiest projects that you may do to learn on how to use the PIC & Connect
some Hardwares to it.

www.facebook.com/ELECTRONICS.LOVERZ
Software Needed:
1. MikroC - to write the code
2. Protues - to simulate the hardware
Hardware:
1. Resisters of 310 ohm before each light
2. Earth (Ground)
3. 5 volt DC power
4. Traffic Lights X4 or 12X Diods
5. PIC16F877 or PIC16F877A

MikroC Code:
The idea here that we connected 3×4 (3: light on each traffic light represent the
colors Red, Yellow, Green then 4: represent the number of the traffic lights on the
cross street) lights to 2 ports of the PIC16f877 PORTB & PORTC …
traffic light #1 took the following: PB0, PB1, PB2 (RED, YELLOW, GREEN)
traffic light #2 took the following: PB3, PB4, PB5 (RED, YELLOW, GREEN)
traffic light #3 took the following: PB6, PB7, PC0 (RED, YELLOW, GREEN)
traffic light #4 took the following: PC1, PC2, PC3 (RED, YELLOW, GREEN)
Example:
Case 1
#1 (Red = 1, Yellow = 0 , Green = 0) = RED
#2 (Red = 1, Yellow = 0, Green = 0) = RED
#3 (Red = 1, Yellow = 0, Green = 0) = RED
#4 (Red = 0, Yellow = 0, Green = 1) = Green
And so on you can repeat the the previous case and change the parameters …
Now, before we go writing the code, you have to know that you can do this project
in many ways, we have used the easiest direct way by setting the state of each
traffic light and display it, and we call a delay method. following is the

www.facebook.com/ELECTRONICS.LOVERZ
code:
void main() {
trisb=0; //make port B output
trisc=0; //make port C output
while(1)
{
portb = 0b01001001;
portc = 0b00001000;
delay_ms(500);
portb = 0b01001001;
portc = 0b00000100;
delay_ms(500);
portb = 0b01001001;
portc = 0b00000010;
delay_ms(500); //case 1 finish
portb = 0b00001001;
portc = 0b00000011;
delay_ms(500);
portb = 0b10001001;
portc = 0b00000010;
delay_ms(500);
portb = 0b01001001;
portc = 0b00000010;
delay_ms(500); //case 2 finish
portb = 0b01100001;
portc = 0b00000010;
delay_ms(500);
portb = 0b01010001;
portc = 0b00000010;
delay_ms(500);
portb = 0b01001001;
portc = 0b00000010;
delay_ms(500); //case 3 finish
portb = 0b01001100;
portc = 0b00000010;
delay_ms(500);
portb = 0b01001010;
portc = 0b00000010;
delay_ms(500);
portb = 0b01001001;
portc = 0b00000010;
delay_ms(500); //case 4 finish
} //close while loop
} //close void main

You might also like