Microcontroller-based Traffic Light Controller. Faculty of Life Sciences & Computing. Communications Technology London Metropolitan University

Similar documents
e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interfacing External Devices using Embedded C Module No: CS/ES/22

8051 Peripherals. On-Chip Memory Timers Serial Port Interrupts. Computer Engineering Timers

1. Attempt any three of the following: 15

Lab 01 Arduino 程式設計實驗. Essential Arduino Programming and Digital Signal Process

C:\Users\Jacob Christ\Documents\MtSAC\ELEC74 Mt SAC - chipkit\homework Sheets.docx

Graphical LCD Display Datasheet EB

LABORATORY MANUAL Interfacing LCD 16x2, Keypad 4x4 and 7Segment Display to PIC18F4580

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR. ELECTRONICS & COMMUNICATION DEPARTMENT Question Bank- 1

C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipkit\homework Sheets.docx

NeoLoch. Inquisitor 4116 DRAM Blade Manual. Overview. Preliminary Release

Goal: We want to build an autonomous vehicle (robot)

ARM HOW-TO GUIDE Interfacing 7SEG with LPC2148 ARM

FPGA Discovery-III XC3S200 Board Manual

Finite State Machine Lab

Magic 8 Ball. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

Basic Input/Output Operations

P89V51RD2 Development Board May 2010

EE 231 Fall EE 231 Lab 3. Decoders and Multiplexers. Figure 1: 7-Segment Display. Memory: where the program is stored.

EE4380 Microprocessor Design Project

ONYX-MM-XT PC/104 Format Counter/Timer & Digital I/O Module

SLCD1-IC Serial LCD Processor

Figure 1.1: Some embedded device. In this course we shall learn microcontroller and FPGA based embedded system.

AC : INFRARED COMMUNICATIONS FOR CONTROLLING A ROBOT

Memory & Simple I/O Interfacing

Outline for Today. Lab Equipment & Procedures. Teaching Assistants. Announcements

ARM HOW-TO GUIDE Interfacing I2C-7SEG with LPC2148 ARM

Slick Line Acquisition System Manual

Mechatronics and Measurement. Lecturer:Dung-An Wang Lecture 6

8051 Intermidiate Development Board. Product Manual. Contents. 1) Overview 2) Features 3) Using the board 4) Troubleshooting and getting help

LCD. Configuration and Programming

RFID: Read and Display V2010. Version 1.1. Sept Cytron Technologies Sdn. Bhd.

Write LED display data, in accordance with the address from the display from low to high, from low to high data byte operation.

Fireloch 4 Digit 7 Segment Programmable Display Module

ISSI 25 Series EEPROM Application Note. 1. Introduction. 2. Power supply & power on reset

8051 Microcontroller

Mega128-DEVelopment Board Progressive Resources LLC 4105 Vincennes Road Indianapolis, IN (317) (317) FAX

Real Time Operating Systems Application Board Details

USB-4303 Specifications

MICROPROCESSORS A (17.383) Fall Lecture Outline

Chapter 9. Input/Output (I/O) Ports and Interfacing. Updated: 3/13/12

Mega128-Net Mega128-Net Mega128 AVR Boot Loader Mega128-Net

PROGRAMMABLE POWER SUPPLY

8051 Microcontroller Interrupts

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

The Arduino Briefing. The Arduino Briefing

Micro-Controllers. Module 2: Outputs Control and Inputs Monitoring. IAT Curriculum Unit PREPARED BY. August 2008

EECS 140 Laboratory Exercise 4 3-to-11 Counter Implementation

Rear Distance Detection with Ultrasonic Sensors Project Report

Manual iaq-engine Indoor Air Quality sensor

EECE 340 Introduction to Microprocessors w/lab Section A. Term Project Parking Visitor Counter

PICAXE DEVELOPMENT BOARD (AXE091)

7 8 9 C. PRELAB REQUIREMENTS You must adhere to the Lab Rules and Policies document for every lab.

PIC-I/O Multifunction I/O Controller

Futaba MDM166A display

DEV-1 HamStack Development Board

Programming (1.0hour)

