0% found this document useful (0 votes)
11 views29 pages

Traffic Control System EG6142

Design software to demonstrate the features of the traffic-board o This can include: 7-segment display; traffic-signal LED’s; pedestrian button and associated LEDs; running-traffic LEDs.  Implement the design using ‘C’ code. o Document the code carefully, and demonstrate it.

Uploaded by

naseer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views29 pages

Traffic Control System EG6142

Design software to demonstrate the features of the traffic-board o This can include: 7-segment display; traffic-signal LED’s; pedestrian button and associated LEDs; running-traffic LEDs.  Implement the design using ‘C’ code. o Document the code carefully, and demonstrate it.

Uploaded by

naseer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

SCHOOL OF ARCHITECTURE, COMPUTING, &

ENGINEERING

February 2016

Name: Naseer Ahmed


Student Number: u1060363
Module Title: DSP & Embedded Systems
Module Code: EG6142
Assignment Title: Traffic Control System
Module Leader: Nic Snailum
Submission Date: 06/02/2016

3|Page
Table of Contents
1. Question Paper……………………………………..…………..….....................…...........5

2. Hardware Demonstrator....................................................................................................6

3. Task......................................................................................................................................7

4. Marking Criteria........………………...........……..................……………......…………..7

5. Summary............................….………………….....................…………………………...8

6. Introduction........................................................................................................................8

7. Specifications.................……………….....................……………………………………8

8. State Event Action.....................………………………..................……………………..10

9. State Transition Diagram......................................…………………………………..….13

10. Full Traffic Light Flow Chart....……….......................……………………………..….15

11. Avenue ON & Stopping Flow Chart....………………......................………………….16

12. High St ON & Stopping flow Chart................................................................................17

13. Pedestrian 1 ON & Stopping flow Chart.........................................................................18

14. Pedestrian 2 ON & Stopping flow Chart.........................................................................19

15. Code..........................................…………..........……......................………….……..…...20

16. Conclusion.........................................................................................................................30

17. Reference.....................................………………….….....................…………………....31

18. Bibliography............……………………..............……………………………................31
4|Page
School of Architecture,
Computing and Engineering

Student:
Module: DSP+Embedded Systems EG6142
Semester: A Year: 3
Lecturer: N. Snailum Academic Year: 2016/17
Assignment: Assignment 1 Submission Date:

Aspect of Work Max 1st 2nd Comments


Mark Mark

Software Design (Flowchart/State 50


Diagram etc.)

Software (‘C’ code including 50


comments.)

Total 100

Student Comments

Lecturer Comments

2nd marker Comments

Date:

5|Page
School of Architecture,
Computing and Engineering

Assignment 1 Specification

A prototype hardware demonstrator has been designed, built and tested.

Using a test-program, the hardware (illustrated in figure 1) appears to work! The


test-program is provided which illustrates, using the ‘C’ language, how many of
the various feature of the demonstrator board may be driven.

A more realistic demonstrator is now required.

Figure 1 Traffic Light Demonstrator Hardware

Tasks

 Design software to demonstrate the features of the traffic-board

o This can include: 7-segment display; traffic-signal LED’s; pedestrian


button and associated LEDs; running-traffic LEDs.

 Implement the design using ‘C’ code.

6|Page
o Document the code carefully, and demonstrate it.

Marking Criteria: This assignment will be marked with consideration to the following:

Completeness: The number of traffic-board features demonstrated Correctness:

Accuracy of task design, execution and demonstration Consistency: Consistent

approach in design, implementation and documentation

Professionalism: Word processed, easy to read, easy to understand and structured in a


professional manner.

The laboratorial hardware used for traffic light code to be run, has been shown in figure 2.
The vertical LEDs representing traffic flow on High Street. On other hand the horizontal
LEDs representing the traffic flow on Avenue. LED 14, 15 and 16 are traffic lights for
Avenue and LED 17, 18, 19 are traffic lights for High Street. LED 20 and 21 represents
traffic lights for Pedestrian Crossing.

Figure 2: Laboratorial Traffic Light Hardware

