The design task of this lab is to develop an interface to an 8-bit Nintendo controller. Your design will cause different LEDs to light up depending upon which button on the controller has been pressed. In addition, you are to design a state machine that observes the keys pressed on the controller. When a certain combination is observed, you are to light a different LED.

NES/controller communication
The NES uses a serialized polling mechanism to query the state of the
buttons 60 times a second. First, the NES sends a 12µs high signal to
the Latch wire, telling the controller to latch the state of all buttons
internally. 6µs later the NES sends 8 high pulses on the Pulse wire,
each with a period of 12µs and a 50% duty cycle.
After detecting the rising edge on Latch, the controller sends the status of the A button on the Data wire; Data is low if the A button is pressed, high if it is not. For each pulse on the Pulse wire, the controller drives the Data wire low if the button corresponding to that pulse was pressed. (The button states on Data are thus active low.) The button order is always the same: A, B, Select, Start, Up, Down, Left, Right. Again, see Figure 1 for more information.
Generating Latch and Pulse
You will need to generate the Latch and Pulse signals so that the controller responds correctly.
The first step is to divide the clock to an appropriate frequency. After that, you are left with a
number of options. You could design a state machine which generates Latch and Pulse. This state
machine would restart every time you desired to sample the controller, and its outputs would be
the Latch and Pulse signals.
Another option is to use a counter (which is of course a state machine itself) to generate Latch and Pulse. Again, you would need to be sure you are only generating these signals when sampling the controller.
Your Latch and Pulse have some restrictions. Each pulse should have a period between 8µs and 16µs and should have a 50% duty cycle. Latch should be high for a duration equal to pulse's period. Further, the time when pulse is actually changing should be a very small fraction of the time. As shown in Figure 2, it should be no more than 5% of the total time.

Reading Data
Once you correctly generate the Latch and Pulse signals, the controller will transmit the button
status on the Data wire. You may wish to use a shift register to read each bit from the Data wire.
Give careful consideration to how to clock the shift register.
Displaying data to the LEDs
You are to map the button data to the Green LEDs so that when a given button is pushed some
corresponding LED is lit. You may map the buttons to the Green LEDs in any way you see fit so
long as each button lights a unique LED.

Many games have secret codes that cause the game to behave differently. These "Easter Eggs" are activated by pressing a certain sequence of keys. Most NES games have Easter Eggs of one type or another in them.
Requirements
Each student will be assigned a different 5-key code. When that code is entered into the NES
controller, a single Red LEDs should be lit -- you may choose which one.
The user must press the right buttons in order and press no other buttons between correct presses
for the entry of the code sequence to be considered correct. The Red LED
should remain lit until the start button on the controller is pressed. In all cases, the Green LEDs
should continue to function as before. Once you have successfully implemented the required
functionality, you can improve upon this Easter Egg feature to earn a few extra credit points.
Information is available in the Deliverables section of this lab.

The mapping of Green LEDs to buttons is done at your discression. You are also free to choose which Red LED to use for the Easter Egg.
The 50Mhz system clock found on pin N2.
In-lab (130+ points)
Download the .sof file for the Nintendo Controller to the DE2 board and verify that your
implementation is working properly. There are two parts to the in-lab assignment. The first is to
demonstrate that your Green LEDs are correctly responding. (70 points)
The second is to demonstrate that your Easter Egg works correctly. (60 points)
Further, you may earn up to 20 points of extra credit for doing one or more of the following with the Easter Egg. Note that these assignments can be fairly difficult. Extra credit will not be accepted after the due date for the in-lab.
Post-Lab (45 points)