• No results found

Automatic Traffic Light Using PIC Microcontroller Code , Circuit Diagram and Explanation – Electronify

N/A
N/A
Protected

Academic year: 2021

Share "Automatic Traffic Light Using PIC Microcontroller Code , Circuit Diagram and Explanation – Electronify"

Copied!
6
0
0

Loading.... (view fulltext now)

Full text

(1)

ELECTRONIFY

You are here: Home / PIC Based Projects / Automatic traf c light using PIC Microcontroller

Automatic traf c light using PIC Microcontroller

APRIL 5, 2017 BY PRASANT

Traf c light controller using PIC microcontroller

The objective of this project is to design a traf c light control system. This traf c light controller is used at the intersection that consists of a main road and two side roads. A four way traf c 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 4-way junction, where each way has its traf c light and counter. Low power LEDs are used for every traf c light with different colors, namely red, yellow and green. The red LED indicates “stop driving”, the yellow LED indicates “start

HOME BASIC LEARN MICROCONTROLLER ELECTRONIC PROJECTS

(2)

stopping” and the green LED indicates “drive”. The sequence of altering the LEDs according to their color is as shown in the gure below: Green-Yellow-Red-Green. Twelve LEDs are used;three to each traf c light.

7-segment LED displays are used to show the current count value. Since all of the

traf c lights are working simultaneously, each one is to display a different digit than the other. When a traf c light is tuned green, its corresponding 7-segment displays start counting down from a speci c 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 traf c 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. PDL (Program Description Language) :

Turn on led_Red1 Turn on led_Green2 Wait 30 seconds Turn on led_Yellow1 Turn on led_Yellow2 Wait 3 seconds Turn on led_Red2 Turn on led_Green1 Wait 20 seconds Turn on led_Yellow1 Turn on led_Yellow2 Wait 3 seconds Software Development

The code developed for the PIC is written in the C language. The compiler used to write the C code is mikroC PRO for PIC V. 6.6.3. After the c code is successfully compiled, a HEX le is generated. CODE : 1 2 3 /*  * Project name:      Automatic traffic light control with microcontroller

(3)

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61  * Copyright:      (c) lET'S THINk BINARY, 2017.  * Revision History:      V0.0  * Description:       Automatic traffic light using PIC Microcontroller .  * Test configuration:      MCU:       PIC16f877a      Oscillator:      8.0000 MHz Crystal      SW:      mikroC PRO for PIC       http://www.mikroe.com/mikroc/pic/  * NOTES:      ‐  This Our Group (thanks to join and participate) :         https://www.facebook.com/groups/816450708460518/      ‐  Facebook page (thanks to like and share) :         https://www.facebook.com/Lets‐Think‐Binary‐1728910547340654/      ‐  Youtube Channel (thanks to subscribe) :         https://www.youtube.com/channel/UCTIAzxEkyeA6HTvl_VHd‐Tw  */ #include "Display_Utils.h"

unsigned short shifter, portd_index;

unsigned short portd_array[4];

int digit,digit1, digit10,i; sbit led_Green1 at portC.b0; sbit led_Yellow1 at portC.b1; sbit led_Red1 at portC.b2; sbit led_Green2 at portC.b5; sbit led_Yellow2 at portC.b6; sbit led_Red2 at portC.b7; void interrupt() {   PORTA = 0;       // Turn off all 7seg displays   PORTD = portd_array[portd_index];      // bring appropriate value to PORTD   PORTA = shifter;       // turn on appropriate 7seg. display   // move shifter to next digit   shifter <<= 1;   if (shifter > 8u)     shifter = 1;   // increment portd_index   portd_index++ ;   if (portd_index > 3u)     portd_index = 0;       // turn on 1st, turn off 2nd 7seg.   TMR0  =   0;      // reset TIMER0 value   TMR0IF_bit = 0;      // Clear TMR0IF }  void display(){       digit   = i % 10u;

      digit1  = conversion(digit);       // prepare ones digit

      portd_array[0] = conversion(digit);        // and store it to PORTD array       portd_array[2] = conversion(digit);

(4)

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

      digit   = (char)(i / 10u) % 10u;

      digit10 = conversion(digit);       // prepare tens digit

      portd_array[1] = conversion(digit);        // and store it to PORTD array       portd_array[3] = conversion(digit);        // and store it to PORTD array       } void main(){      ADCON1=6;      // Configure PORTX pins as digital      TRISA = 0;       // Configure PORTA as output      PORTA  = 0;       // Clear PORTA      TRISD = 0;       // Configure PORTD as output      PORTD  = 0;       // Clear PORTD      TRISC=0;      PORTC=0;      OPTION_REG=0x80;      // Timer0 settings      TMR0 = 0;       // clear TMROL      digit = 0;      portd_index = 0;      shifter = 1;      GIE_bit = 1;       // Enaable GIE      TMR0IE_bit = 1;      // Enaable T0IE      //INTCON      = 0xA0;      // Enaable GIE,T0IE do{      // PHASE1      PORTC=0;      i=30;

     for(i;i>=0;i‐‐){

       display();        led_Green1=1; led_Red2=1;        delay_ms(400);        }      //PHASE2      PORTC=0;      i=3;

     for(i;i>=0;i‐‐){

       display();        led_Yellow2=1;led_Yellow1=1;        delay_ms(400);        }      //PHASE3      PORTC=0;      i=20;

     for(i;i>=0;i‐‐){

       display();        PORTC=0;        led_Green2=1; led_Red1=1;        delay_ms(400);        }      //PHASE4      PORTC=0;      i=3;

     for(i;i>=0;i‐‐){

       display();

       led_Yellow2=1;led_Yellow1=1;        delay_ms(400);

(5)

FILED UNDER: PIC BASED PROJECTS TAGGED WITH: PIC TRAFFIC LIGHT, TRAFFIC LIGHT, TRAFFIC LIGHT CONTROLLER view raw 120

121 122

traffic_light_controller_using_pic.c hosted with by GitHub

Results :

Compile the PIC code and get the hex le from it.

For simulating with PROTEUS ISIS hit run button and then you will get above output. Resource :

You can download the MikroC Source Code and Proteus les etc from this link traf c light controller :

This Our Group (thanks to join and participate) :

https://www.facebook.com/groups/816450708460518/

Facebook page : https://www.facebook.com/Lets-Think-Binary-1728910547340654/ Youtube Channel (thanks to subscribe) :

https://www.youtube.com/channel/UCTIAzxEkyeA6HTvl_VHd-Tw  

PLEASE ! SHARE THIS PROJECT  

       

 PROJECT BY : SALAH

DAHOUATHI

  }while(1);     // infinite loop }     // end of program

Share0

(6)

SOCIAL LINKS ELECTRONIFY LINKS About us Career Amazon store Contact Us Download proteus

References

Related documents