7|Page
Summary:
The purpose of this assignment is to create a SEA table, State
Transition Diagram (STD) and Flow Chart, and then to build a programme code for traffic
lights. In this particular assignment, the implementation of the software design and working
principals of U.K traffic lights will be examined, studied and software will be built to display
a simulation of the traffic lights controlling two roads and a pedestrian crossing. The code
will be written in C language and run in PIC micro controller.

Introduction:
With the invention of automobile, where it made human’s life very easy,
also it became essential to have a proper and smooth system for automobile users. Accidents
on the roads and traffic jams were the two biggest problems faced by automobile users. To
overcome these problems traffic light’s idea was proposed. In order to reduce accidents and
fasten the flow of cars on the roads, traffic lights were designed to regulate and smooth the
traffic. Good care should be taken in consideration when writing software for traffic lights, a
small logic mistake can cause serious accident and/or heavy congestion on the roads.
This report will show the making of a SEA table, STD, Flow Chart and a programme code
for traffic lights.

This code will be implemented on microcontroller then. The microcontroller used for the
project in this assignment is PIC18F7J11. And it falls in Mid-Range 8-bit MCUs category
and has 20 pins with a flash memory of 4096 words.. The compiler used in the project to
programme the microchip is MPLABX and the hardware is Pickit3 (Ahmed, 2015).

This assignment is about a traffic lights. The assignment is to build the hardware with
PIC18F7J11 microchip. By using PIC18F7J11 microchip a hardware circuit to be built on
breadboard and the Pickit programme has to be used to download code in to PIC18F7J11
microcontroller.

Specifications:
Once the traffic lights board powered on, all lights on the board will turn on for 3 seconds.
After that the normal traffic light system will start work until the power is on. In the traffic
light system, first of all the Avenue green light will show up and red lights for High St and
Pedestrian crossing will show up. At this stage the traffic at avenue will flow smoothly for

8|Page
few seconds, in software this has been addressed by the completion of 4 loops of leds (on/off
in sequence) on Avenue. After traffic has finished flowing (4 loops complete), traffic light on
Avenue will turn amber and traffic will stop. On the same time red and amber lights on High
Street will turn on, all three lights will stay on for 2 seconds and then Avenue light will
change to red and High Street light will change to green.

If the Pedestrian button (RB0) is pressed while Avenue traffic is flowing, it will wait for the
Avenue traffic to complete its loop before the transition of lights occurs. Once the Avenue
traffic flow loop completed then the traffic light on Avenue will turn amber and traffic will
stop, it will stay amber for two seconds. On the same time Pedestrian crossing’s green light
will turn on, but no change for High Street light it will stay red.

After the green light on pedestrian crossing turns on, seven segment displays will start
displaying countdown on the screen. Pedestrians can start walking until countdown completes
and a warning ‘S’ shows on Seven Segment display to warn the pedestrians to stop walking.

The same procedure will repeat if pedestrian button (RB0) is pressed while High Street traffic
is flowing. The only difference is the lights changes, in this case the traffic light on High
Street will turn amber and traffic will stop, it will stay amber for two seconds. On the same
time Pedestrian crossing’s green light will turn on, but no change for Avenue light it will stay
red.

If the pedestrian button was pressed while Avenue traffic was flowing then, High Street
traffic will start, after the completion of the pedestrian countdown. And if the pedestrian
button was pressed while High Street traffic was flowing then, Avenue traffic will start, after
the completion of the pedestrian countdown.

If the pedestrian button was pressed while High Street traffic was flowing then after the
completion of pedestrian countdown and the warning sign of ‘S’ showed up, pedestrian’s red
light will turn on which will stay on. The Avenue’s amber and red light will also turn on
which will stay on for 2 second and then turn off and the green light on Avenue will show up
and the traffic on Avenue will to start. High Street light will stay red for this whole period.

Similar happens if the pedestrian button was pressed while Avenue traffic was flowing. The
only difference is the transition of traffic lights on High Street. Once it completes then traffic
on High Street will start. In this case Avenue’s red light will stay on for this whole period.

9|Page
State Event Action:
Designing a program or writing a code for software, before
starting writing any code it is important to think about and plan its structure. Therefore SEA
(State Event Action), STD (State Transition Diagram) and Flow Chart are the useful tools to
make the program easy to understand. It is good practice to spend some time and plan about
that program by writing S.E.A (State Event Action) table and Flow Chart in first stage. In this
report we need to write SEA, STD, and Flow Chart for Traffic Light System. First of all we
need a SEA table. A SEA table for this purpose can be seen in table 1. The whole program
has been divided in few states and according to that, events and actions are allocated to them.