Lecture Objectives. Introduction to Computing Chapter 0. Topics. Numbering Systems 04/09/2017

Designing Your Own Soft Modules

Bachelor of Engineering in Computer and Electronic Engineering

3.3V regulator. JA H-bridge. Doc: page 1 of 7

8051 Basic Development Board. Product Manual. Contents. 1) Overview 2) Features 3) Using the board 4) Troubleshooting and getting help

MicroTRAK 8051 Training & Project Kit User s Guide

Programmable Control. Name Class Teacher. Ellon Academy Technical Faculty

I/O handling. Purpose. Seven-segment displays. Digital Systems 15 hp

CEIBO FE-5111 Development System

MIFARE Secure OEM Reader Module Data Sheet

KNJN I2C bus development boards

ECE2049 Homework #2 The MSP430 Architecture & Basic Digital IO (DUE Friday 9/8/17 at 4 pm in class)

DESIGN AND IMPLEMENTATION OF A SPECTATOR COUNTING SYSTEM

HAND HELD PROGRAMMER QUICK START GUIDE

INTERFACING HARDWARE WITH MICROCONTROLLER

PVK40. User's manual. Feature Rich Development and Educational Kit for 40-pin Microchip PIC microcontrollers

JMY504M User's Manual

Experiment 4.A. Speed and Position Control. ECEN 2270 Electronics Design Laboratory 1

Freeduino USB 1.0. Arduino Compatible Development Board Starter Guide. 1. Overview

Module 003: Introduction to the Arduino/RedBoard

TRAFFIC LIGHT CONTROLLER

SECURE DIGITAL ACCESS SYSTEM USING IBUTTON

XC164CS Prototype Board

ISA Host Controller 15a Hardware Reference Release 1.2 (October 16, 2017)

S125 Multi-Purpose 125 KHz RFID Reader USER MANUAL. 9V/24V DC Operating Voltage, AC (optional) KHz RFID EM4100/2 Cards & Tags

External and Flash Memory

ARDUINO LEONARDO ETH Code: A000022

C Language Programming

EE 231 Fall EE 231 Lab 3

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

Easy Kit Board Manual

WINTER 14 EXAMINATION Subject Code: Model Answer Page No: 1/ 26

Display Real Time Clock (RTC) On LCD. Version 1.2. Aug Cytron Technologies Sdn. Bhd.

K191 3 Channel RGB LED Controller

EE 231 Fall Lab 2: Decoders and Multiplexers. Introduction

ECE 270 Lab Verification / Evaluation Form. Experiment 1

Lab 2 - Powering the Fubarino. Fubarino,, Intro to Serial, Functions and Variables

The Atmel ATmega328P Microcontroller

IME-100 Interdisciplinary Design and Manufacturing

FPGA Interfacing of HD44780 Based LCD Using Delayed Finite State Machine (FSM)

Introduction to 8051 microcontrollers

CDN503 HIGH DENSITY I/O ADAPTER USER GUIDE

Lab3: I/O Port Expansion

Transcription:

Faculty of Life Sciences & Computing Communications Technology LONDON NORTH CAMPUS Microcontroller-based Traffic Light Controller Submitted 26/04/13 in partial fulfilment of the requirements for the Embedded Systems CT5003 Olivier Zoude 10034346 / org0020@my.londonmet.ac.uk Faculty of Life Sciences & Computing Communications Technology London Metropolitan University I hereby declare that this report is all my own work, except as indicated in the text: Signature: Date: May 2013 Page 1 of 35

CT5003: Microprocessors & Embedded Systems Case Study Microcontroller-based Traffic Light Controller CONTENTS CASE STUDY REPORT: Microcontroller-based Traffic Light Controller 3. ABSTRACT.Page 3 3. INTRDUCTION..Page 3 3. SECTION 1: Preparatory Tasks...Page 4 4. SECTION 2: Case Study...Page 14 a) HARDWARE DEVELOPMENT..Page 15 TASK 1: pin configuration of main components..page15 TASK 2: Board layout and Schematic...Page18 b) SOFTWARE DEVELOPMENT..Page 22 FLOW CHART Page 22 C-PROGRAM.Page 23 EXPLANATION..Page 27 c) TESTING..Page 30 5. CONCLUSION.Page 35 6. REFERENCES Page 35 Page 2 of 35

1. ABSTRACT Traffic junctions are generally controlled by traffic lights controller. The function of traffic lights requires sophisticated control and accurate coordination to ensure that traffic moves as safely and smoothly as possible. Our case study is developed to meet the requirements of solid state traffic light controller by adopting microcontroller as the main controlling element, and led s as the indication of light. A microcontroller is interfaced to led s provide for centralized control of the traffic signals. Microcontroller is programmed in such a way to adjust their timing and phasing to meet changing traffic conditions. 2. INTRODUCTION Traffic lights are signaling devices positioned at road intersections, pedestrian crossings and other traffic locations to control competing flows of traffic. They assign the right of way to road users by the use of lights in standard colors (red - amber/yellow - green), using a universal color code. Design of an effective traffic light system in a modern city is a task of traffic engineers, and is an important undertaking. It has therefore always being a real concerns for traffic authorities in every country. Ever since Roman times, society has tried to control traffic. Even the fabled Roman road system created a conflict between pedestrian and equine travelers until the first traffic signal project was installed near Westminster Abbey in London, England in 1868. But J. P. Knight, project was having a safety issue and its implementation caused the death of a police officer. In our case study, Microcontroller-based Traffic Light Controller, composed respectively of two sections (Preparatory Tasks and Case Study) we will use the appropriate tools developed in the first section to implement a program in the second section, controlling the safety aspect of the traffic light board function, using C-program, compile it and debug it with compiler software (Ride) and then embed the program into the traffic light circuit board using tester software (Win loader) to effectively see the outcome of the C-program embedded into the microcontroller circuit board using a 7-segment display. Finally we will build the circuit board, base on the case study guideline, using appropriate software (Eagle) to emphasize in details on the components used to build the traffic light circuit board. 3. SECTION 1: Preparatory Tasks Page 3 of 35

The 7-Segment Display Module 4-Digits This module uses the M5450 Driver. The physical layout of this module is shown below: 4-Digits 7-Segment M5450 Enable Pin 1 Pin 3 Pin 5 Pin 7 Ground Pin 2 Pin 4 Pin 6 Pin 8 VCC=5V Data Clock RJ45 Connector Figure1. The Layout of the 4-Digit 7-Segment Module using the M5450 There is also a second version of this module where a 10-way straight connector is used instead of the RJ45. The pin configuration of this connector is shown above and in the posters in the laboratory. One of the microcontroller ports is connected to the 7-segment module via an interface board as shown below: Page 4 of 35

RJ45 Serial Port To Host Target Board DC Power RJ45 Straight Through Cable 7-Segment Display (M5450 Driver) Data Clock GND VCC D3 D2 D1 D0 Data Clock GND VCC Task 1: Using the data for the interfacing cards and the 7-segment display module (Displayed on the posters in the lab). We determine which port is the 7-Segment has been connected to via the RJ45 cable. We determine which pin of the M5450 is connected to pin 1 of the RJ45 in the 7-segment module. We write these in the table in the row for pin 1. We continue until all the 8-pins have been checked. Note that some of the pins may have no connection in one or either side. In this case simply enter NC for No Connection. Task 2: Figure2. Interfacing the 7-segment Module Note1: The module may be interfaced either via the RJ45 OR the 4-way connector Note2: Some Modules may also have the <Enable> pin as well. Task 2.1: From table 1, we enter the information in the definition part of the program Table 1 RJ45 Pins RJ45 in the RJ45 in the Interface Card 7-Segment Module 1 NC NC 2 P1.3 P1.2 3 NC NC 4 P1.1 P1.4 5 NC NC 6 P1.0 P1.6 Page 5 of 35

