0% found this document useful (0 votes)
112 views12 pages

Section 1

The document provides instructions for a case study assignment to design a microcontroller-based traffic light controller. Students must complete preparatory tasks to help with the design, which involves interfacing a 4-digit 7-segment display module with a microcontroller. The preparatory tasks include determining the pin connections between the display module and interface board, writing code snippets like a delay function, and obtaining the 7-segment display codes. The tasks help prepare students to complete a program to display the number "1234" on the 7-segment display module.

Uploaded by

Aziz London
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
112 views12 pages

Section 1

The document provides instructions for a case study assignment to design a microcontroller-based traffic light controller. Students must complete preparatory tasks to help with the design, which involves interfacing a 4-digit 7-segment display module with a microcontroller. The preparatory tasks include determining the pin connections between the display module and interface board, writing code snippets like a delay function, and obtaining the 7-segment display codes. The tasks help prepare students to complete a program to display the number "1234" on the 7-segment display module.

Uploaded by

Aziz London
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 12

CT5003: Microprocessors & Embedded Systems

Case Study

Microcontroller-based Traffic Light Controller


Introduction
In this case study you are required to design/develop a microcontroller-based Traffic Light Controller. In order to help you with this assignment, you are asked to complete a series of tasks. These tasks are designed to prepare you for the actual case study and are given in section 1; while the requirements of the case study proper, are given in section 2. While you are working through the preparatory tasks, you need to keep a detailed logbook. Your logbook will be checked as you take a Multiple Choice Test (MCT) at the end of your case study. Your MCT result will NOT be carried forward if you fail to produce an acceptable logbook. You are required to write your own individual report for this case study. Your report must be submitted to the Assessments Unit of before the deadline date. Please confirm the actual date with the Assessments Unit, as NO marks will be awarded to late submissions. Important Notes: You must ONLY work in groups of TWO. You will be assessed as to how you carry out your work in the lab. Once you are assigned to a group, you must work together. You will have the same program but you must write your own individual report. Do NOT disturb other groups or work around the lab during the session. Read and plan your work before attending the laboratory. A limited number of hardware Modules / Cables will be available in the lab during weeks 10 to 14 in order for groups to download, test and demonstrate their program. You MUST NOT disconnect the modules or cables at all. You must keep a logbook and maintain it while in the lab. The assessment for the case study will be as follows:

Element Report Tests Total Mark:

% Mark 20 20 40

CT5003: Student taking CT5003 (30-Credit) will ONLY required to submit their logbook and take the Test in Week 13 (week after Christmas break). The actual Case Study report will be handed in week 26 along with the log book for submission. (please look at the Module Guide for further Details). Page 1 of 12

SECTION 1: Preparatory Tasks


The 7-Segment Display Module 4-Digits
The following Notes are taken from Chapter 16, Embedded Systems & Interfacing, by Saeed R Taghizadeh, 2005]

This module uses the M5450 Driver. The detail of this IC may be found elsewhere in the web site. 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 8 VCC=5V Pin 2 Pin 4 Pin 6 Data Clock

RJ45
Figure 1. 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.

Page 2 of 12

One of the microcontroller ports is connected to the 7-segment module via an interface board as shown below:
Target Board

Serial Port To Host

DC Power

RJ45 Straight Through Cable

7-Segment Display (M5450 Driver) Data Clock GND VCC

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.

Figure 2. Interfacing the 7-segment Module

Task 1:
Use the data for the interfacing cards and the 7-segment display module (Displayed on the posters in the lab). Determine which port is the 7-Segment has been connected to via the RJ45 cable. For example, look at the data for the interface card, find which bit of which port is connected to pin 1 of the RJ45 where the cable is connected. Determine which pin of the M5450 is connected to pin 1 of the RJ45 in the 7-segment module. Write these in the table in the row for pin 1. 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. Check these very carefully as a wrong deduction will effect the entire program. Table 1 RJ45 Pins
1 2 3 4 5 6 7 8

RJ45 in the Interface Card

RJ45

D3

D2

D1

D0

Data Clock GND VCC

RJ45 in the 7-Segment Module

Page 3 of 12

Task 2:
The skeleton of a typical C-program for microcontroller-based applications is shown below in figure 3.
/************************************************************************ * A Program for the 7-Segment Display Module * ************************************************************************* * Developed By: Member 1 & Member 2 * ************************************************************************* * Date: * * Module: CT3011N Embedded Systems and Interfacing * *************************************************************************/ #include <reg51.h> #include <string.h> /* Declaration of the Data and Clock Bits for the M5450 */ sbit Data = ? ; sbit Clock = ? ; sbit Enable = ? ; /* Only on some Modules but not all */