Table 1: SEA Table for Traffic Lights


STATE EVENT Action
Power on Go to Initialise
Initialise All Leds on
5 seconds elapsed Go to Avenue
Avenue Av green light on
High St red light on
Pedestrian red light on
0.4 seconds elapsed Led 08 turns on
0.8 seconds elapsed Led 08 to 09
0.12 seconds elapsed Led 09 to 10
0.16 seconds elapsed Led 10 to 04
0.20 seconds elapsed Led 04 to 11
0.24 seconds elapsed Led 11 to 12
0.28 seconds elapsed Led 12 to 13
4 loops elapsed Go to Avenue Stop
4 loops elapsed & Button 1 Go to Pedestrian 1
pressed

Avenue Stop Av green to amber


High St red & amber on
Pedestrian red light on

10 | P a g e
2 seconds elapsed Go to High St

High St High St green light on


Av red light on
Pedestrian red light on
0.4 seconds elapsed Led 01 turns on
0.8 seconds elapsed Led 01 to 02
0.12 seconds elapsed Led 02 to 03
0.16 seconds elapsed Led 03 to 04
0.20 seconds elapsed Led 04 to 05
0.24 seconds elapsed Led 05 to 06

0.28 seconds elapsed Led 06 to 07

4 loops elapsed Go to High St Stop


4 loops elapsed & Button 1 Go to Pedestrian 2 Crossing
pressed

High St green to amber


High St Stop Avenue red & amber on
Pedestrian red on
2 seconds elapsed Go to Avenue
Pedestrian 1 Avenue amber on
High St red on
Pedestrian red on
2 seconds elapsed Pedestrian green on
Avenue red on
High St red on
3 seconds elapsed ‘P’ displays on Seven Segment
4 seconds elapsed Seven Segment off
5 seconds elapsed ‘P’ displays on Seven Segment

11 | P a g e
6 seconds elapsed ‘A’ displays on Seven Segment
7 seconds elapsed ‘9’ displays on Seven Segment
8 seconds elapsed ‘8’ displays on Seven Segment
9 seconds elapsed ‘7’ displays on Seven Segment
10 seconds elapsed ‘6’ displays on Seven Segment
11 seconds elapsed ‘5’ displays on Seven Segment
12 seconds elapsed ‘4’ displays on Seven Segment

13 seconds elapsed ‘3’ displays on Seven Segment


14 seconds elapsed ‘2’ displays on Seven Segment
15 seconds elapsed ‘1’ displays on Seven Segment
16 seconds elapsed ‘0’ displays on Seven Segment
17 seconds elapsed ‘S’ displays on Seven Segment
18 seconds elapsed Seven Segment display off
17 seconds elapsed ‘S’ displays on Seven Segment
18 seconds elapsed Seven Segment display off
19 seconds elapsed ‘S’ displays on Seven Segment
20 seconds elapsed Go to Pedestrian 1 Stop
Pedestrian 1 Stop Pedestrian red on
Avenue red on
High St amber & red on
2 seconds elapsed Go to High St
Pedestrian 2 Avenue red on
High St amber on
Pedestrian red on
2 seconds elapsed Pedestrian green on
Avenue red on
High St red on
3 seconds elapsed ‘P’ displays on Seven Segment
4 seconds elapsed Seven Segment off
5 seconds elapsed ‘P’ displays on Seven Segment

12 | P a g e
6 seconds elapsed ‘A’ displays on Seven Segment
7 seconds elapsed ‘9’ displays on Seven Segment
8 seconds elapsed ‘8’ displays on Seven Segment
9 seconds elapsed ‘7’ displays on Seven Segment
10 seconds elapsed ‘6’ displays on Seven Segment
11 seconds elapsed ‘5’ displays on Seven Segment
12 seconds elapsed ‘4’ displays on Seven Segment
13 seconds elapsed ‘3’ displays on Seven Segment
14 seconds elapsed ‘2’ displays on Seven Segment
15 seconds elapsed ‘1’ displays on Seven Segment
16 seconds elapsed ‘0’ displays on Seven Segment
17 seconds elapsed ‘S’ displays on Seven Segment
18 seconds elapsed Seven Segment display off
19 seconds elapsed ‘S’ displays on Seven Segment
20 seconds elapsed Go to Pedestrian 2 Stop
Pedestrian 2 Stop Pedestrian red on
Avenue amber & red on
High St red on
2 seconds elapsed Go to Avenue

State Transition Diagram:


State transition diagrams have been used right from the
beginning in object-oriented modeling. The basic idea is to define a machine that has a
number of states (hence the term finite state machine). The machine receives events from the
outside world, and each event can cause the machine to transition from one state to
another. (State transition diagrams, 2016)
State Transition Diagram is a kind of flow chart but with less details compare to flow chart,
and more focusing the events which makes a transition of one state to another. Flow chart
mainly deals with events and actions on other hand STD describes each state and the
elements which changes that state. A State Transition Diagram for traffic lights has been
given in Figure 3.

13 | P a g e
Power on
Go to Initialise High St Traffic Flow Stop

Initialise

All Leds ON

4 loops elapsed
5 seconds elapsed 2 seconds elapsed
Go to High St Stop
Go to Avenue ON Go to Avenue ON

Avenue Traffic
High St Traffic
Flow ON 4 loops elapsed 2 seconds elapsed
Avenue Traffic Flow ON
Go to Ave Stop Flow Stop Go to High St ON

4 loops elapsed &


Button 1 pressed
Button 1 Pressed
& 4 loops elapsed Go to Pedestrian 2

Go to Pedestrian 1

Pedestrian 2 ON
Pedestrian 1 ON

Countdown Start
Countdown Start
2 seconds elapsed

Go to High St ON
Countdown Stopped
2 seconds elapsed
Countdown Stopped
Go to Pedestrian 2 Stop
Go to Avenue ON
Go to Pedestrian 1 Stop

Pedestrian 1 Stop Pedestrian 2 Stop

Figure 1:
3 State Transition Diagram for Traffic Lights

14 | P a g e
Full Traffic Light Flow Chart: In order to avoid hassle Flow Charts are created to give a better
understanding of the programme without reading the code and it also helps the client or other people to
understand who are not able to understand programming language. The Flow chart of the game is as follows.

YES

NO

NO YES

15 | P a g e
Avenue ON & Stopping Flow Chart

NO

YES

NO YES

16 | P a g e
High St ON & Stopping Flow Chart

NO

YES

NO YES

17 | P a g e
Pedestrian 1 Crossing & Stopping Flow Chart

NO

YES

18 | P a g e
Pedestrian 2 Crossing & Stopping Flow Chart

NO

YES

19 | P a g e
Code:
And the final outcome of the whole assignment is this precious code which took a lot of
value able time and effort to be written down in this form. This is a complete code and tested on
the traffic light hardware in laboratory. All the functionalities in this code have been explained in
comment’s section.
/*
* File: main.c
* Author: Naseer Ahmed
*
* Demonstrates some of the traffic board features
* version H
* 06/02/ 2017
*/

#include <stdio.h>
#include <stdlib.h>
#include <p18f87j11.h>
#include <xc.h>
#include "config.h"
#include "lcdE.h"
#include "SPI_trafficE.h"

extern void Delay10KTCYx(unsigned char);

typedef enum { Avenue, AveStop, HighST, HighStop, Pedestrian1, Pedestrian2,


PedestrianStop1, PedestrianStop2 } stateMachine;
stateMachine simpleState = Avenue; //initialise statemachine

int buttonOneInt, count, count1, count2, count3, count4, count5;


unsigned char SPI1A_data, SPI1B_data, SPI2A_data, SPI2B_data;

void Initialise(void)
{
// some of this not required for demo
// configure ADC
WDTCONbits.ADSHR = 1;
ANCON0 = 0xFF;
ANCON1 = 0xFE; //make RA0 analog input
WDTCONbits.ADSHR = 0;
ADCON0 = 0;
ADCON0bits.ADON = 1;
ADCON1 = 0b00111010;

TXSTA = 0xA4; // configure USART


SPBRG = 255;
RCSTA = 0x90;

TRISD = 0x00; // configure LED

TRISB = 1; // configure switches


TRISA = 0x20;
//SPI CS as outputs
SPI1_CS_TRIS = 0; //A4
SPI1_CS = 1; //INACTIVE
SPI2_CS_TRIS = 0; //a3
SPI2_CS = 1; //INACTIVE

//configure LCD

20 | P a g e
LCDInit();
InitSPI();

//initialise SPI(traffic)
SPI1A_data = 0x00; //all on for testing
SPI1B_data = 0x00; //all on for testing
InitPortA_SPI1();
InitPortB_SPI1();
WritePortA_SPI1(SPI1A_data);
WritePortB_SPI1(SPI1B_data);

SPI2A_data = 0x00; //off //all on for testing


SPI2B_data = 0x00; //off //all on for testing
InitPortA_SPI2();
InitPortB_SPI2();
WritePortA_SPI2(SPI2A_data);
WritePortB_SPI2(SPI2B_data);

ADRESH = 0;

void Delay(void) // minimum 15ms


{
Delay10KTCYx(25);
Delay10KTCYx(25);
Delay10KTCYx(25);
return;
}
void SDelay(void) // minimum 5ms
{
Delay10KTCYx(10);
}
void twentysecdelay(){
Delay10KTCYx(100);
Delay10KTCYx(100);
Delay10KTCYx(100);
Delay10KTCYx(100);

void interrupt low_priority CheckButtonPressed()


{
//check if the interrupt is caused by the pin RB0
if (INTCONbits.INT0IF == 1)
{
buttonOneInt = 1;
INTCONbits.INT0IF = 0;
}

//variables
int secs;
int button2;
int Button1;
int WRONGPIN;
unsigned short long i;
char d[] = " Avenue Flow ON ";
char b[] = " High St Flow ON ";
char d1[] = "Avenue Flow STOP ";
char b1[] = "HighSt Flow Stop ";
char P[] = "Pedestrian Walk ";
char P1[] = "Pedestrian Stop ";

21 | P a g e
char test[] = "No Smocking.... ";
char syst[] = "U.K Light System ";

void main(void){

Initialise();
LCDClear();

for (i = 0; i<16; i++)


d_write(syst[i]); //write Message on LCD
LCDLine_2();
for (i = 0; i<16; i++)
d_write(test[i]); //write Message on LCD

count = 0;

while (1)
{
PORTD = count;
count++;
Delay10KTCYx(20); // delay

switch (simpleState)
{

case Avenue: //state = Avenue

LCDClear(); //LCD = clear


for (i = 0; i<16; i++)
d_write(d[i]); //LCD = Avenue Flow ON

SPI2A_data = 0x88; // indicate A


WritePortA_SPI2(SPI2A_data);

SPI1B_data = 0xF8; // LED 1, 2 & 3 ON


WritePortB_SPI1(SPI1B_data);

for (count1 = 0; count1<5; count1++)

SPI2B_data = 0xB3; // LED 16,17,20 ON (Avenue =


Green Rest is Red)
WritePortB_SPI2(SPI2B_data);
Delay10KTCYx(100);
SPI1A_data = 0xFE; // LED 08 (Indicates flow of
Traffic on Avenue)
WritePortA_SPI1(SPI1A_data);
Delay10KTCYx(100);
SPI1A_data = 0xFD; // LED 09 (Indicates flow of
Traffic on Avenue)
WritePortA_SPI1(SPI1A_data);
Delay10KTCYx(100);
SPI1A_data = 0xFB; // LED 10 (Indicates flow of
Traffic on Avenue)
WritePortA_SPI1(SPI1A_data);
Delay10KTCYx(100);

22 | P a g e
SPI1A_data = 0xFF; // LED 10 (necessary to show
the flow of traffic)
WritePortA_SPI1(SPI1A_data);
SPI1B_data = 0xF0; // LED 1,2,3,4 (necessary to
show the flow of traffic)
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(100);
SPI1B_data = 0xFF; // LED 04 OFF (necessary to
show the flow of traffic)
WritePortB_SPI1(SPI1B_data);
SPI1B_data = 0xF8; // LED 1,2,3 (necessary to
show the flow of traffic)
WritePortB_SPI1(SPI1B_data);
SPI1A_data = 0xF7; // LED 11 (Indicates flow of
Traffic)
WritePortA_SPI1(SPI1A_data);
Delay10KTCYx(100);
SPI1A_data = 0xEF; // LED 12 (Indicates flow of
Traffic)
WritePortA_SPI1(SPI1A_data);
Delay10KTCYx(100);
SPI1A_data = 0xDF; // led 13 (Indicates flow of
Traffic)
WritePortA_SPI1(SPI1A_data);
Delay10KTCYx(100);

} //end of for

