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

Share Embed Donate


Short Description

New...

Description

ELECTRONIFY HOME

BASIC

LEARN MICROCONTROLLER

MICROCONTROLLER PROJECTS

ELECTRONIC PROJECTS

LATEST

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

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

 * Project name:

3

     Automatic traffic light control with microcontroller

4

 * Copyright:

5

     (c) lET'S THINk BINARY, 2017.

6

 * Revision History:

7

     V0.0

8

 * Description:

9

      Automatic traffic light using PIC Microcontroller .

10

 * Test configuration:

11

     MCU:             PIC16f877a

12 13

     Oscillator:      8.0000 MHz Crystal

14

     SW:              mikroC PRO for PIC

15

                      http://www.mikroe.com/mikroc/pic/

16

 * NOTES:

17

     ‐  This Our Group (thanks to join and participate) :

18

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

19

     ‐  Facebook page (thanks to like and share) :

20

        https://www.facebook.com/Lets‐Think‐Binary‐1728910547340654/

21

     ‐  Youtube Channel (thanks to subscribe) :

22

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

23

 */

24 25

#include "Display_Utils.h"

26 27

unsigned short shifter, portd_index;

28

unsigned short portd_array[4];

29

int digit,digit1, digit10,i;

30 31

sbit led_Green1 at portC.b0;

32

sbit led_Yellow1 at portC.b1;

33

sbit led_Red1 at portC.b2;

34

sbit led_Green2 at portC.b5;

35

sbit led_Yellow2 at portC.b6;

36

sbit led_Red2 at portC.b7;

37 38

void interrupt() {

39

  PORTA = 0;                             // Turn off all 7seg displays

40

  PORTD = portd_array[portd_index];      // bring appropriate value to PORTD

41

  PORTA = shifter;                       // turn on appropriate 7seg. display

42 43

  // move shifter to next digit

44

  shifter  3u)

51

    portd_index = 0;             // turn on 1st, turn off 2nd 7seg.

52

  TMR0  =   0;                  // reset TIMER0 value

53

  TMR0IF_bit = 0;                // Clear TMR0IF

54

}

55 56 57

 void display(){

58

      digit   = i % 10u;

59

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

60

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

61

      portd_array[2] = conversion(digit);

62

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

63

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

64

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

65

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

66

      }

67 68

void main(){

69 70

     ADCON1=6;                      // Configure PORTX pins as digital

71

     TRISA = 0;                     // Configure PORTA as output

72

     PORTA  = 0;                     // Clear PORTA

73

     TRISD = 0;                     // Configure PORTD as output

74

     PORTD  = 0;                     // Clear PORTD

75

     TRISC=0;

76

     PORTC=0;

77

     OPTION_REG=0x80;                // Timer0 settings

78

     TMR0 = 0;                     // clear TMROL

79

     digit = 0;

80

     portd_index = 0;

81

     shifter = 1;

82

     GIE_bit = 1;                     // Enaable GIE

83

     TMR0IE_bit = 1;                  // Enaable T0IE

84

     //INTCON      = 0xA0;                  // Enaable GIE,T0IE

85 86

do{

87

     // PHASE1

88

     PORTC=0;

89

     i=30;

90

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

91

                       display();

92

                       led_Green1=1; led_Red2=1;

93

                       delay_ms(400);

94

                     }

95

     //PHASE2

96

     PORTC=0;

97

     i=3;

98

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

99

                     display();

100

                     led_Yellow2=1;led_Yellow1=1;

101

                     delay_ms(400);

102

                     }

103

     //PHASE3

104

     PORTC=0;

105

     i=20;

106

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

107

                     display();

108

                     PORTC=0;

109

                     led_Green2=1; led_Red1=1;

110

                     delay_ms(400);

111

                     }

112

     //PHASE4

113

     PORTC=0;

114

     i=3;

115

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

116

                     display();

117

                     led_Yellow2=1;led_Yellow1=1;

118

                     delay_ms(400);

119

                     }

120 121

  }while(1);     // infinite loop

122

}     // end of program

traffic_light_controller_using_pic.c hosted with

by GitHub

view raw

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 0  Share

31  Share

 Tweet

FILED UNDER: PIC BASED PROJECTS

 Pin0

0  Share

0  Share

TAGGED WITH: PIC TRAFFIC LIGHT, TRAFFIC LIGHT, TRAFFIC LIGHT CONTROLLER

SOCIAL LINKS

ELECTRONIFY LINKS About us Career Amazon store Contact Us Download proteus

© All right reserved to electronify 2016

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF