






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







By: Brian Pohl Matt Vivona ECE 395: ADSL Spring 2008 TA: Zuofu Cheng
The goal of this project was to use individual LED matrices to create a large LED grid that would display a randomly generated maze. Simple player controls then allow a player to navigate through the maze.
Our project this semester was to generate a random maze on a grid of LED matrices and control a guy that could move through the maze. The game is composed of nine LED matrices with a PIC controlling each one. Another PIC can be hooked up to send a new random maze to the matrices. Our original design was to make the maze on a monitor or TV screen, but they need to be constantly updated and we just want to display a static maze, once its started up, with a guy moving through it. So we decided to have LED matrices as our display instead. The display on the LED matrices was a little tricky at first, because we originally thought you could control each LED individually, but you can only control one column or row at a time. So we display the maze by quickly going row by row and turning on the LEDs that represented walls. We had to make sure to scan through the matrix fast enough that the human eye can’s see it scanning and it looks like a static maze, but as slow as we could so that there weren’t any wrong LEDs turned on because of delays. We used code written in C in generate the maze on a PIC30. We used a PIC for the random generation because of the extra memory on it. Once the maze was generated the PIC30 sends 64 bits to each PIC controlling an LED matrix. The 64 bits represented which LEDs represented walls and which represented open space. The LED matrices were controlled by a PIC18. We used a PIC18 because of all the I/O ports it has, but we didn’t need the extra capabilities of the PIC30.
i. Parts List DISTRIBUTOR DISTRIBUTOR PART # MANUFACTURER PART # DESCRIPTION QTY Sparkfun COM-00681 FYM-12881ABxx LED Matrix - Dual Color - Small 9 DIGIKEY CP-102B-ND PJ-102B CONN POWER JACK MALE 2.5MM CLSD 1 Parts Shop n/a n/a 9 PIN HEADER (0.1 INCH) 1 Parts Shop n/a n/a 12 PIN HEADER (0.1 INCH) 18 Parts Shop n/a n/a 3 PIN HEADER (0.1 INCH) 8 Parts Shop n/a n/a Push Button 4 Microchip dsPIC30F4013 dsPIC30F4013 16-bit PIC Microcontroller 1 Microchip PIC18LF4520 PIC18LF4520 8-bit PIC Microcontrollers 9 ii. Overview The game is comprised of LED matrices and controlled by PICs. The LED matrices have 24 pins, 8 representing ground for each row, 8 for the red LEDs of each column, and 8 for the green LEDs of each column. The matrices work so that a row or rows that are used are grounded and than the red and/or green LEDs that are used in the row(s) are connect to +5v to be lit up. To program the PICs we used MPLAB ICD 2. The ICD 2 is microchip’s in- circuit programmer that connects to the computer by USB and to the PIC through an ICD2 Header.
All of the software for our game was written in C and compiled using Microchip’s C18/C30 compilers. The C30 compiler was used for the random maze code as that was put on the dsPIC30 while the maze display and player control code was compiled using the C18 compiler as that code was put on PIC18s. The software side of our project consisted of two main files: generic.c and random.c. We had a few variations of each of the generic file that were changed slightly for the matrix in which the player would first start, as well as versions that just displayed a static maze hard coded in or versions that would load the random code bit by bit through PORT E3 when a combination of input buttons was pressed. Also, the random code had some different versions that scaled the size of the maze down because ultimately we didn’t receive all of the LED matrices that we ordered. The first file, generic.c , displays the final maze as a 2D array of zeros and ones that represent open spaces and walls. Each spot in the 2D array represents an LED on the matrix. The final maze would either be hard coded in or taken from the random generator. The LED matrix had latches that would keep rows and columns activated but it was impossible to address multiple individual pixels in this matter. Thus, to display the maze we cycle through each row and specify which columns need to be activated for each row. In setting the cycle to a high enough frequency, we were able to achieve a static appearance for the maze. The player movement control used four push buttons connected to PORT D as inputs to control the player’s movement. Current row and column variables were used along with the final maze array to check if the player was allowed to move in a certain direction. Because the player can only be on one matrix in the grid at a time, each matrix not occupied by the player is set to receive information on which direction the player is coming from. Each matrix has four variables the represent the player coming in from the left, right, top, and bottom. These ports are input for the matrices not occupied by the player and outputs for the matrix that contains the player. All of the unoccupied matrices also have input ports that receive the current row or column the player is coming from so the player will start at the appropriate spot on that matrix. These same ports are set to outputs on the currently occupied matrix. Each matrix has an on variable that represents whether the player is currently on that matrix or not. The second file, random.c , generates a random maze of a size that is hard coded into the code (one of our improvements was an input device that would allow the user to input maze dimensions within a certain range). The code starts with a 2D array of maze cells. Each maze cell contains variables representing a down wall and a right wall. Thus, it can be thought of that the left wall of a maze cell is the right wall of the previous cell and the up wall of a maze cell is the down wall of the cell above it. The maze also contains other variables such as length and label that are involved in finding the longest possible solution to the maze. The code utilizes an array that contains the down and right walls of every cell and then uses a random number generator to randomly pick from the array what wall to remove. A timer is started when the code begins and then runs until a certain combination of input buttons is pressed. The value is read from the timer at the instant the button combination is pressed and then the timer is closed. The maze generation code then starts so that the random number generator is seeded with a different
One thing that would have helped us would have been to have our PCB boards made. We drew up the schematics for a PCB board (attached), but we did not get all our parts in time and so we did not route it. The board would have made things a lot easier, because the breadboard was a mess of wires just for three matrices and it was very easy to make mistakes in wiring it. Lastly, a future idea that we had wanted to do but didn’t get to was to make this so that you could connect a lot of the PCB board together to create a giant maze. In our schematics we included connections to connect multiple boards, but never finished designing it.
We really learned a lot this semester in working on this project. We have never used a PIC before so we spent a good amount of time learning how to use it correctly through the data sheets, and also had never really programmed in C. We are, now, fairly comfortable with the I/O functions of the PIC and various other aspects of it. Also, because we’d never programmed a micro-controller such as the PIC before, we had never had to really worry about memory limitations when writing code. However, because our code initially required too much memory to run, we had to go through and optimize all that we could so that it would fit. In the end, we were able to optimize the code enough to run on the PIC, and the actual optimization process, while difficult and tedious, was definitely a great learning experience. We also learned how to use Eagle, which we have never used before, to draw up our schematics and design for a PCB board. While we couldn’t get the random maze generator fully integrated into the project, we did get a static maze to correctly display on the grid and our player motion worked without error, allowing the player to move throughout the grid from matrix to matrix without a problem. Not receiving all of the matrices we ordered and blowing out some of the lights on one didn’t allow us to make the large grid that we had intended but in the end we were happy with what we were able to accomplish. We gained a lot of hands on experience throughout the course of the semester and learned a lot of real world lessons concerned with project development that will only serve to help us in the future.
Figure A. Circuit Board Layout Figure A. Circuit Board Layout
Figure A.3 and A, Breadboard of design with 3 matrices