if (count1>4) //check if loop count > 4 state = AveStop


{
simpleState = AveStop;
}
Button1 = (PORTBbits.RB0 || 0);

if (Button1 == 0) //check if button 1 activated


{
simpleState = Pedestrian1;
}

break;

case AveStop: // state = AveStop

LCDClear();
for (i = 0; i<16; i++)
d_write(d1[i]);

//PORTD = 0x8c;
SPI2A_data = 0x92; // Show 'S' on Seven Segment display
for Stop

WritePortA_SPI2(SPI2A_data);

SPI2B_data = 0xA5; //LED 15,17,18,20 (Ave = amber, High.St


= red & amber)
WritePortB_SPI2(SPI2B_data);

SPI1B_data = 0xF8; //LED 01,02,03 (High St Traffic Stopped)


SPI1A_data = 0xF8; // LED 8,9,10 (Avenue Traffic Stopped on)

23 | P a g e
WritePortA_SPI1(SPI1A_data);
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(100); //delay

for (count2 = 0; count2<4; count2++)


{

Delay10KTCYx(100); //delay
}

if (count2>3) //check if count2 > 3 state = HighSt


{
simpleState = HighST;
}

break;

case HighST: //state = HighST

LCDClear(); //LCD = clear


for (i = 0; i<16; i++)
d_write(b[i]); //LCD = High St Flow ON

// PORTD = 0x86;
SPI2A_data = 0x89; // 'H'
WritePortA_SPI2(SPI2A_data); // show ‘H’ on Seven Segment

SPI1A_data = 0xF8; // LED 8,9,10 (Avenue = Stopped)


WritePortA_SPI1(SPI1A_data);
Delay10KTCYx(100);

for (count4 = 0; count4<5; count4++)


{

SPI2B_data = 0x9e; // LED 14,19,20 (High St =


green, rest is red)
WritePortB_SPI2(SPI2B_data);
Delay10KTCYx(80);
SPI1B_data = 0xFE; // LED 1 (Indicates flow of
Traffic on High Street)
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(80);
SPI1B_data = 0xfd; // LED 2 (Indicates flow of
Traffic on High Street)
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(80);
SPI1B_data = 0xfb; // LED 3 (Indicates flow of
Traffic on High Street)
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(80);
SPI1B_data = 0xf7; // LED 4 (Indicates flow of
Traffic on High Street)
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(80);
SPI1B_data = 0xef; // LED 05 (Indicates flow of
Traffic on High Street)
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(80);
SPI1B_data = 0xdf; // LED 06 (Indicates flow of
Traffic on High Street)

24 | P a g e
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(80);
SPI1B_data = 0xbf; // LED 07 (Indicates flow of
Traffic on High Street)
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(80);

if (count4>4) //if ciunt4>4 state = HighStop


{
simpleState = HighStop;
}

Button1 = (PORTBbits.RB0 || 0);

if (Button1 == 0){ //if button 1 activated


simpleState = Pedestrian2;
}

break;

case HighStop: // state = HighStop

LCDClear(); //LCD = clear


for (i = 0; i<16; i++)
d_write(b1[i]); //LCD = High St Flow Stop

SPI2A_data = 0x92; // Show 'S' on Seven Segment


WritePortA_SPI2(SPI2A_data);

SPI2B_data = 0xAC; // LED 14,15,18,20 (High St = amber,


Avenue = red & amber)
WritePortB_SPI2(SPI2B_data);
SPI1B_data = 0xF8; //LED 01,02,03 (High St Traffic Stopped)
SPI1A_data = 0xF8; //LED 8,9,10 (Avenue Traffic Stopped)
WritePortA_SPI1(SPI1A_data);
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(100); //delay

for (count3 = 0; count3<4; count3++)