7 GND GND 8 VCC VCC Task 2.2: The function <void M5450_Delay (void)> is a very short delay of about 10 microseconds. We complete the function by writing the appropriate code. This is just an approximate. The skeleton of a typical C-program for microcontroller-based applications is shown below. /************************************************************************ * A Program for the 7-Segment Display Module * ************************************************************************* * Developed By: Olivier Zoude * ************************************************************************* * Date: 20/12/12 * * Module: CT5003 Microprocessor & Embedded Systems * *************************************************************************/ #include <reg51.h> #include <string.h> /* Declaration of the Data and Clock Bits for the M5450 */ sbit Data = P1^4 ; sbit Clock = P1^6 ; /* A very short Delay of about 10 microseconds */ void M5450_Delay(void) int i; for (i=0; i<10000; i++) ; /* The Main Program */ void main (void) /* Declaration of all local variables in the main part of the program */ M5450_Start(); for(;;) ; /* End of the main program */ Task 2.3: Questions Task 2.3(a): What is the purpose of #include <reg51.h>? Page 6 of 35

e -1 d-2 CA-3 C-4 DP-5 10-g 9-f 8-CA 7-a 6-b Answer: It is used to include a header-file for the registers (SFRs) in the source file Task 2.3(b): What is the purpose of < for(;;)> in the main program? Answer: The statements in the for loop repeat continuously for a specific number of times Task 3: To display a number or a letter, the program requires the 7-segment code for each digit from 0 to 9. Using figure 4 and the table provided, determine the 7-segment codes for digits 0 to 9 and complete the table. f g a b e d c D P Task 3.1: There are some limited numbers of characters that can also be displayed (e.g. H). We write down the codes for all alphabetical letters that we think may be displayed on a 7-segment display. Dec dp g f e d c b a Hex 0 0 0 1 1 1 1 1 1 0x3F 1 0 0 0 0 0 1 1 0 0x06 2 0 1 0 1 1 0 1 1 0x5B 3 0 1 0 0 1 1 1 1 0x4F 4 0 1 1 0 0 1 1 0 0x66 5 0 1 1 0 1 1 0 1 0x6D 6 0 1 1 1 1 1 0 0 0x7D 7 0 0 0 0 0 1 1 1 0x07 8 0 1 1 1 1 1 1 1 0x7F 9 0 1 1 0 1 1 1 1 0x6F Page 7 of 35

Figure 4 Task 3.2: The above 7-segment is assumed to be of Common-Anode type. The other type is Common-Cathode. What is the difference between the two types? - In common cathode type display, all the cathodes of the segments are tied together and connected to ground. The supply will be given to the required segment from the decoder or driver. - In common anode type display, the anodes of all the segments are tied together and connected to supply and the required segments will be connected to ground from the decoder or driver. Is M5450 suitable for both types? M5450 is not suitable for both type displays because when the power supply is ON all LEDs must be ON then the required segment will be connected to ground (OFF) from the decoder or driver. Task 4: Display 1234 on the module. This program displays 1234. The skeleton of a main program may be written as follows: /************************************************************************ * A Program for the 7-Segment Display Module * ************************************************************************* * Developed By: Olivier Zoude * Page 8 of 35

************************************************************************* * Date: 20/12/12 * * Module: CT5003 Microprocessor & Embedded Systems * *************************************************************************/ #include <reg51.h> #include <string.h> /* Declaration of the Data and Clock Bits for the M5450 */ sbit Data = P1^4 ; sbit Clock = P1^6 ; /* A very short Delay of about 10 microseconds */ void M5450_Delay(void) int i; for (i=0; i<10000; i++) ; void M5450_Pulse(void) /* This function sends a single clock pulse to the M5450 Driver */ Clock=0; Clock=1; M5450_Delay(); /* A short Delay */ Clock=0; void M5450_Send(unsigned char D) /* This function sends the 8-bit (byte) D to the M5450 in serial form */ /* with the least significant bit first */ unsigned char k; for (k=0; k<8; k++) B=D&0x01; if(b==0) Data=0; else Data = 1; D=D>>1; /* The following function sends a start pulse to the M5450 */ void M5450_Start(void) Data = 0; Data = 1; /* The Main Program */ void main (void) /* Declaration of all local variables in the main part of the program */ /* First Send a Start Pulse to the M5450 */ M5450_Start(); Page 9 of 35

