RTX51 Tiny User's Guide

Traffic Example

The TRAFFIC example is a pedestrian traffic light controller. It is much more complex than the RTX_EX1 and RTX_EX2 examples and cannot be easily implemented without a multitasking real-time operating system like RTX51 Tiny.

TRAFFIC is a time-controlled traffic light controller that operates during a user-defined clock time period. Outside this period, the yellow light flashes. If a pedestrian presses the request button, the traffic light goes immediately into a "walk" state. Otherwise, the traffic light works continuously.

Traffic Light Controller Commands

You can communicate with the traffic light controller via the serial port interface of the 8051. You can use the Serial Window of the debugger to test the traffic light controller commands.

The serial commands that are available are listed in the following table. These commands are composed of ASCII text characters. All commands must be terminated with a carriage return.

CommandSerial TextDescription
DisplayDDisplay clock, start, and ending times.
TimeT hh:mm:ssSet the current time in 24-hour format.
StartS hh:mm:ssSet the starting time in 24-hour format. The traffic light controller operates normally between the start and end times. utside these times, the yellow light flashes.
EndE hh:mm:ssSet the ending time in 24-hour format.

Source Files

The TRAFFIC application is composed of three source files that are found in the \KEIL\C51\RTXTINY2\EXAMPLES\TRAFFIC\ folder.

  • TRAFFIC.C contains the traffic light controller program which is divided into the following tasks:
    • Task 0 Initialize: initializes the serial interface and starts all other tasks. Task 0 deletes itself since initialization is only needed once.
    • Task 1 Command: is the command processor for the traffic light controller. This task controls and processes serial commands received.
    • Task 2 Clock: controls the time clock.
    • Task 3 Blinking: flashes the yellow light when the clock time is outside the active time range.
    • Task 4 Lights: controls the traffic light phases while the clock time is in the active time range (between the start and end times).
    • Task 5 Button: reads the pedestrian push button and sends signals to the lights task.
    • Task 6 Quit: checks for an ESC character in the serial stream. If one is encountered, this task terminates a previously specified display command.
  • SERIAL.C implements an interrupt driven serial interface. This file contains the functions putchar and getkey. The high-level I/O functions printf and getline call these basic I/O routines. The traffic light application will also operate without using interrupt driven serial I/O. but will not perform as well.
  • GETLINE.C is the command line editor for characters received from the serial port. This source file is also used by the MEASURE application.

To build TRAFFIC using µVision...

  1. Load the TRAFFIC.UV2 project in the µVision IDE.
  2. Build Target ButtonSelect Project — Build Target to compile and link TRAFFIC.

Once the TRAFFIC program is compiled and linked, you may test it using the µVision Debugger.