/* A very short Delay of about 10 microseconds */ /* This doesnt have to be accurate as explained in the lecture classes */ void M5450_Delay(void) {

/* The Main Program */ void main (void) { /* Declaration of all local variables in the main part of the program */

for(;;) { } } /* End of the main program */

Task 2.1. From table 1, enter the information in the definition part of the program (where the two/three question marks are). Task 2.2. The function <void M5450_Delay(void)> is a very short delay of about 10 microsecond. Complete the function by writing the appropriate code. This is just an approximate. Task 2.3. Answer the following questions: Task 2.3(a) What is the purpose of #include <reg51.h>? Task 2.3(b) What is the purpose of < for(;;)> in the main program?

Page 4 of 12

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.
10-g 8-CA 9-f 7-a a f g b c d DP 6-b DP-5

e -1

CA-3

d-2

Dec 0 1 2 3 4 5 6 7 8 9

dp 0 0 0 0 0 0 0 0 0 0

C-4

Hex

Figure 4 Task 3.1: There are some limited numbers of characters that can also be displayed (e.g. H). Write down the codes for all alphabetical letters that you think may be displayed on a 7-segment display. Task 3.2: The above 7-segment is assumed to be of Common-Anode type. The other type is Common-Cathode. Find out the difference between the two types. Is M5450 suitable for both types? Explain?

Page 5 of 12

Task 4: Display 1234 on the module.


Develop a program to display 1234. The skeleton of a main program may be written as follows:
/************************************************************************* * A Program for the 7-Segmen Display Module Task 4 * ************************************************************************** * Developed By: Full Name of Member 1 & Member 2 * ************************************************************************** * Date: * * Module: CT3011N Embedded Systems and Interfacing * *************************************************************************/

#include <reg51.h> #include <string.h>

/* Declaration of the Data and Clock Bits for the M5450 */ sbit Data = ? ; sbit Clock = ? ; sbit Enable = ? ; /* Only on some Modules but not all */

/* A very short Delay of about 10 microseconds */ /* This doesnt have to be accurate as explained in the lecture classes */ void M5450_Delay(void) {

void M5450_Pulse(void) { /* This function sends a single clock pulse to the M5450 Driver */ Clock=0; Clock=1; M5450_Delay(); Clock=0; }

/* A short Delay */

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 */

/* The following function sends a start pulse to the M5450 */ void M5450_Start(void) { Enable = 0; /* Eliminate this line if there is no Enable pin defined */ Data = 0; M5450_Pulse(); Data = 1; M5450_Pulse(); }

Page 6 of 12

/* 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(); for(;;) { M5450_Send(The M5450_Send(The M5450_Send(The M5450_Send(The M5450_Pulse(); M5450_Pulse(); M5450_Pulse(); } } /* End of the main program */

seven seven seven seven

segment segment segment segment

code code code code

for for for for

digit digit digit digit

1); 2); 3); 4);

/* Send a further Three Clock Pulses to Complete the 35 Pulses */

Remember, you need to write the complete the functions <M5450_Send> and <M5450_Delay> as described in the lecture class. Write everything in your logbook. Explain clearly how the functions are written. Complete the program. Enter and compile and build. Use the debugger to single step and simulate the function of your program. Write the result of the simulation /outcome in your logbook. Finally once you have fully simulated the program, you are ready to download it to the target board. If your program doesnt work in the target system, DO NOT unplug or disconnect any cables. All boards and cabling have been fully tested. If your program compiles and builds OK, this simply means that there are NO syntax errors (i.e. typographical errors). The fact that it doesnt function means that there may be one or more logical errors. This further indicates that you have failed to simulate your program fully. At this stage, Go back to the debugger and simulator and single step your program until the error is found. The most exciting and rewarding part of any project development is this step: To make a program that to perform its intended task. This requires patient and time. Together with your other member in the team, look at each line of the program and try to carry out a Dry Run. This means try and execute each line one at the time and determine where the error is occurring. DO NOT begin walking around the laboratory and disturb others or wait for an instructor to help you find the error. This is your task and you must do it. <Do Not move to the next task until you have completed this task first>

Page 7 of 12

Task 5: A Simple Counter


Develop 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-Segmen Display Module Task 5 * ************************************************************************** * Developed By: Full Name of Member 1 & Member 2 * ************************************************************************** * Date: * * Module: CT3011N Embedded Systems and Interfacing * *************************************************************************/ #include <reg51.h> #include <string.h> /* Declaration of the Data and Clock Bits for the M5450 */ sbit Data = ? ; sbit Clock = ? ; sbit Enable = ? ; /* Only on some Modules but not all */