{

Delay10KTCYx(100);

if (count3>3)
{
simpleState = Avenue;
}

break;

case Pedestrian1: // state = Pedestrian Crossing

25 | P a g e
LCDClear(); //LCD = clear
for (i = 0; i<16; i++)
d_write(P[i]); //LCD = Pedestrian Walk

PORTD = 0x20; // port D


SPI2B_data = 0xB5; // LED 15,17,20 (High St = red &
Avenue = amber)
WritePortB_SPI2(SPI2B_data);
Delay10KTCYx(225);
SPI2B_data = 0x76; // 14,17,21 (Pedestrian = green, rest = red)
WritePortB_SPI2(SPI2B_data);
Delay10KTCYx(225);

SPI1B_data = 0xF8; // LED 01,02,03 (High St = Stopped)


SPI1A_data = 0xF8; // LED 8,9,10 (Avenue = Stopped)
WritePortA_SPI1(SPI1A_data);
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(100);

SPI2A_data = 0x8c; // shows 'P' on Seven Segment


WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100);
SPI2A_data = 0xFF; // Seven Segment = OFF
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100);
SPI2A_data = 0x8c; // shows 'P' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100);

SPI2B_data = 0x76; // 14,17,21 (Pedestrian = green, rest = red)


WritePortB_SPI2(SPI2B_data);

SPI2A_data = 0x88; //shows 'A' on Seven Segment


WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x90; //shows '9' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x80; //shows '8' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xF8; //shows '7' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x82; //shows '6' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x92; //shows '5' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x99; //shows '4' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xB0; //shows '3' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xA4; //shows '2' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xF9; //shows '1' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);

26 | P a g e
SPI2A_data = 0xC0; //shows '0' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x92; //shows 'S' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xFF; // Seven Segment = OFF
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100);
SPI2A_data = 0x92; //shows 'S' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xFF; // Seven Segment = OFF
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100);
SPI2A_data = 0x92; //shows 'S' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xFF; // 'Seven Segment = OFF'
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100);
SPI2A_data = 0x92; //shows 'S' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);

simpleState = PedestrianStop1; //state = PedestrianStop1

LCDClear(); //LCD = clear


for (i = 0; i<16; i++)
d_write(P[i]); //LCD = Pedestrian Walk

break;

case PedestrianStop1: //state = PedestrianStop1

LCDClear(); //LCD = clear


for (i = 0; i<16; i++)
d_write(P1[i]); //LCD = Pedestrian Stop
PORTD = 0x88;

SPI2A_data = 0x92; // show 'S’ on Seven Segment


WritePortA_SPI2(SPI2A_data);

SPI2B_data = 0xA6; // LED 14,17,18,20 (High St = red &


amber, Avenue = red)
WritePortB_SPI2(SPI2B_data);
SPI1A_data = 0xf8; // LED 8,9,10 (Avenue = Stopped)
WritePortA_SPI1(SPI1A_data);
SPI1B_data = 0xf8; // LED 1,2,3 (High St = Stopped)
WritePortB_SPI1(SPI1B_data);

for (count3 = 0; count3<4; count3++)


{

Delay10KTCYx(100);

if (count3>3)
{

27 | P a g e
simpleState = HighST;
}

break;

case Pedestrian2: // Pedestrian Crossing


LCDClear(); // LCD = clear
for (i = 0; i<16; i++)
d_write(P[i]); // LCD = Pedestrian Walk

PORTD = 0x20;
SPI2B_data = 0xAE; // LED 14,18,20 (High St = amber, Avenue = red)
WritePortB_SPI2(SPI2B_data);
Delay10KTCYx(225);
SPI2B_data = 0x76; // 14,17,21 (Pedestrian = green, rest = red)
WritePortB_SPI2(SPI2B_data);
Delay10KTCYx(225);

SPI1B_data = 0xF8; // LED 01,02,03 (High St = Stopped)


SPI1A_data = 0xF8; // LED 8,9,10 (Avenue = Stopped)
WritePortA_SPI1(SPI1A_data);
WritePortB_SPI1(SPI1B_data);
Delay10KTCYx(100);

SPI2A_data = 0x8c; // shows 'P' on Seven Segment


WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100);
SPI2A_data = 0xFF; // Seven Segment = OFF
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100);
SPI2A_data = 0x8c; // shows 'P' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100); // delay