for(;;) M5450_Send(0x66); M5450_Send(0x4F); M5450_Send(0x5B); M5450_Send(0x06); /* Send a further Three Clock Pulses to Complete the 35 Pulses */ /* End of the main program */ Task4 - Figure1 Task 5: A Simple Counter This program is a simple counter. The display should start with 0000 and count at a rate of every second until it reaches to 9999 where it rolls over to 0000 and repeats the counting sequence again. The skeleton for this task is shown below: /************************************************************************ * A Program for the 7-Segment Display Module * ************************************************************************* * Developed By: Olivier Zoude * ************************************************************************* * Date: 20/12/12 * * Module: CT5003 Microprocessor & Embedded Systems * *************************************************************************/ #include <reg51.h> #include <string.h> Page 10 of 35

/* Declaration of the Data and Clock Bits for the M5450 */ sbit Data = P1^4 ; sbit Clock = P1^6 ; void Delay(void); void M5450_Start(void); void M5450_Pulse(void); void M5450_Delay(void); void M5450_Send (unsigned char D); void M5450_Display(unsigned int D); void main (void) /* Declaration of all local variables in the main part of the program */ /* First Send a Start Pulse to the M5450 */ M5450_Start(); for(;;) unsigned int k; for( k = 0; k<9999; k++) M5450_Display(k); Delay(); /* A 1 Second Delay */ /* A very short Delay of about 10 microseconds */ /* This doesn t have to be accurate as explained in the lecture classes */ void M5450_Delay(void) int i; for (i=0; i<10000; i++) ; void Delay(void) int j,k; for (j=0; j<50; j++) for(k=0; k<10000; k++) ; /* This function sends a single clock pulse to the M5450 Driver */ void M5450_Pulse(void) Clock=0; Clock=1; M5450_Delay(); /* A short Delay */ Clock=0; Page 11 of 35

/* This function sends the 8-bit (byte) D to the M5450 in serial form */ /* with the least significant bit first */ void M5450_Send (unsigned char D) unsigned char k; for (k=0; k<8; k++) B=D&0x01; if(b==0) Data=0; else Data = 1; D=D>>1; /* The following function sends a start pulse to the M5450 */ void M5450_Start(void) Data = 0; Data = 1; /* this function to display 7-segment display. D is a 4 digit number from 0 to 9999 */ void M5450_Display(unsigned int D) unsigned int D3,D2,D1,D0,K,J,T0,T1,T2,T3; unsigned int Seg[ ] = 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F,0x6F; /* first the 4 digits are separated and assigned to D0, D1, D2, and D3 */ K=(int)(D/10); D0=D-K*10; J=(int) (K/10); D1=K-J*10; D3=(int) (J/10); D2=J-D3*10; /* Then each digit is converted to its seven-segment code using the lookup table method */ T0=Seg[D0]; T1=Seg[D1]; T2=Seg[D2]; T3=Seg[D3]; M5450_Start(); M5450_Send(T0); M5450_Send(T1); M5450_Send(T2); M5450_Send(T3); Page 12 of 35

/* End of the main program */ Task5 - Figure1 Task5 Figure2 Page 13 of 35

4. SECTION 2: Case Study We are required to design a microcontroller-based Traffic Light Controller. The constraints (what we must use ) are as follows: The unit: 1. We must use an 8051 microcontroller 2. We must use the available hardware modules: The 7-segment display and the traffic light modules. 3. All programs must be properly documented and have a corresponding flowchart (where appropriate). Figure 7. A simplified diagram of the traffic light junction Our Initial Task Our first task is to decide how the traffic light should operate in order to control the traffic in all directions. General points As already mentioned, our organization in the lab is an important part of this case study. Before we start the work, we MUST ensure that we are clear on how to use: Ride Development System to Enter, Compile, Debug, Simulate, Single Step a program written in C. Page 14 of 35

The down loader to download our HEX programs onto the Microcontroller Memory. We read the relevant lecture / tutorials from the lecture classes as well as the web site before attending the laboratory. a) HARDWARE DEVELOPMENT This phase of the project concerns: the design of the Microcontroller board. It involves designing the hardware on paper and design a PCB using the Eagle software. Task 1: Pin configuration of main components of developed circuit board. - Pin configuration of the microcontroller device Page 15 of 35