/* A very short Delay of about 10 microseconds */ /* This doesnt have to be accurate as explained in the lecture classes */ void M5450_Delay(void) {

} void M5450_Pulse(void) { /* This function sends a single clock pulse to the M5450 Driver */ Clock=0; Clock=1; M5450_Delay(); Clock=0; }

/* A short Delay */

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 */

} /* A long Delay of about 1 second */ /* This doesnt have to be accurate as explained in the lecture classes */ void Delay(void) {

/* The following function sends a start pulse to the M5450 */ void M5450_Start(void) { Enable = 0; /* Eliminate this line if there is no Enable pin defined */

Page 8 of 12

Data = 0; M5450_Pulse(); Data = 1; M5450_Pulse(); }

/* The following function Displays a 4-digit number D on the 7-Segment */ /* Display */ void M5450_Display(unsigned int D) { unsigned char D3,D2,D1,D0; /* First separate the 4 digits and assign them to D0, D1, D2 and D3. */

/* Then convert each digit to its seven-segment code using the /* lookup table method */

*/

/* Now call the send function to send each individual code as before */

/* Now send the final 3 extra clock pulses */ M5450_Pulse(); M5450_Pulse(); M5450_Pulse(); }

/* 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(); for(;;) { for( k = 0; k<9999; k++) { M5450_Display(k); Delay(); /* A 1 Second Delay */ } } } /* End of the main program */

There are two further functions that you need to develop. <Display> and <Delay>. Read the program skeleton very carefully and begin to develop these functions. Carry out the same step as for task 4 and enter your conclusions in your log book.

Page 9 of 12

Task 6: (Optional) Rotating Single Segment


Your task is to develop a program that will operate the 7-segments as follows: Turn all the segments (including the decimal points) of all 4-digits off Wait for about 0.5 second Turn segment dp of digit D0 ON, and all remaining segments OFF. Wait for 0.5 second. Turn segment a of digit D0 ON, and all remaining segments OFF. Wait for 0.5 second. Turn segment b of digit D0 ON, and all remaining segments OFF. Wait for 0.5 second. . . .

Turn segment g of digit D0 ON, and all remaining segments OFF. Wait for 0.5 second. Repeat the above sequence for D1, D2 and D3. Once the individual segments of all 4-digits have been operated one at a time, repeat the whole process again. Hints: The skeleton for the main program is given in figure 5. To turn all the segments (including the decimal points) of all 4-digits off We need to send: 00000000 00000000 00000000 00000000 to the M5450. Converting this to 4 bytes of hexadecimal, we may write: 0x00, 0x00, 0x00 and 0x00. Let us assume a function called <Send> whose function is to send a byte to the M5450. To do the above we write: Send(0x00); Send(0x00); Send(0x00); Send(0x00); Turn segment a of digit D0 ON, and all remaining segments OFF The 32 bit code will be: 0x01, 0x00,0x00 and 0x00, therefore: Send(0x01); Send(0x00); Send(0x00); Send(0x00); The above may be repeated until all segments of each digit have been turned ON once. This method however is too long and may be made more efficient by using the Shift statement. Page 10 of 12

SECTION 2: Case Study


Introduction
You are required to design a microcontroller-based Traffic Light Controller. The constraints (what you must use) are as follows: The unit: 1. Must use an 8051 microcontroller 2. 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).

Block Diagram:

N
Large Seven Segment Displays showing a count down of the time left for the lights to change to Red/Green

RN1 YN1 GN1

To Ports of the microcontroller

15.20
W

PDN1

To INT0 Pin of the microcontroller

E
Large Seven Segment Displays showing a count down of the time left for the lights to change to Red/Green

45.10
Pedestrian Crossing. Once pressed, a Buzzer sounds for a certain time (15 Sec) and traffics are stopped to allow pedestrians to cross

Buzzer

S
Figure 7. A simplified diagram of the traffic light junction

From A Port

Page 11 of 12

Your Initial Task


Your first task is to decide how the traffic light should operate in order to control the traffic in all directions. Please note that this part of the case study is entirely up to the individual groups. The groups must also decide all the necessary timings. Clearly formulate your strategy in your logbook.

General points
As already mentioned, your organization in the lab is an important part of this case study. Before you start the work, you MUST ensure that you are clear on how to use: Ride Development System to Enter, Compile, Debug, Simulate, Single Step a program written in C. The down loader to download your HEX programs onto the Microcontroller Memory. You read the relevant lecture / tutorials from the lecture classes as well as the web site before attending the laboratory.

DO NOT ASK Questions Such as:


How do I do this.. What shall I do Next.. Is this Correct. Can you check my program. This is part of the module that YOU become responsible in your learning. Sort out all your questions before you attend the laboratory. Remember for most of you, this is the last year of your course and you will be applying for jobs very soon. This is what you will be expected to do once you are given a task.

Page 12 of 12

You might also like