SPI2B_data = 0x76; // 14,17,21 (Pedestrian = green, rest = red)


WritePortB_SPI2(SPI2B_data);
SPI2A_data = 0x88; //shows 'A' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x90; //shows '9' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x80; //shows '8' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xF8; //shows '7' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x82; //shows '6' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x92; //shows '5' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x99; //shows '4' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xB0; //shows '3' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xA4; //shows '2' on Seven Segment
WritePortA_SPI2(SPI2A_data);

28 | P a g e
Delay10KTCYx(1000);
SPI2A_data = 0xF9; //shows '1' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xC0; //shows '0' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0x92; //shows 'S' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xFF; // Seven Segment = OFF
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100);
SPI2A_data = 0x92; //shows 'S' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xFF; // Seven Segment = OFF
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100);
SPI2A_data = 0x92; //shows 'S' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);
SPI2A_data = 0xFF; // 'Seven Segment = OFF'
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(100);
SPI2A_data = 0x92; //shows 'S' on Seven Segment
WritePortA_SPI2(SPI2A_data);
Delay10KTCYx(1000);

simpleState = PedestrianStop2; // state = PedestrianStop2

break;

case PedestrianStop2:

LCDClear(); // LCD = clear


for (i = 0; i<16; i++)
d_write(P1[i]); // LCD = Pedestrian Stop

PORTD = 0x88;

SPI2A_data = 0x92; //show 'S' on Seven Segment


WritePortA_SPI2(SPI2A_data);

SPI2B_data = 0xB4; //LED 14,15,17,20 (High St = red, Avenue = red


& amber)
WritePortB_SPI2(SPI2B_data);
SPI1A_data = 0xF8; // LED 8,9,10 (Avenue = Stop)
WritePortA_SPI1(SPI1A_data);
SPI1B_data = 0xF8; // LED 1,2,3 (High St = Stop)
WritePortB_SPI1(SPI1B_data);

for (count3 = 0; count3<4; count3++)


{

Delay10KTCYx(100);

29 | P a g e
}

if (count3>3)
{
simpleState = Avenue;
}

break;

default: //catches any rogue values for simpleState


break;
} //end of switch
} //end of while (TRUE)
} //end of main()

Conclusion:
The entire task has been completed and the following have been concluded from
this assignment. It has been observed that when creating State Event Action (SEA) table one
should take small event into consideration which results in any action because those actions then
results in change of states. It is very important to identify all the states in the start as without
having knowledge of all states it would be extremely difficult to create events and their actions.
All the events and their resultant actions have been noted in SEA table

State Transition Diagram (STD) is the pictorial view of SEA table. SEA table must be finished
before starting work on State Transition Diagram; SEA table is a kind of protection pre-step
before starting work on STD, without pre-step things can get worse. One more thing was
concluded that it is quite difficult or say impossible to include all the events and actions in State
Transition Diagram, so a reader should be aware to consider State Event Action table for full
information on events and actions. And consider State Transition Diagram to examine the core
events which makes transition of one state to another state

Flow Chart is the most important part of any program writing, Flow chart gives full information
of different stages occurs in the making of a program. A nice flow chart is extremely beneficial
not only for the programmer who is writing the program but also for the non technical client who
might not have any technical knowledge of coding. In this assignment it was noticed that the
flow chart made life easy for programmer, it is essential to have a good flow chart ready which
can make it easy to write a complete program. And for those clients who are unable to read the
code can easily get a pictorial view of the program functionality from Flow Chart.

30 | P a g e
Reference:

Ahmed, N. (2015) Electronic Ping Pong on Micro controller. Unpublished manuscript,


University of East London.
State transition diagrams (2016) Available at: http://www.cs.unc.edu/~stotts/145/CRC/state.html
(Accessed: 5 February 2017).
Bibliography:

Inc, F.D. (2015) LabVolt series by Festo didactic. Available at: http://www.labvolt.com/
(Accessed: 5 February 2017).

Ahmed, N. (2015) Electronic Ping Pong on Micro controller. Unpublished manuscript,


University of East London.

State transition diagrams (2016) Available at: http://www.cs.unc.edu/~stotts/145/CRC/state.html


(Accessed: 5 February 2017).

31 | P a g e

You might also like