Please contact me if you find any errors or other problems (e.g., something is unclearly stated) in this web page
Useful references for E15 labs
In this lab you will be performing many of the same tasks that you did in the last lab. The goal is to teach you new methods, but also to give you an appreciation of various solutions to the same problem.
Go through the tutorial describing the writing and debugging of a C program in Code Composer Studio.
This may seem familiar: You have seven LED's (light emitting diodes) as shown below:

The LED's are connected to an MSP430F2012 as shown in the table below:
|
LED 1 (Red): A EZ430: P1.0 |
LED 7 (Red): E EZ430: P1.4 |
|
|
LED 2 (Yellow):B EZ430: P1.1 |
LED 5 (Yellow):D EZ430: P1.3 |
LED 8 (Yellow):F EZ430: P1.5 |
|
LED 3 (Green): C EZ430: P1.2 |
LED 9 (Green):G EZ430: P1.6 |
The code below (E15Lab2Die_1.c - right-click to download file) is the shell of a program to simulate a die.
Task 1a: Implement a di by filling in the code in the two locations that say "// &&&&&&&&&& Add your well commented and neatly indented code here". Demo to me.
Task 1b: "Roll" your die 36 times and record the output. Compare to expected values.
Task 1c: Read this description of "state machines" and then neatly and thoroughly comment the code in the file E15Lab2Die_2.c. You can do this later, but you must make sure you understand the code before continuing.
The goal is to design a stoplight for which the signals should change according to the following table:
| Input Values | Light Setting | |
| North-South | East-West | |
| 0-5 | Red | Green |
| 6-7 | Red | Yellow |
| 8 | Red | Red |
| 9-12 | Green | Red |
| 13-14 | Yellow | Red |
| 15 | Red | Red |
Task 2a: Draw a state diagram with 16 states that implements the design above. Note that this is fairly easy because there are no conditional state transitions.
Task 2b: Write a program that implements your state diagram and cycles through it at about 1 state per second (you'll have to experiment to get the proper delay - recall that there were delays in the code in the tutorial). You only need one delay per loop (you can put it at the beginning). Remember that integers have a maximum of 32767.
There should be two major distinct sections to your code: State Transitions and State Outputs. This is not the only (and in some situations, not the best method), but I want you to stick to it for this lab.
Task 2c: At some intersections of a busy road and one that is not very busy, the light stays green on the busy road until a car shows up on the other road, at which time the light changes. Let the East-West road be the busy road. Draw a state diagram that stays in state 5 until the pushbutton is pressed, and then cycles until it returns to state 5.
Task 2d: Implement the state diagram from the previous subtask. Connect to the traffic lights in Hicks 310 and demo to me (you only need the E15 I/O board, the power supply, and the small D-shaped board with the processor). The traffic lights have a cable that connects to the 9-pin connector on the edge of the E15 I/O board.
The state diagrams for this task have been somewhat tedious to code for because there were 16 states. If we wanted a longer cycle (more states), or different timing (different state transitions), this problem only gets worse. Let's modify things a bit so that we only have 6 states as listed below:
| States | Light Setting | |
| North-South | East-West | |
| SRG | Red | Green |
| SRY | Red | Yellow |
| SRR0 | Red | Red |
| SGR | Green | Red |
| SYR | Yellow | Red |
| SRR1 | Red | Red |
Now we will add a counter to the code that increments at every cycle. As you transition from one state to the next, the counter is reset to 0; so as we enter a new state the counter is always equal to 0.
So for example, we might stay in state SGR for four increments of the counter, at which time we transition to state SYR, and reset the counter to 0. We can stay in state SYR until we get two increments of the counter, then we transition to state SRR1. Etc...
A code shell is given in the file E15Lab2Traffic.c, and is shown below:
Task 2e: Draw a state diagram that implements the "busy road" scenario (Task 2c and 2d). Assume "count" is an input to each state (much as "n" and "d" were inputs in the gumball state machine), as well as the pushbutton. Implement the same timing as before. The variable "count" is also an output that should be reset to 0 at state transitions (unless the variable is not needed because we only stay in the state for 1 iteration).
Task 2f: Implement it and demo to me.
Write code such that if the pushbutton is pressed when you apply power to the circuit it will run the "die" code, otherwise it runs the traffic light code. Demo to me.
Consider the following game:
I haven't thought this through completely, so if something is ambiguous (or impossible), adjust the rules slightly (but document your changes/decisions).
You might also (but needn't) consider
Task 4a: Draw the state diagram.
Task 4b: Implement.
The grading of each subtask is as follows.
This is a minimal list, feel free to augment with material you think is necessary (but I'm not looking for anything beyond what I ask for).
Please contact me if you find any errors or other problems (e.g., something is unclearly stated) in this web page