- The microcontroller Board other components To work with a 9v battery. This requires a small regulator An External SRAM (Static RAM) for external Data Storage pin configuration 9 pin D-con Serial Port using RS232 Protocol Page 16 of 35

Expansion port on the edge of the board for user s applications. Atmel s 2-Wire Serial EEPROM (AT24Cxx Series).RS232 Transceiver. A NAND gate. An inverter Page 17 of 35

. Some resistors. Some capacitors. Some diodes. Some resistors. Some GND and VCC A Crystal of 12MHz Task 2: Schematic and board layout (screen print) SCHEMATIC Page 18 of 35

Page 19 of 35

Page 20 of 35

BOARD LAYOUT (of the designed PCB) Page 21 of 35

Task 3: See logbook for drawing of entire circuit diagram for the entire board. b) SOFTWARE DEVELOPMENT FLOW CHART Page 22 of 35

C-PROGRAM (Software) /************************************************************************ * A Program for the 7-Segment Display Module * ************************************************************************* * Developed By: Olivier Zoude * ************************************************************************* * Date: 20/12/12 * * Module: CT5003 Microprocessor & Embedded Systems * *************************************************************************/ #include <reg51.h> #include <string.h> sbit Data = P1^4; sbit Clock = P1^6; sbit Pedestrian_Buzzer = P3^2; void M5450_Switch(void); void M5450_Start(void); void M5450_Pulse(void); void M5450_Delay(void); void Delay1 (void); void Delay2 (void); void M5450_Send(unsigned char D); void M5450_Display(unsigned int D); /* This main function regulates all traffic lights */ void main (void) // RS-NS = Road-Side North-South // RS-WE = Road-Side West-East unsigned int K; P3=0; for (;;) P3=0x84; /* Pin P3^7 and P3^2 are ON which is green from RS-NS and red from RS-WE */ for (K=10; K>0; K--) /* Decrement from 10 to 0 second */ M5450_Display(K);/* 7-segment displays count down from 10 to 0*/ Delay2();/* delay of 1.5 microsecond */ M5450_Display(0); P3=0x46;/* Pin P3^6, P3^2 and P3^1 are ON which is yellow from RS-NS and red, yellow from RS-WE */ Delay1();/* delay of 3 microsecond */ M5450_Display(0); P3=0x21; /* Pin P3^5 and P3^0 are ON which is red from RS-NS and green from RS-WE*/ for (K=10; K>0; K--)/* Decrement from 10 to 0 second */ Page 23 of 35

to 0*/ M5450_Display(K);/* 7-segment displays count down from 10 Delay2();/* delay of 1.5 microsecond */ M5450_Display(0); P3=0x62;/* Pin P3^6, P3^5 and P3^1 are ON which is yellow, red from RS-NS and yellow from RS-WE*/ Delay1();/* delay of 3 microsecond */ M5450_Display(0); P3=0x84; /* Pin P3^7 and P3^2 are ON which is green from RS-NS and red from RS-WE */ for (K=10; K>0; K--) /* Decrement from 10 to 0 second */ M5450_Display(K);/* 7-segment displays count down from 10 to 0*/ Delay2();/* delay of 1.5 microsecond */ M5450_Display(0); P3=0x44;/* Pin P3^6 and P3^2 are ON which is yellow from RS-NS and red from RS-WE*/ Delay1();/* delay of 3 microsecond */ M5450_Display(0); M5450_Switch();/* Pin P3^5, P3^4, P3^3 and P3^2 are ON which is red, amber from RS-NS and amber, red from RS-WE*/ for (K=15; K>0; K--)/* Decrement from 10 to 0 second */ M5450_Display(K);/* 7-segment displays count down from 15 to 0*/ Delay2();/* delay of 1.5 microsecond */ M5450_Display(0); P3=0x64;/* Pin P3^6, P3^5 and P3^2 are ON which is red from RS-NS and red, yellow from RS-WE*/ Delay1();/* delay of 3 microsecond */ /* This function would clear all green and yellow LEDs */ void M5450_Switch(void) Pedestrian_Buzzer = 1;/* pedestrian buzzer is pressed, amber light is ON */ P3 = 0x3C;/* red light on both roads RS-NS and RS-WE are ON for 15 seconds when pedestrian press buzzer and its amber light is ON */ /*This function sends a very short delay of 10 microseconds (us) */ void M5450_Delay(void) int i; for (i=0; i<10000; i++) Page 24 of 35

