PIC microcontroller C language programming (13)

Publisher:LogicLeaperLatest update time:2013-02-05 Source: dzsc Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  14. Red and green lights for urban traffic intersection management

  At the crossroads of city streets, various indicator patterns composed of red and green high-brightness LEDs are placed to manage motor vehicles, non-motor vehicles and pedestrians so that they can pass through their respective intersections safely and smoothly. These traffic light patterns are varied. The author takes the control of one of the traffic light patterns at the crossroads as an example to illustrate the application of PIC microcontroller C language in urban traffic light management.

  FIG55a is a palm-shaped indicator pattern composed of red high-brightness LEDs, which is displayed at the intersection. It indicates that pedestrians are prohibited from passing in this direction at this time. FIG55b and FIG55c are respectively human-shaped and bicycle-shaped indicator patterns composed of green high-brightness LEDs. When the patterns are displayed at the intersection, it indicates that people are allowed to pass at this time. FIG56 is a circular indicator pattern composed of red and green high-brightness LEDs (red and green are displayed in time-sharing mode) to indicate whether motor vehicles are allowed to pass. The above-mentioned indicator patterns are all set on the traffic road 13 and are displayed alternately in a time-sharing manner. The length of time for each indicator pattern to be displayed is set according to the actual situation of the traffic and pedestrian flow on different roads 13, generally between 80 seconds and 140 seconds (special intersections can be up to 180 seconds, or even longer).

Fig.55

Fig.56

  By using the 121 bit of the PIC16F877 or PIC16F876 microcontroller and the corresponding driving circuit, the high-brightness red and green LEDs that make up the indication patterns shown in Figures 55 and 56 can be driven to display according to the required timing, thus realizing the above functions. By installing them in a box and at a designated location at a traffic intersection, traffic management at the intersection can be performed. [page]

    1. Hardware circuit and function

  (1) Hardware circuit

  According to the above-mentioned traffic intersection traffic light indication pattern display requirements, the hardware circuit designed by PIC16F877 is shown in Figure 57.

Fig.57

  As can be seen from Figure 57, PIC16F877 has 40 pins and more I/O ports than PIC16F84A, which can fully meet the requirements of time-sharing display of the above traffic sign pattern.

  It should be noted that when we introduced C language programs in the previous serial articles, we used the 18-pin PIC16F84A microcontroller as an example. Through this example, you will see that as long as you are familiar with PIC16F84A, it will be easy to master the use of other multi-pin PIC microcontrollers.

  Since the output current of each bit of the 1:3 I/O terminal of the PIC microcontroller is limited, that is, ≤ 20mA, and the total output current of PORTA, PORTB and PORTE shall not be greater than 200mA, and the total output current of PORTC and PORTD shall not be greater than 200mA, and it can be seen from Figure 57 that the number of high-brightness LEDs connected to the PB0~PB7 ports and PC0 and PC1 ports of PORTB of the PIC16F877 microcontroller ranges from more than ten to dozens, so for all I/O ports with external high-brightness LEDs, we have added a power tube output drive connection 1:3 circuit, and the driving circuit is different depending on the number of external high-brightness LEDs (that is, different current sizes).

  (2) PIC16F877 port function bit allocation

  ① Manage the port position of the palm-shaped red highlighted LED indicator.

  Using the RB0 position of PIC16F877, a unidirectional thyristor SCR1 (2A) and multiple red high-brightness LEDs are connected externally (multiple LEDs are wired to form a hand pattern as shown in Figure 55a), and a static display mode is adopted. Usually, the hand pattern of a traffic light requires about 60 to 70 LEDs. In our design, the SCR1 circuit connected to the RB0 port can connect up to 100 high-brightness LEDs. It is enough to meet the design requirements. The RB1 position is connected to a PNP power transistor V1 (2A) and a current limiting resistor R0 and a bias resistor R1 to form a +24V switch circuit. The C program controls the RB0 port and RB1 to work synchronously and timingly in a 1:3 ratio. The conduction or cutoff of V1 controls whether to provide a +24V working voltage to SCR1, thereby achieving the purpose of timing the red high-brightness LED in the SCR1 circuit to light up or turn off.

  ② Manage the end 13 of the humanoid green high-brightness LED indicator light.

  Using the RB2 bit of PIC16F877, a unidirectional thyristor SCR2 (2A) and multiple red high-brightness LEDs are connected externally (multiple LEDs are wired to form a human-like figure as shown in Figure 55b), and a static display mode is adopted. It takes about 70 LEDs to form this figure. The RB3 bit is connected externally to a PNP power transistor V2 (2A) and resistors R2 and R3 to form a +24V switch circuit.

  The working mode of this circuit is exactly the same as the palm-shaped indicator light introduced earlier, so it will not be described here.

  ③ Manage the port position of the bicycle-shaped green high-brightness LED indicator light.

  By using RC0, RC1~RC7, externally connected NPN power transistors V5~V12 and several green high-brightness LEDs (through wiring to form a graphic that can control the dynamic display of a bicycle as shown in Figure 55c). When the circuit is working, by controlling the LEDs arranged on the bicycle wheels to light up and off in time, people can see an image that seems to be a bicycle rotating, so as to prompt people or non-motor vehicles to pass.

  ④ Manage the port position of the circular green highlighted LED.

  The one-way thyristor SCR3 and related circuits such as V3 connected to RB4 and RB5 are used to control the green high-brightness LED circular indicator light as shown in Figure 56 to prompt the passage of motor vehicles.

  ⑤ Manage the port position of the circular red highlighted LED.

  The one-way thyristor SCR4 and related circuits such as V4 connected to RB6 and RB7 are used to control the red high-brightness LED circular indicator light as shown in Figure 56 to indicate that motor vehicles are prohibited from passing.

  It should be noted that the circular pattern in Figure 56 is common to both red and green lights. When wiring, the red and green highlight LEDs should be arranged alternately, and the red and green LEDs can be controlled to display in time using a C language program.

  The operation of the above I/O ports is all controlled by software (C language program). The program controls the time-sharing operation of each high-brightness LED indicator pattern according to the specifications of each traffic intersection, so that pedestrians and vehicles at the traffic intersection can pass safely and orderly.

  2. C language program flow chart and C program

  According to the circuit shown in Figure 57, we can draw the C language program flow of the red and green lights in the straight direction of the urban traffic intersection as shown in Figure 58. The C language program flow of the red and green lights in the horizontal direction is the same. This flowchart can provide ideas for everyone to edit C language programs.

Fig.58

[page]

    The C program list for traffic light management at traffic intersections edited according to the process shown in Figure 58 is as follows (program name pic08.C):

[page]

  Note: The above traffic road 1:3 red and green light C program is the pattern of traffic lights observed by the author at the traffic intersection. The purpose of editing this program is to help everyone learn C language programming. For the delay function value in the program, readers can adjust it as needed to use it in other C programs as a delay function value that can change the time arbitrarily.

  It should be noted that the actual red and green light management system at traffic intersections is a red, green and yellow light engineering management system based on multiple intersections, which considers more and more complex issues than the procedures in this article.

Reference address:PIC microcontroller C language programming (13)

Previous article:PIC microcontroller C language programming (14)
Next article:PIC microcontroller C language programming (12)

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号