Section 1
Section 1
Case Study
% 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
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
DC Power
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 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
D3
D2
D1
D0
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 */
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
/* 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 */
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
/* 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
/* 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
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
Block Diagram:
N
Large Seven Segment Displays showing a count down of the time left for the lights to change to Red/Green
15.20
W
PDN1
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
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.
Page 12 of 12