; /* This function sends 3 microseconds delay */ void Delay1 (void) int j,k; for (j=0; j<60; j++) for(k=0; k<20000; k++) ; /* This function sends 1.5 microseconds delay */ void Delay2 (void) int j,k; for (j=0; j<30; j++) for(k=0; k<20000; k++) ; /* This function sends a single clock pulse to the M5450 Driver */ void M5450_Pulse(void) Clock=0; Clock=1; M5450_Delay(); /*delay of 10 microseconds */ Clock=0; /* this function sends the 8 bit (byte) D to the M5450 in serial form, with the least significant bit first */ void M5450_Send(unsigned char D) unsigned char B,i; for (i=0; i<8; i++) B=D&0x01; if (B == 0) Data=0; else Data=1; D=D>>1; /* This function sends a start pulse to The M5450 */ void M5450_Start(void) Page 25 of 35

Data =0 ; Data =1 ; /* this function to display 7-segment display. D is a 4 digit number from 0000 to 9999 */ void M5450_Display(unsigned int D) unsigned char D3,D2,D1,D0,K,J,T0,T1,T2,T3; unsigned char Seg[ ] = 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F,0x6F; /* first we separate the 4 digits and assign them to D0,D1,D2, and D3 */ K=(int)(D/10); D0=D-K*10; J=(int) (K/10); D1=K-J*10; D3=(int) (J/10); D2=J-D3*10; /* Then we convert each digit to its seven-segment code using the lookup table method */ T0=Seg[D0]; T1=Seg[D1]; T2=Seg[D2]; T3=Seg[D3]; M5450_Start(); M5450_Send(T0); M5450_Send(T1); M5450_Send(T2); M5450_Send(T3); /* End of program */ Page 26 of 35

EXPLANATION (Using program description language: PDL) 1 - Main program Start Set port 3 (P3) to 0 Do forever Set P3 to 0x84 Decrement count (converted data) from 10 to 0 Call Function M5450_Display to display count Call Function Delay2 to delay for 1.5 microseconds Set function M5450_Display to 0 Set P3 to 0x46 Call Function delay1 to delay P3 for 3 microseconds Set function M5450_Display to 0 Set P3 to 0x21 Decrement count (converted data) from 10 to 0 Call Function M5450_Display to display count Call Function Delay2 to delay P3 for 1.5 microseconds Set function M5450_Display to 0 Set P3 to 0x62 Call Function Delay1 to delay P3 for 3 microseconds Set function M5450_Display to 0 Set P3 to 0x84 Decrement count (converted data) from 10 to 0 Call Function M5450_Display to display count Call Function Delay2 to delay P3 for 1.5 microseconds Set function M5450_Display to 0 Set P3 to 0x44 Call Function Delay1 to delay P3 for 3 microseconds Set function M5450_Display to 0 Call Function M5450_Switch Page 27 of 35

Decrement count (converted data) from 15 to 0 Call Function M5450_Display to display count Call Function Delay2 to delay for P3 for 1.5 microseconds Set function M5450_Display to 0 Set P3 to 0x64 EndDo Call Function Delay1 to delay P3 for 3 microseconds End 2 Function M5450_Display Input: Digit value Output: None Start End Convert data into 4 decimal digits Set T0 to decimal digit D0 Set T1 to decimal digit D1 Set T2 to decimal digit D2 Set T3 to decimal digit D3 Call Function M5450_Start to set data Call Function M5450_Send to send T0 Call Function M5450_Send to send T1 Call Function M5450_Send to send T2 Call Function M5450_Send to send T3 Call Function M5450_Pulse to set clock Call Function M5450_Pulse to set clock Call Function M5450_Pulse to set clock 3 Function M5450_Start Input: None Output: None Start Page 28 of 35

