Description: This program is a simple Traffic Light Controller. Between the start time and end time, the system controls a traffic light with pedestrian self-service. Outside of this time range, the yellow caution lamp is blinking. The commands include displaying times, setting the clock time, start time, and end time.
The program includes several external functions for string and memory operations, initializing the serial UART, and managing various tasks such as initializing, handling commands, maintaining the clock, controlling the traffic lights, reading keys, and checking for escape characters. It employs a structure to record time, storing values for current time, start time, and end time. The traffic light system utilizes specific I/O pins for controlling the red, yellow, green, stop, and walk lamps, as well as a key input for pedestrian self-service.
The program initializes tasks for clock management, command processing, and light control, with a continuous loop for clock updates. The timing functions include checking for valid time inputs and handling errors in the input format.
The Traffic Light Controller is designed to operate within a defined schedule, managing the traffic lights and pedestrian signals appropriately. The system uses a time structure that includes hours, minutes, and seconds, allowing for precise control over the light sequences. The red, yellow, and green lamps are activated based on the current time in relation to the defined start and end times, while the yellow caution lamp operates outside of these hours.
The implementation of the clock task ensures that the current time is continuously updated, and any changes in time status are communicated to the command task. The program also includes mechanisms to read user input for setting times and managing the operation of the traffic lights. Error handling is incorporated to ensure that only valid time formats are accepted, enhancing the robustness of the system.
In summary, this Traffic Light Controller program effectively manages traffic signals and pedestrian requests based on a defined schedule, utilizing a structured approach to time management and user input. The system is designed for reliability and ease of use, ensuring safe and efficient traffic flow.This program is a simple Traffic Light Controller. Between start time and end time the system controls a traffic light with pedestrian self-service. Outside of this time range the yellow caution lamp is blinking. |
" "+ command -+ syntax -+ function -+
" "| Display | D | display times Time | T hh:mm:ss | set clock time Start | S hh:mm:ss | set start time End | E hh:mm:ss | set end time |
" "+-+-+-+
"; #include /* string and memory functions */ extern getline (char idata *, char); /* external function: input line */ extern serial_init (); /* external function: init serial UART */ #define INIT 0 /* task number of task: init */ #define COMMAND 1 /* task number of task: command */ #define CLOCK 2 /* task number of task: clock */ #define BLINKING 3 /* task number of task: blinking */ #define LIGHTS 4 /* task number of task: signal */ #define KEYREAD 5 /* task number of task: keyread */ #define GET_ESC 6 /* task number of task: get_escape */ struct time { /* structure of the time record */ unsigned char hour; /* hour */ unsigned char min; /* minute */ unsigned char sec; /* second */ }; struct time ctime = { 12, 0, 0 }; /* storage for clock time values */ struct time start = { 7, 30, 0 }; /* storage for start time values */ struct time end = { 18, 30, 0 }; /* storage for end time values */ sbit red = P12; /* I/O Pin: red lamp output */ sbit yellow = P11; /* I/O Pin: yellow lamp output */ sbit green = P10; /* I/O Pin: green lamp output */ sbit stop = P13; /* I/O Pin: stop lamp output */ sbit walk = P14; /* I/O Pin: walk lamp output */ sbit key = P15; /* I/O Pin: self-service key input */ char idata inline[16]; /* storage for command input line */ / <7465> */ /* Task 0 `init`: Initialize */ / <7465> */ void init (void) _task_ INIT { /* program execution starts here */ serial_init (); /* initialize the serial interface */ os_create_task (CLOCK); /* start clock task */ os_create_task (COMMAND); /* start command task */ os_create_task (LIGHTS); /* start lights task */ os_create_task (KEYREAD); /* start keyread task */ os_delete_task (INIT); /* stop init task (no longer needed) */ } bit display_time = 0; /* flag: signal cmd state display_time */ / <7465> */ /* Task 2 `clock` */ / <7465> */ void clock (void) _task_ CLOCK { while (1) { /* clock is an endless loop */ if (+ctime. sec = 60) { /* calculate the second */ ctime. sec = 0; if (+ctime. min = 60) { /* calculate the minute */ ctime. min = 0; if (+ctime. hour = 24) { /* calculate the hour */ ctime. hour = 0; } } } if (display_time) { /* if command_status = display_time */ os_send_signal (COMMAND); /* signal to task command: time changed */ } os_wait (K_IVL, 100, 0); /* wait interval: 1 second */ } } struct time rtime; /* temporary storage for entry time */ / <7465> */ /* readtime: convert line input to time values & store in rtime */ / <7465> */ bit readtime (char idata *buffer) { unsigned char args; /* number of arguments */ rtime.
sec = 0; /* preset second */ args = sscanf (buffer, "%bd:%bd:%bd", /* scan input line for */ &rtime. hour, /* hour, minute and second */ &rtime. min, &rtime. sec); if (rtime. hour > 23 | rtime. min > 59 | /* check for valid inputs */ rtime. sec > 59 | args < 2 | args = EOF) { printf ("
* ERROR: INVALID TIME FORMAT
"); return (0); } return (1); } #define ESC 0x1B /* ESCAPE character code */ bit escape; /* flag: mark ESCAPE character entered */ / <7465> */ /* Task 6 `get_escape`: check if ESC (escape character) was entered */ / <7465> */ void get_escape (void) _task_ GET_ESC { while (1) { /* endless loop */ if (_getkey () = ESC) escape = 1; /* set flag if ES
The SP6691 circuit is designed to provide a high output voltage using a lower voltage boost regulator by incorporating a charge pump circuit. This configuration can convert a standard 30V boost regulator into a 60V boost regulator if necessary. Testing...
Four way Traffic light controller which Has Red, Yellow and Green LEDS. It uses the AT89C2051.
The four-way traffic light controller is an essential electronic system designed to manage traffic flow at intersections by controlling the operation of Red, Yellow, and...
This article outlines the construction of a simple microcontroller-based delay circuit designed for photographic applications, such as drop or high-speed photography. It is capable of controlling the trigger lag for cameras and flash units, generating periodic trigger pulses, or managing...
Using a switch to power up your microcontroller projects may not be a good idea if you need to "wake" the PIC during some events. For example: A metal detector sends a pulse indicating a car is ready to enter...
The Tutorial shows how to interface 7-segment display to a microcontroller. Also explains how do display more than one 7-segment on same data lines using scanning method. 7 Seg displays are are basically 7 LED's. It will be much easier...
Introduction: Token Display Systems are ideal for banks, airports, public dealing offices, hospitals, doctors' clinics, restaurants, and other locations where people must wait in line. These systems allow customers to wait comfortably without standing in line; they only need to...
The system operates between 10 minutes to 2 hours, featuring a 100-line bell controlled by a multi-gear stick labeled S2 41f. The integrated circuit (IC) functions as a self-excited multivibrator. The device can manage binary pulses ranging from 3 to...
You must be able to recognise components such as capacitors, diodes, zeners, transistors and resistors to build a 5x7 Display project. This information is covered in our BASIC ELECTRONICS course and a complete set of circuit symbols can be found...
Turning electrical devices ON or OFF using a remote control is a well-established concept, with numerous devices available that perform this function effectively. To create such a device, it is necessary to construct a receiver and a transmitter, as well...
We use cookies to enhance your experience, analyze traffic, and (if you allow) serve personalized ads.
By clicking Accept All, you agree to our use of cookies.
Learn more