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 🔗 External reference
This receiver, designed around the popular ZN414 integrated circuit, operates within the AM band frequency range of 550 to 1600 KHz. For Longwave reception, it is necessary to replace the coil, which can be sourced from an old medium...
If you are searching for the 8255 datasheet, click here. Another project describing the 8255 interface to PC is here.
The 8255 Programmable Peripheral Interface (PPI) is an integrated circuit designed to facilitate communication between the microprocessor and peripheral devices....
This application note details the integration of a quad serial controller into the EB675001 Module. A multi-source quad Universal Asynchronous Receiver and Transmitter (UART), specifically the 16554 type, was chosen to facilitate component sourcing and implementation. The RS232 line...
The QM-NJ9 is an alcohol sensor that detects the presence of alcohol by measuring the resistance values between points A and B. When alcohol is detected, the resistance decreases, leading to an increase in potential at point B. As...
This project involves a GSM-based voting machine system that utilizes AT commands to send SMS through a microcontroller. It operates in two modes: Normal mode, where an authorized individual from a local area can cast their vote, and Security...
Most small portable radios require a 3-V supply, which is typically provided by two AA or AAA batteries. Many of these radios are equipped with a charger socket since rechargeable batteries are an option. When used in a stationary...
We use cookies to enhance your experience, analyze traffic, and serve personalized ads.
By clicking "Accept", you agree to our use of cookies.
Learn more