End Set data to 0 Call Function M5450_Pulse to set clock Set data to 1 Call Function M5450_Pulse to set clock 4 Function M5450_Pulse Input: None Output: None Start End Set clock to 0 Set clock to 1 Call Function M5450_Delay to delay clock for 10 microseconds Set clock to 0 5 Function M5450_Delay Input: None Output: None Start End Delay of 10 microseconds 6 Function M5450_Send Input: Digit value Output: None Start Get bit map of the digit to be sent Increment the bit to 8 Get top bit of the bit pattern If top bit is set to 0 then Send 0 to data input Else Send 1 to data input EndIf Page 29 of 35

End Call function M5450_Pulse to set clock Shift bit map right by 1 bit 7 Function Delay2 Input: None Output: None Start End Delay of 1.5 microseconds 8 Function Delay1 Input: None Output: None Start End Delay of 3 microseconds 9 Function M5450_Switch Input: None Output: None Start End Set Pedestrian_Buzzer port pin P3^2 to 1 Set Port 3 (P3) to 0x3C c) TESTING From the Lab, the C program above was successfully tested end the results are as below for evidence. Page 30 of 35

NB: LEDs green, yellow and red are for traffic light and LEDs amber are for pedestrian buzzer on both roads side (RS-NS and RS-WE). Port 3 P3^7 P3^6 P3^5 P3^4 P3^3 P3^2 P3^1 P3^0 GREEN YELLOW RED AMBER AMBER RED YELLOW GREEN For P3 = 0x84: Pin P3^7 and P3^2 of port 3 are ON which is green from RS-NS and red from RS-WE. 7-Segment display counts down from 10 to 0. Page 31 of 35

For P3 = 0x46: Pin P3^6, P3^2 and P3^1 of port 3 are ON which is yellow from RS-NS and red, yellow from RS-WE. For P3 = 0x21: Pin P3^5 and P3^0 of port 3 are ON which is red from RS-NS and green from RS-WE. 7-Segment display counts down from 10 to 0. Page 32 of 35

For P3 = 0x62: Pin P3^6, P3^5 and P3^1 of port 3 are ON which is yellow, red from RS-NS and yellow from RS-WE. For P3 = 0x44: Pin P3^6 and P3^2 of port 3 are ON which is yellow from RS-NS and red from RS-WE. Page 33 of 35

Calling M5450_Switch (): Pin P3^5, P3^4, P3^3 and P3^2 of port 3 are ON which is red, amber from RS-NS and red, amber from RS-WE. 7-Segment display counts down from 15 to 0. For P3 = 0x64: Pin P3^6, P3^5 and P3^2 of port 3 are ON which is red from RS- NS and red, yellow from RS-WE Page 34 of 35

5. CONCLUSION In this Case Study we have studied the importance of embedded system in real life by implementing the optimization of Microcontroller-based Traffic Light Controller to reduce the possibility of traffic jams and improve the safety issues surrounding major traffics by applying accurate timing and delay over traffic light sequences. But this case study outcome can be enhanced in such way as to control automatically the signals depending on the traffic density on the roads using sensors like infrared (IR) detector/receiver module extended with automatic turn off when no vehicles are running on any side of the road which helps in power consumption saving. 6. REFERENCES Common anode common cathode image http://arduinoexplained.blogspot.co.uk/2012_04_01_archive.html Intelligent traffic light and density control using IR sensor and microcontroller pdf http://www.ijater.com/files/ijater_03_06.pdf. Microcontroller Projects in C for the 8051 Dogan Hibrahim (2000). Microcontroller Projects in C for the 805. Tyeset by David Gregson associates, Beccles, Suffolk. Printed and Bound in Great Britain. (page: 57 to 62) http://www4.hcmut.edu.vn/~bmthanh/vixuly/microcontroller%20projects%20in%20c%2 0for%20the%208051.pdf. MINI-MAX/51-C2 PDF from module Tutorial document http://www.bipom.com/documents/brochures/minimax51c2.pdf. MINI-MAX/908-C PDF http://www.bipom.com/documents/boards/minimax908c.pdf. Development of a traffic light control system PDF http://umpir.ump.edu.my/75/1/cd2636.pdf. Page 35 of 35