43
1 EEL 4924 Electrical Engineering Design (Senior Design) Final Project Report 19 April 2011 Project Name: E-Board Abstract: The E-Board is an old school gaming system where two players challenge each other in an 8x8 grid game. Each player has a portable control with a single color display of the game. The user interface is a directional button pad and an action pad. The controls communicate wirelessly to each other and relay information to the audience board. Each control has Checkers and Connect four games. The audience board is an 8x8 grid board that updates nonplaying viewers of the game’s status with lit LEDs. The board operates with a dot matrix LED array (two color LEDs per square) beneath the grid mask. It can play sound effects and display character information when an action is performed. A NiMh battery charging circuit was added for academic understanding as well. The board operates best with a 6V voltage source (9V source for battery charging).

Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

1

EEL 4924 Electrical Engineering Design

(Senior Design)

Final Project Report 19 April 2011

Project Name: E-Board Abstract:

The E-Board is an old school gaming system where two players challenge each other in an 8x8 grid game. Each player has a portable control with a single color display of the game. The user interface is a directional button pad and an action pad. The controls communicate wirelessly to each other and relay information to the audience board. Each control has Checkers and Connect four games.

The audience board is an 8x8 grid board that updates nonplaying viewers of the game’s status with lit LEDs. The board operates with a dot matrix LED array (two color LEDs per square) beneath the grid mask. It can play sound effects and display character information when an action is performed. A NiMh battery charging circuit was added for academic understanding as well. The board operates best with a 6V voltage source (9V source for battery charging).

Page 2: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

2

Table of Contents Section Page Project features 3 Competitive Projects 3 Concept and Technology 4 Project Architecture 12 Diagrams 19 User Directions 21 Bill of Materials 22 Responsibility Table 23 Improvements and Future Work 23 Project Schedule 24 References 24 Appendices 24 List of Figures and Tables Section Page Figure 1 4 Figure 2 4 Figure 3 6 Figure 4 7 Figure 5 8 Figure 6 9 Figure 7 9 Figure 8 9 Figure 9 10 Figure 10 10 Figure 11 12 Figure 12 13 Figure 13 14 Figure 14 14 Figure 15 15 Figure 16 16 Figure 17 18 Figure 18 18 Figure 19 19 Figure 20 19 Figure 21 20 Figure 22 20 Figure 23 21 Table 1 21 Table 2 22 Table 3 22 Table 4 24

Page 3: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

3

Project Features The audience board is capable of playing 16kHz sampled sounds, displaying information on character LCD, driving an 8x16 dot matrix, wireless communication, physical button commands, and NiMh recharge-backup circuit. It successfully met all basic features proposed in abstract and added features such as LCD interface and battery charging. The dot matrix is a green-red LED array truly designed for dark or dim areas. This array quickly displays game information or can be used to access internal animations and a 2 digit alphanumeric display. The character LCD also displays information such as statistics and game being played. The interface for accessing these displays is the wireless Nordic chip or two interrupt button commands. The battery charging circuit uses the LTC4060 standalone controller and external elements to charge a 4 series NiMh pack (or 4 NiMh charged together). This circuit requires heat sinking on the current delivering transistor and 5V voltage regulator.

Each controller has a 4 button D-pad a 3 button action pad for the user interface. A monochrome LCD is the centerpiece of the control displaying the game and its information. A wireless chip on the back of the controller is used to relay information to the other controller and the audience board. The controllers support two player and single player game modes.

Because the audience board is set up for an 8x8 square playing field, the featured games will feature an 8x8 grid. Connect four was implemented as a one-player game and shows the principle of single player mode (controller to audience board interaction) Checkers is the two player game implemented and showcases the two player mode and controller to controller to audience board interaction. The system as a whole operates well. Both controllers are able to successfully interact with each other and the audience board and produce appropriate outputs and sound effects. Competitive Products

Controlling dot matrix displays are popular for hobbyist kits and engineered large pixel displays. These boards are typically used as electronic signs and are not specifically designed for interactive games. The audience board is a more interactive device which can act as a large sign or play games and simple 8 bit music. Figure 1 exhibits two large pixel displays.

Page 4: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

4

Figure 1: Left: Peggy board; Right: Sure Electronics Dot Matrix Board

Several handheld systems with a similar function exist on the market. One such example

is the Mattel Tetris handheld.

Figure 2: Mattel Tetris handheld

These types of handhelds typically play a single game or a set number of games, but do

not support two-player functionality or wireless capability.

Concept and Technology Controller

The Atmega32A is a 40 pin microcontroller. For this application 3 ports will be used as IO ports: 1 for the buttons, and 2 for the LCD. The last port is used to interface with the wireless chip through SPI. This microcontroller was chosen because it is easy to work with and the main things that are needed were SPI communication, IO ports, and interrupt functionality.

Like most gaming systems, buttons will be used to send input and allow the user to interact with the controller and play a game. As with most buttons, they have the issue of bouncing. To debounce the circuit a 10 ms delay is added in between button presses.

Page 5: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

5

The controller uses a NHD-12864MZ-FSW-GBW-L Graphic LCD. It is a 128x64 pixel display that will display what is currently going on in the game. This particular type of LCD has its left and right halves controlled by two separate chip select pins. It has a KS0108B driver built in, of which there are several libraries that can interface with the LCD and the Atmel. The driver chosen for this was the Procyon Avrlib created by Pascal Stang, because it is easy to work with, has most of the basic functions needed for the games that will be implemented, and also takes into account the two chip select pins that control the left and right halves.

The Nordic nRF24L01+ RF transceivers are used to interface between the controllers and audience board. They are capable of sending or receiving up to 32 bytes at a time at a data rate of 1Mbps or 2Mbps and communicate with the microcontroller through SPI. They can also be configured to communicate with more than 2 units.

The Atmega32A interfaces with the Nordic by sending bytes through SPI. It has its own

instruction set where you can read or write to registers to configure things such as the receive/transmit address, how many bytes you want to receive/send, and whether or not the device operates as a transmitter or receiver. Each instruction cycle is also initiated by setting or clearing the CE or CSN pins. The CE pin is usually toggled if you want to start a transmission/reception process, and the CSN pin is usually toggled when you are done sending a command to the Nordic.

The IRQ pin on the Nordic is an active-low pin that is connected to one of the interrupt pins on the Atmel and notifies the microcontroller on whether data was successfully sent or received. When the Nordic either sends or receives data the IRQ pin goes low and the microcontroller goes to the interrupt service routine that the transmission/reception process was successful. Before the Nordic can transmit or receive any data again, the IRQ pin is set high again.

The LM7805C voltage regular is used to generate 5 volts needed to power the LCD. Although the product is discontinued and is not a low-dropout regulator, it does generate the appropriate voltage the LCD needs to function properly, although this only applies for batteries around a 1.5V rating. Because of this, 4 alkaline batteries are used to power each controller.

The LCD needs a negative source voltage for its contrast, and so the ICL7662 voltage inverter was used to produce it. Two capacitors are needed to make it function properly. Audience Board The board is controlled by the Atmega32a processor, a more power efficient version of the Atmega32. The Atmega32a processor was chosen for its 32 I/O pins, SPI capability, and large programmable memory. The Atmega32a voltage range is 2.7-5.5V but is used at the 5V processing level to better drive LED’s. The processor runs at 8MHz which is fast enough to avoid the use of an external oscillator. The max speed of the SPI which is utilized in the circuit is 444kbit/s (a fck/16 setting). The SPI PORTB of the Atmega32 controls the wireless chip, DAC, and shift register row driver. PORTD is responsible for two interrupt command buttons and a 4-bit operated character

Page 6: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

6

LCD. PORTA and PORTC are responsible for column LED logic. These ports are connected to buffer IC’s to relieve current stress. With multiplexing and SPI control, 140 outputs and 3 inputs are controlled. A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as desired. A 100Hz or higher pulse frequency will not be perceived by the human eye for nonmoving applications otherwise a kHz range is required. Eyes react to brightness in a logarithmic manner and perceive average brightness for frequencies greater than the nominal threshold of 60Hz. Vision also attempts to even differing brightness’s. The audience board operates with a 12.5% duty cycle and thus 1/8 of LED brightness is seen with some freedom room in operation. The principle of operation is the use of PWM. The rows are controlled by the 8 bit shift register 74HC595. The selection of the register is not critical. Most 8 bit shift registers, counters, and output expansion IC’s are capable. The ULN2803a current sink follows the shift register to output the necessary current for the 16 LED’s per row. The ULN2803a is a cheap Darlington array that can output a maximum of 500mA and only take 1mA~ of current. The ULN2803a drives the cathodes to near ground voltage (typically 0.9V) when a positive voltage is applied.

Figure 3: Equivalent Circuit (Voltage follower represents IC with current maximum)

The final components of the circuit are the current limiting resistors and the buffer IC’s. The current limiting resistors are dependent on the dot matrix being used. Considerations to the type of LED and the current must be made to select the right resistor DIP package. The buffer IC used is the 74ACT541 which can source 50mA of current per pin. Without these IC’s, the microprocessor could only safely source 11mA per pin. The option of overdriving, which works on devices higher resilience to PWM current than static current, is frowned upon as a glitch could damage the system and the LED will degrade faster. Current limiting resistance is calculated by:

or

Page 7: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

7

Figure 4: Output Current vs. VULN

For a VF of 2V, a 100ohm resistor package would provide 19-23mA (16LED-1LED ON) current. Such a decrease as more LEDs turn on is negligible to the eye. LEDs also have capacitance which results in a voltage decay that isn’t problematic at kHz pulsing. A LED has a rise time in the order of nanoseconds. A larger viewing angle and luminosity rating mean a brighter LED. Forward voltage typically increases as emitted wavelength decreases. For example, red LEDs typically have a lower forward voltage (1.6-2V) then blue LEDs (2.5-3.7V). Wavelengths of emitted may also affect perceived brightness. The audience board was designed for dual LED packages. The Kingbright LEDs have two colors (GaAIAs Red 2V and GaP Green 2.2V) that with a diffused package can create a third color. The third color can also be blended in different ways with PWM. For example, a Red/Green LED will normally blend orange. But if red had a lower duty cycle, the color will appear yellow. Considerations to the differences in forward voltages of the two colors were negligible. The audience board is designed to have rows tied to cathode and columns tied to anode and works with positive logic. The audio circuit uses the LTC1661 10bit DAC to generate sounds. The LTC1661 was chosen on availability and only 8bit resolution is used to conserve memory. The SPI port of the Atmega32a can deliver a sample frequency of 27.75kHz to the DAC (444k/16). This sample frequency is further limited by multiplexing processing delay to a frequency of approximately 18kHz. This is not a problem since sounds should be limited in memory and 16kHz is the maximum reasonable sample rate. Thus, the sounds files are within the 8kHz region. There are three types of sound designs: tones, 11kHz wav files, and 16kHz wav files. The 16kHz wave file was down sampled from 22kHz wav sound. This is done by applying a raised cosine filter before down sampling. The second processing step is to crop and suppress any digital static noise in the file. The third step is to format the data into 8bit integers and transfer into a text block suitable for code. These last two steps are done for the 11kHz wav sounds as well. The tones are created from sinusoids and other periodic sounds. The 16kHz sampled sound files are the most heavy in terms of memory followed by the 11kHz sampled sound files. Tones are an order of magnitude smaller but are the most versatile as they can be repeated and transmitted at different rates.

Page 8: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

8

The speaker chosen should have a frequency response range of at least 8kHz. Speakers with better sound pressure levels will provide louder sound levels. A large speaker was chosen for demo audibility. The IC amplifier being used is the TPA301D audio amplifier. This chip is a Class AB Bridge Tied Load amplifier that can operate without heat sink up to 350mW. It is more preferable to operate the amplifier at 250mW to allow smaller speakers to be used. The human ear is very logarithmic where approximately ten times the power is needed to generate twice the volume. A drop down resistor should be configured from the DAC’s output to the potentiometer. An actual, approximated, or simulated logarithmic potentiometer is recommended for volume control but the log pot used was unfortunately inverted. The following are relevant calculations to the operations of the device.

Figure 5: TPA301 Example Circuit Diagram

Perceived volume change 2

Drop down resistance (with unity feedback = 2V/V): ∙ √#. ∙% 1'

For a 10k pot, 25.355*Ω ⇒27*Ω Choosing unity feedback resistances:

5* / 001

/ 20* ⇒ 0 , 33000Ω4567*8 ||' 1 33000 ⇒ 25.7* ⇒ 27*Ω

: 1

2;<=⇒ <= 464@A<BC: 10DE

:0 1

2;0<F⇒ <F 102.6*@A<BC:0 475E

CB and CS can be left as 1uF capacitors.

Efficiency = GH

31.4% at 5V

Page 9: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

9

Figure 6: Drop down factor and power influence of linear, logarithmic (10), and simulated (R/10)

potentiometers

Figure 7: Equivalent Circuit of TPA

TPA301D has better performance with low ESR (equivalent series resistance) capacitors and metal film resistors. Since transient effects are on the order of milliseconds, they can be neglected. Phase change is also not important when considering a mono-speaker.

Figure 8: TPA301D data sheet plots

Page 10: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

10

Figure 9: Example output of superimposed frequencies (500Hz, 1kHz and 8kHz)

The Densitron LM2022 4bit version LCD was used as it was already available. Any 4bit operable character LCD is a suitable replacement. There is no reading from the LCD and when the RESET button is pushed the LCD holds information until microprocessor reinitializes it. The LCD operates with the multiplexing by utilizing transmission delay time as switching time. The wireless chip used for the design is the Nordic Transceiver NRF24L01+ which is capable of 2Mbps transmission. This chip was purchased early and has the same principle as most SPI wireless chips. The board also does not transmit to other devices but still retains this capability. The wireless information sent is 1 byte of protocol and 16 bytes of truth state data. The truth state data represents 8 LEDs’ on/off states. The dot matrix board has 2 bytes per row where the top left corner byte is the first byte and the bottom right corner is the last byte.

10 00 10 00 10 00 10 11

00 10 00 10 00 10 11 10

10 00 10 00 10 11 10 00

00 00 00 00 11 00 00 00

00 00 00 11 00 00 00 00

00 01 11 01 00 01 00 01

01 11 01 00 01 00 01 00

11 01 00 01 00 01 00 01

Figure 10: Two Color LED Truth State Diagram 0x88,0x8B,0x22,0x2E,0x88,0xB8,0x00,0xC0,0x03,0x00,0x1D,0x11,0x74,0x44,0xD1,0x11

Three buttons were added to the circuit to utilize all the pins except the clock inputs and VREF. The first button is connected in a pull up fashion (normally to Vcc) to the active low RESET pin. When this button is pressed the microprocessor shuts down and reboots when the button is released. Devices do not reset alongside the microprocessor but will be reinitialized (if applicable) when the microprocessor reboots.

Page 11: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

11

The other two buttons are labeled Action and Demo and operate on interrupt principle. The configuration is pull down (normally low) but the configuration is unimportant and only chosen for academic inclusion of both configurations. Rather than polling, these are interrupt buttons that can occur anytime during the processor when a rising edge is detected. The interrupt code executes at this time and returns to the step the microprocessor left. The 5V VCC level was chosen for the proper operation of the multiplex and LCD devices. The LTC4060 is a standalone ∆V fast charger control for NiMh batteries which uses a few external components to deliver current. The choice to implement this charger circuit demanded a minimum wall input of 8.7V which implies the use of a 9V adapter. A 4 pack battery of NiMh is implemented as backup or alternative power to the board. While it is more suggested to use a single 4cell pack to maintain distributed charging, four individual batteries will not cause any problems.

The use of four cells requires SEL1 and SEL0 to be tied to VCC9. Since active low

shutdown and active high pause are not required, the pins are held high and low respectfully. The chemistry pin is tied to ground to indicate NiMh batteries instead of NiCd. Auto-recharge is held high to allow the controller to recharge batteries that fall below the threshold voltage. The NTC pin is for an optional thermo resistor network but is tied to ground as it is not in use. Active low charge status and supply status (ACP) outputs are drivers to LED indicators. Sense, drive, and battery pins use an external PNP transistor (FZT948CT) for controlled current driving. This transistor meets the minimum requirements of current gain (50) and current maximum (2A). The program components are calculated as follows:

' 1395

KLMN=

1395

400OP= 3490Ω ⇒ ' = 3.3*Ω ⇒ KLMN = 423OP

:QRST =U

'1.567 × 10W=

3ℎC

3300 ∙ 1.567 × 10W= 5805E ⇒ 5605E ⇒ U = 2.9ℎC

Note: These values allow longer lasting batteries.

Page 12: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

12

Figure 11: Schematic of the LTC4060 charger controller

Neglected in this prototype, a proper pcb heat sink of 4 square inches is needed for the PNP transistor. This was compensated with paralleling transistors and an external heat sink. The path control circuit uses the input voltage to the gate of a P-channel logic gate MOSFET () to decide whether battery power should be used. The Schottky diode (1N5817) allows the 9V to pass when present with a slight voltage drop. This diode also blocks current from the batteries when the 9V source is nonexistent. A regular diode would be better as it will reduce the 3.6V drop across the 5V regulator (less heat dissipation).

A low dropout regulator with linear low voltage characteristic is required to regulate the 9V to 5V without having severe effects on the lower battery voltage. The LM2940 was chosen as it meets these requirements. The downside to this power management is the battery voltage will swing with load current. For the LM2940, the voltage has a worst possible swing of 200mV as the LED’s switch. This can be reduced with reservoir capacitors on the output. A tantalum capacitor is used on the output of the voltage regulator.

Page 13: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

13

Figure 12: LM2940 characteristics

Reservoir capacitors are larger electrolytic capacitors that compensate for these dips in the voltage. Rather than a 5% clock like ripple in drop out mode, a 1mF or greater capacitor with reduce the ripple to <1%. Bypass capacitors used are moderate ESR ceramic capacitors that target noise in the system. The 3.3V was a redundant addition as the wireless module already has a LDO surface mount regulator. A mechanical switch also turns the system power off or on. All devices operate with at least 20% head room and the board is designed not to be damaged by bad software. Project Architecture

The microcontroller reads the button inputs, and performs some action depending on what button is pressed, like moving a cursor, selecting a piece, or shifting menu screens. When the checkers game is on for both controllers, one controller starts their turn while the other stays idle and waits for data from the controller currently playing. Once the current player finishes their turn, the information from the playing field is translated into an array of bytes, which is transmitted to the audience board, then to the other controller. The player ends their turn, goes into receive mode and waits for the other player while the other controller, having received the data bytes, uses it to update their screen and their turn starts. This cycle repeats until the game is won. The following flowcharts illustrate the software and hardware architecture of the controls.

Page 14: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

14

Figure 13: Software flow chart

Figure 14: Hardware block diagram showing how the main hardware components interact

Page 15: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

15

The audience board operates with the principle that a dot matrix is running virtually at all times. Unless the processor is interrupted, saving EEPROM, or loading EEPROM, the multiplex board (see figure 17) will continue to display the 8x8 image. The wireless works in the same way as mentioned in the controller section. The character LCD is operated under 4 bit operation and flashes switches the dot matrix row 5 times during each character write.

The audio software requires a transmission to the DAC and a row switch of the dot matrix. A sound file is a large array stored in flash that is SPI transmitted to the DAC at a specified frequency. MATLAB (see appendix) was used to process these sounds. Tones are smaller arrays that require more intricate script for musical effects.

The coding scheme loops on instructions, typically just multiplex. The interrupt buttons

and the wireless chip can change this instructional byte to perform an action such as changing LED information, LCD character information, or playing sounds.

The following flowcharts illustrate the software and hardware architecture of the

audience board. It should be noted that drivers for tones, animations, and timers exist but no demo code is available for the April 19 due date. They were thus excluded from software flowchart.

Figure 15: Overall Hardware flowchart

Page 16: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

16

Figure 16a: Overall audience software flowchart

(Note: Interupts are shown at top for clarity but can happen at anyime)

Page 17: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

17

Figure 16b: Overall software flowchart continued

Page 18: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

18

Figure 17: Initialize (Left) and multiplex (Right) flowcharts

Figure 18: Sound (Left) and Figure 8: LCD (Right) flowcharts

Page 19: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

19

Diagrams

Figure 19: Schematic of controller

Figure 20: PCB Layout of controller

Page 20: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

20

Figure 21: Audience Board Schematic

(Note: Sockets represent barrel jack connection and log pot mounts)

Figure 22: Audience board layout (6.455x3.28in) (Reflects improvement on 5V voltage

regulator)

PB0 (XCK/T0)1

PB1 (T1)2

PB2 (AIN0/INT2)3

PB3 (AIN1/OC0)4

PB4 (SS)5

PB5 (MOSI)6

PB6 (MISO)7

PB7 (SCK)8

RESET9

PD0 (RXD)14

PD1 (TXD)15

PD2 (INT0)16

PD3 (INT1)17

PD4 (OC1B)18

PD5 (OC1A)19

PD6 (ICP)20

PD7 (OC2)21

XTAL212

XTAL113

GND11

PC0 (SCL) 22

PC1 (SDA)23

PC2 (TCK) 24

PC3 (TMS)25

PC4 (TDO) 26

PC5 (TDI)27

PC6 (TOSC1) 28

PC7 (TOSC2) 29

AREF 32AVCC30

GND 31

PA7 (ADC7) 33PA6 (ADC6) 34PA5 (ADC5) 35PA4 (ADC4) 36PA3 (ADC3)

37PA2 (ADC2) 38PA1 (ADC1)39PA0 (ADC0) 40

VCC 10

U1

ATmega32-16PC

1 2 3

P1

VReg5

1 2 3

P2VReg3.3

12

P3

Battery Pack

1234

5678

P9

LTC1661

GND

VCC

GND

12345678

P10

Header 8

123456789

101112131415161718

P11

ULN2803A

12345678

910111213141516

P7

DIP 100

12345678

P5 Header 8

12345678

P8 Header 8

33k

R4Res1

27k

R5

Res1123

P13

(Log) Pot

GND

VCC

GND

V5

V33

V5

12345678

P6

Nordic

GND

12345678

910111213141516

P12

ShiftReg

GND10nF

C5

Cap

V5

GNDLS1

Speaker

GND

GND

V33

SCKMISOMOSI

SCK

MISOMOSI

SCK

GND

V5

12345678

910111213141516

P4

DIP 100

1234

5678

P14

TPA301

MOSI

PB4SS

PB4SS

V5

PB0CE

PB0CE

IRQ

PB1CSN

PB1CSN

RCK

GNDV5SCKRCK

MOSI

123456789

10

P15

LCD

123

P16

POT

V5

GND

DB7DB6DB5DB4

V5

GND

DB7DB6DB5DB4

LRSLE

LRS

LE

GND

12

34 Demo

Button1

12

34 Action

Button2

10K

R1Res1

10K

R2Res1

GND

GND

V5

V5

23

1 S1

SW-SPDT

470nF

C1Cap2

470nF

C3Cap2

47uF

C2Cap2

47uF

C4Cap2

33kR6Res1

47pF

C6

Cap

.1u

C7Cap

V5

1u

C8

Cap

GND

GND

12

34 Reset

Button2GND

V510K

R8 Res1

IRQ

J2

SocketJ3

Socket

V5

V5

GND

J4

SocketJ6

SocketJ5

Socket

PadSocket

1

32

, 4

Q1

FZT758

Path

Path

GND

47nF

CB1Cap2

GND

VCC

3.3kRP

Res1

12345678

910111213141516

P17

Header 8X2A

GNDVCC

CTime

CTime

560p

CTCap

GND

VCCGND

GND

D2LED1

D3LED1

1k

RGRes1

1k

RRVCC

Green Red

Green

Red VCC

560p

CLCap

10u

CSn

CapGND

1RSn

Res1

Q2ZXMP3A13F

Path

D1

Diode 11DQ03 100p

CBPCap

GND

V5

V5

.1u

CBPACap

4.7uF

CBBCap2

12345678910

11121314151617181920

P18

Header 10X2AGND

GND

V5

12345678910

11121314151617181920

P19

Header 10X2A

V5

GND

GND

GND

560p

CAtCap

.1u

CSrCap

.1u

CDaCap

GND

.1u

CLcCap

GND

.1u

CBcCap

GND

.1u

CBaCap

GND

Page 21: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

21

Figure 23: Dot-Matrix design for audience board (7.7x7.7in)

User Directions Switch the controller on and follow the onscreen directions to play the game of your choice. A switch for back light is also available. When the audience board is switch on, it is in standby mode. Press the Action or Demo button or wirelessly interact with the device. The battery charger is design for four NiMh series charge and should not be used with different charged batteries. Bill of materials (prototype) Table 1: Bill of materials for controller Part Cost per unit Quantity Total nRF24L01+ chips $19.95 2 $39.90 Graphic LCDs $25 2 $50 Button switches $0.05 14 $0.70 ATMega32A $4.00 2 $8.00 Voltage inverter $3.87 2 $7.74 Voltage regulators $0.10 4 $0.40 Resistors and capacitors $0.05 24 $1.20 PCBs $33.00 2 $66.00 Miscellaneous $40 N/A $40 $213.94

Page 22: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

22

Table 2: Bill of materials for audience board Part Cost per unit Quantity Total ULN2803a Current Sink $1.16 1 $1.16 100Ω 16 DIP Limit Resistor array $0.60 2 $1.20 74HC595 8bit Shift Register $1.50 1 $1.50 74ACT541 Buffer $0.88 2 $1.76 Green-Red LED $0.1692 64 $10.83 10k Log Pot $0.96 1 $0.96 TPA301D Audio amplifier $1.20 1 $1.20 LTC1661 DAC $3.38 1 $3.38 8Ω Speaker - 1 - LM2940 5V LDO Regulator - 1 - T220 Heat Sinks - 2 - 10k Potentiometer - 1 - Denistron character LCD - 1 - LTC4060 Charger Controller $7.38 1 $7.38 FDN338 MOSFET P-Ch $0.47 1 $0.47 1N5817 Schkotty diode $0.54 1 $0.54 FZT948 PNP Transistor $1.14 1 $1.14 Battery 4 Pack Holder $1.95 1 $1.95 4 NiMh Rechargeable batteries $14.96 1 $14.96 2.1mm Power Jack $0.88 1 $0.88 9V Wall Adapter $11.48 1 $11.48 Buttons $0.33 3 $0.99 nRF24L01+ module $19.95 1 $19.95 Atmega32A $5.36 1 $5.36 Various Capacitors and Resistors* - - - Total $87.09 *Miscellaneous items are <$5 in cost **Other items are <$25 total ***List does not include other costs such as wire, programmer, and printed circuit boards Responsibility Table 3: Responsibility Table

Job Delegation Audience Board

Samer Okasha

~Audio Current Drive Circuit ~DSP for Sounds and DAC interface/software ~Character LCD interface/software ~DSP for Sounds ~Multiplex array software and design ~Multiplex PCB ~Processor Board PCB

Page 23: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

23

Control

Justin Lu

~Graphic LCD interface/software ~Button interface/software ~Game software ~Wireless interface/software ~Control PCB Miscellaneous

Samer Okasha 50%|Justin Lu 50% ~Communication of information design Improvements and Future work

The current games implemented take up about 70% of the microprocessor’s memory, despite being simple, so either the code could be revised to be made more memory efficient, or another microprocessor with enhanced memory capabilities could be used. The LCD also has problems with correctly displaying pixels that lie on the boundary of the right and left halves of the LCD, and would sometimes not display anything for one of the halves, so other LCDs could be looked into, probably ones that are not split into sections that are controlled by separate pins.

Since the controllers are designed to play games, there is a lot of room for flexibility. Other than board games, more complex games could be implemented such as platformers. The controller could also have its own sound system and not have to rely on the audience board for sound. The audience board that was demonstrated had two corrections. The first was rerouting the 5V regulator after the path circuit and the other was heat sinking the charger transistor by improvising with 3 parallel transistors and a large mounted heat sink. The transistor PCB heat sink was neglected and should have 4 square inches of solder mask. The other corrections are minor but should be made which include a redundant 3.3V regulator for the wireless module and an inverted logarithmic potentiometer (does not have the desired exponential response). While measures were made to save as much memory as possible, it is ultimately preference to decide how much memory is absorbed by sound effects over musical scripts. The dot matrix also can be made to work better in brightly lit rooms. Minor improvements to the PCB such as trace thickness for ground and vcc could also be made. For higher current, different buffers and a parallel configuration of 2 ULN2903 can be done. Since the battery charger puts such strain on heat sinking and board design, it would be best to leave it out and utilize a 3 way switch between off, 6V adapter, and 4-AA battery pack (compatible with Alkaline or rechargeable in drop out mode). While a larger memory microprocessor would provide more software opportunity, a FPGA or capable device for mp3 player capability would far more improve the design.

Page 24: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

24

Project Schedule Table 4: Gnatt Chart Weeks 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Planning Procurement of parts Audience board setup Game programming Testing and debugging

References Source Code for Graphic LCD driver https://ccrma.stanford.edu/courses/250a/docs/avrlib/html/files.html Datasheet for LCD driver http://www.newhavendisplay.com/app_notes/KS0108.pdf Datasheet for LCD http://www.newhavendisplay.com/specs/NHD-12864MZ-FSW-GBW-L.pdf Datasheet for voltage inverter http://datasheets.maxim-ic.com/en/ds/ICL7662-Si7661.pdf Tutorial on how to use the Nordic transceivers http://www.diyembedded.com/tutorials/nrf24l01_0/nrf24l01_tutorial_0.pdf nRF24L01+ datasheet http://www.sparkfun.com/datasheets/Wireless/Nordic/nRF24L01P_Product_Specification_1_0.pdf Sound effects http://www.partnersinrhyme.com/pir/PIRsfx.shtml Appendices The following is the MATLAB process code to generate the sound files. [Clack, fs1, nbits] = wavread( 'pcmouseclick2.wav' ); [Swoosh, fs2, nbits] = wavread( 'Arrow_Swoosh.wav' ); [Static, fs3, nbits] = wavread( 'ESPARK1.wav' ); [Dies, fs4, nbits] = wavread( 'headchop.wav' ); [Explode, fs5, nbits] = wavread( 'bomb.wav' ); [Siren, fs6,nbits]=wavread( 'police1.wav' ); [Thundera, fs7, nbits]=wavread( 'thundra.wav' ); [Thunderb, fs7, nbits]=wavread( 'thundrb.wav' ); dowhat=4; if dowhat==0 %22050 Dies=Dies'; MM=length(Dies); ff=[0:(length(Dies)-1)]/(length(Dies)-1)*fs4-fs4/2; fT=fftshift(fft(Dies-mean(Dies))); plot(ff,abs(fT)) t=ff/fs4; RR=[zeros(1,1600) (1+cos(-pi:pi/4000:0))/2]; wl= MM -2*length(RR);

Page 25: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

25

Filter= [RR ones(1,wl) fliplr(RR)]; plot(Filter) New=real(ifft(fftshift(Filter.*fT))); wavwrite(New,fs4,nbits, 'num1' ) Sup=[(1+cos(0:pi/4000:pi))/2 zeros(1,1000)]; Sup=[ones(1,6500-length(Sup)) Sup]; New2=New(1:1.3781:end); length(New2) New2=New2(1:6500); New2=New2/max(abs(New2)); figure(2);plot(New2) New2=New2.*Sup; New2=New2(1:4600);figure(3);plot(Ne w2) wavwrite(New2,16000,nbits, 'num2' ) New2I=round(255*(New2+1)/2); wr=reshape(New2I,50,92)'; dlmwrite( 'Dies' ,wr) end if dowhat ==1 Clack2=Clack(1:1600)'-mean(Clack(1:1600)); Clack2= Clack2/max(abs(Clack2)); Clack2= round(255*(Clack2+1)/2); wr=reshape(Clack2,50,32)'; dlmwrite( 'Check' ,wr) end if dowhat==2 Explode2=Explode(1:10000)'-mean(Explode(1:10000 )); Explode2= Explode2/max(abs(Explode2)); %250! Sup=[(1+cos(0:pi/2000:pi))/2 zeros(1,3500)]; Sup=[ones(1,10000-length(Sup)) Sup]; Explode2=Explode2.*Sup; Explode2=Explode2(1:6500); Explode2= round(255*(Explode2+1)/2); wr=reshape(Explode2,50,130)'; dlmwrite( 'Explode' ,wr) end if dowhat==3 Siren2=Siren(1:1700)'-mean(Siren(1:1700)); %137 Siren2= Siren2/max(abs(Siren2)); %wavwrite(Siren2,11050,nbits, 'send') Siren2= round(255*(Siren2+1)/2); wr=reshape(Siren2,50,34)'; dlmwrite( 'Siren' ,wr) end Reference Code ********GLCD functions written for game (added to glcd.c)********* void glcdCircleFill(u08 xcenter, u08 ycenter, u08 radius) //displays a filled circle int tswitch, y, x = 0; unsigned char d; d = ycenter - xcenter; y = radius; tswitch = 3 - 2 * radius; while (x <= y) for(int j=0;j<=x;j++) for(int k=0; k<=y;k++) glcdSetDot(xcenter + j, ycenter + k); glcdSetDot(xcenter + j, ycenter - k); glcdSetDot(xcenter - j, ycenter + k); glcdSetDot(xcenter - j, ycenter - k); glcdSetDot(ycenter + k - d, ycenter + j); glcdSetDot(ycenter + k - d, ycenter - j); glcdSetDot(ycenter - k - d, ycenter + j); glcdSetDot(ycenter - k - d, ycenter - j); if (tswitch < 0) tswitch += (4 * x + 6); else tswitch += (4 * (x - y) + 10); y--; x++;

void glcdCircleClear(u08 xcenter, u08 ycenter, u08 radius) //clear a filled circle area int tswitch, y, x = 0; unsigned char d; d = ycenter - xcenter; y = radius; tswitch = 3 - 2 * radius; while (x <= y) for(int j=0;j<=x;j++) for(int k=0; k<=y;k++) glcdClearDot(xcenter + j, ycenter + k); glcdClearDot(xcenter + j, ycenter - k); glcdClearDot(xcenter - j, ycenter + k); glcdClearDot(xcenter - j, ycenter - k); glcdClearDot(ycenter + k - d, ycenter + j); glcdClearDot(ycenter + k - d, ycenter - j); glcdClearDot(ycenter - k - d, ycenter + j); glcdClearDot(ycenter - k - d, ycenter - j); if (tswitch < 0) tswitch += (4 * x + 6); else tswitch += (4 * (x - y) + 10); y--; x++;

Page 26: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

26 void glcdCircleC(u08 xcenter, u08 ycenter, u08 radius) //clear circle int tswitch, y, x = 0; unsigned char d; d = ycenter - xcenter; y = radius; tswitch = 3 - 2 * radius; while (x <= y) glcdClearDot(xcenter + x, ycenter + y); glcdClearDot(xcenter + x, ycenter - y); glcdClearDot(xcenter - x, ycenter + y); glcdClearDot(xcenter - x, ycenter - y); glcdClearDot(ycenter + y - d, ycenter + x); glcdClearDot(ycenter + y - d, ycenter - x); glcdClearDot(ycenter - y - d, ycenter + x); glcdClearDot(ycenter - y - d, ycenter - x); if (tswitch < 0) tswitch += (4 * x + 6); else tswitch += (4 * (x - y) + 10); y--; x++; void glcdRectangleC(u08 x, u08 y, u08 a, u08 b) //clear rectangle unsigned char j; for (j = 0; j < a; j++) glcdClearDot(x, y + j); glcdClearDot(x + b - 1, y + j); for (j = 0; j < b; j++) glcdClearDot(x + j, y); glcdClearDot(x + j, y + a - 1); void glcdRectangleC(u08 x, u08 y, u08 a, u08 b) //clear rectangle unsigned char j; for (j = 0; j < a; j++) glcdClearDot(x, y + j); glcdClearDot(x + b - 1, y + j); for (j = 0; j < b; j++) glcdClearDot(x + j, y); glcdClearDot(x + j, y + a - 1); *******Main code******* #include "KS0108.h" #include "glcd.h" #include "avrlibdefs.h" #include <avr/io.h> #include <util/delay.h> #include "global.h" #include "ks0108conf.h" #include "rprintf.h" #include "avrlibtypes.h" #include <avr/interrupt.h> #include <avr/pgmspace.h> #include "avr/eeprom.h" #define buttonpin PINA #define buttonport PORTA #define buttonddr DDRA // buttons (all on port A) #define up 3 #define down 4 #define left 5 #define right 6 #define select 2 #define cancel 1 #define reset 0 #define you 0 //used in functions that need to determine player ownership //#define you 1 //used in functions that need to determine player ownership //NORDIC PIN SETUP // CE to PB0 // CSN to PB1 //SCK to PB7 //MOSI to PB5 //MISO to PB6 //IRQ to PB3 //port A buttons //port B //port C lcd data //port D glcd volatile char vect[17]; //for transmission to audience board unsigned char check[27]; //for transmission to controller 2 //format: 0 byte start turn or game over byte, 1-24 piece row, column info, 25-26 score P1, score P2 volatile char confirm; //confirmation byte (to start checkers) unsigned int checkerstatus[24]=1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1; //denotes status of each piece, normal (1), dead (0), or king (2) //default positions //int checkerX[24]=1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8; //X position of piece (row) //int checkerY[24]=1, 3, 5, 7, 2, 4, 6, 8, 1, 3, 5, 7, 2, 4, 6, 8, 1, 3, 5, 7, 2, 4, 6, 8; //Y position of piece (column) //dummy positions, used for debugging unsigned int checkerX[24]=1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8; //X position of piece (row) unsigned int checkerY[24]=1, 3, 5, 7, 2, 4, 6, 8, 1, 3, 5, 7, 2, 4, 6, 8, 1, 3, 5, 7, 2, 4, 6, 8; //Y position of piece (column) unsigned int possiblemoveX[4]; //stores the x-coordinates for the possible moves of a piece (checkers) unsigned int possiblemoveY[4]; //stores the y-coordinates for the possible moves of a piece (checkers) unsigned int square[64]; //used for truth vector conversion, 0 if no piece, 1 if player 1, 2 if player 2 //notes //0=upper right of piece (+-) //1=lower right of piece (++) //2=upper left of piece (--) //3=lower left of piece (-+) int fourX[32]; //X position of connect four piece (row) int fourY[32]; //Y position of connect four piece (column) int fourX2[32]; //X position of connect four piece enemy (row) //1-8 int fourY2[32]; //Y position of connect four piece enemy (column) //1-8 int numpiece1; //tells how many pieces there are on the board (yours)//0-32 int numpiece2; //tells how many pieces there are on the board (not yours)//0-32 int piececol[8]; //tells how many pieces are currently in a column (range from 0-8 int othX[32]; //X position of othello piece (row) int othY[32]; //Y position of othello piece (column) //24 pieces, 1 byte per piece (holds coordinate information), 3 bytes for "king" (1 bit per piece) //loss or won byte, 1 + 3 + 24 = 28 bytes sent //format for position bytes //each nibble holds x and y information, ranges from 0-8. eg. 0x28 means x coordinate is 2 and 8 is y coordinate //board does not care about king piece unsigned int player[24]=0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1; //0 if player 1, 1 if player 2 unsigned int cursorposX=1; //ranges from 1 to 8 unsigned int cursorposY=1; //ranges from 1 to 8 unsigned int selectpiece; //used in select mode unsigned int pointsA, pointsB=0; //score volatile int txrx; //states whether you're receiving or transmitting (0 if transmitting, 1 if receiving, 2 if transmitting to //other controller) volatile int done=0; //used to track the first transmission (28 bytes) int gameover=0; //used to check whether game is finished int selected=0; //used to indicate whether a piece is currently selected or not int won=0; //did you win or lose? int yourturn=0; //is it your turn? 1 if yes, 0 if no int AI=0; //computer controlled or 2 players? //1 if comp, and 2 if 2 players

void set_TX_ADDR(); void set_RX_ADDR_0(); unsigned char SPI_trans(unsigned char); void set_CE(); void reset_CE(); void SPI_MasterInit(); void NordicInitTX(); void SPI_send2(unsigned int ,unsigned int ); void SPI_send(unsigned int ); char SPI_get(unsigned int ); //Checkers functions void checkers(); void writeChecker(int, int); void writeCheckerB(int, int); void removeChecker(int, int); void writeCursor(int, int); void removeCursor(int, int); void scanButton(); void selectmode(); int occupied(int, int); int getPiece(int, int); int CheckMove(int); int CheckJump(int); void kill(int); void invalidMove(); void tvect(); void update(); //Connect four functions int candrop(int); int drop(int); int checkFour(int, int); int main() _delay_ms(400); //Initialization Stuff //---------SET DIRECTION REGISTERS-------------------- DDRB |= 0x03; //Set CE and CSN to output PORTA &= 0x00; //reset port A DDRA &= 0x00; //Port A input //DDRD &= 0xFE; //Port D0 input //---------END SET DIRECTION REGISTERS-------------------- sei(); //global interrupt on //---------INTERRUPT ENABLE (INT2)---------------- //Falling edge will trigger this interrupt GICR |= 0x20; //External Interrupt INT2 enabled MCUCSR &= ~0x40; //INT2 enabled by falling edge SREG |= 0x80; //---------END INTERRUPT ENABLE (INT2)---------------- TCCR1B |= (1 << CS10); SPI_MasterInit(); //NordicInitTX(); glcdInit(); glcdClearScreen(); while(1) menu(); ISR(INT2_vect)//triggered by falling edge on PB2 (triggered when packet sent or packet received) done=1; if(txrx==0) //transmitting 1 byte else if(txrx==1) //receiving the confirmation byte glcdSetAddress(82, LINE1); glcdPutStr("Get!"); else if(txrx==2) //transmitting truth vector else if(txrx=3) //transmitting 27 bytes done=1; else if(txrx=4) //receiving the 27 bytes _delay_ms(100); glcdSetAddress(82, LINE1); glcdPutStr("Get!"); _delay_ms(1000); //--------------------MENU---------------------- void menu()//displays menu AI=0; glcdSetAddress(0, LINE1); glcdPutStr("CHOOSE A GAME"); glcdSetAddress(0, LINE5); glcdPutStr("Checkers"); glcdSetAddress(0, LINE6); glcdPutStr("(PRESS SELECT)"); glcdSetAddress(0, LINE7); glcdPutStr("Connect Four"); glcdSetAddress(0, LINE8); glcdPutStr("(PRESS CANCEL)"); //check for button presses scanbuttonmenu(); void scanbuttonmenu() //checks for button presses during the menu screen if(bit_is_set(PINA, select)) //checkers _delay_ms(10); while(bit_is_set(PINA, select)) //stall until button is unpressed _delay_ms(10); initrand(); glcdClearScreen();//checkers checkers(); else if(bit_is_set(PINA, cancel)) //connect four _delay_ms(10); while(bit_is_set(PINA, cancel)) //stall until button is unpressed _delay_ms(10); initrand();//connectfour AI=1; connectfour(); else if(bit_is_set(PINA, reset)) //test mode _delay_ms(10); while(bit_is_set(PINA, reset)) //stall until button is unpressed _delay_ms(10);

Page 27: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

27 else if(bit_is_set(PINA, up)) //test mode _delay_ms(10); while(bit_is_set(PINA, up)) //stall until button is unpressed _delay_ms(10); //--------------------END MENU------------------ void initrand() //seed based on timer, so different result each startup int state; static int EEMEM sstate; state = eeprom_read_dword(&sstate); sstate = TCNT1; // Check if it's unwritten EEPROM if (state == 0xffffffUL) state = 0x3242323FUL; srand(state); eeprom_write_dword(&sstate, rand()); void generateGrid() //grid covers 2/3 screen for(int j=0; j<8; j++) for(int i=0; i<=80;i++) glcdSetDot(i, j*8); //make lines (vertical) for(int j=0; j<=8; j++) for(int i=0; i<=64;i++) glcdSetDot(j*10, i); void ClearWords() //clear space for words glcdSetAddress(82, LINE1); glcdPutStr(" "); glcdSetAddress(82, LINE2); glcdPutStr(" "); glcdSetAddress(82, LINE3); glcdPutStr(" "); glcdSetAddress(82, LINE4); glcdPutStr(" "); glcdSetAddress(82, LINE5); glcdPutStr(" "); glcdSetAddress(82, LINE6); glcdPutStr(" "); //-----------------------CHECKERS STUFF------------------------------ void checkers() //game code goes on here score(); yourturn=1; //checkersinit(); done=0; //initialize grid generateGrid(); for(int e=0;e<64;e++) square[e]=0; for(int y=0;y<24;y++) if(player[y]==0) writeChecker(checkerX[y],checkerY[y]); else writeCheckerB(checkerX[y],checkerY[y]); writeCursor(cursorposX,cursorposY); while (gameover==0) //while the game is not over if(yourturn==1) //Player 1 turn //***For P1***** //comment out if programming for P2 glcdSetAddress(85, LINE1); glcdPutStr("P1"); glcdSetAddress(85, LINE2); glcdPutStr("turn"); scanButton(); //***For P1***** //***For P2***** //comment out if programming for P1 /* done=0; NordicInitRX(); _delay_ms(400); txrx=4; ClearWords(); glcdSetAddress(82, LINE1); glcdPutStr("Waiting"); while(done==0) //wait for interrupt receive27(); glcdSetAddress(82, LINE1); glcdPutStr("Get!"); glcdSetAddress(0, LINE3); //remove the current pieces on the screen remove(); //update the variables analyze(); //update the screen rewrite(); score(); ClearWords(); //Start turn stuff, get out of receive mode yourturn=0; */ //***For P2***** else //Player 2 turn //***For P1***** //comment out if programming for P2 ClearWords(); glcdSetAddress(82, LINE1);

glcdPutStr("Waiting"); NordicInitRX(); _delay_ms(400); done=0; txrx=4; while(done==0) //wait for interrupt receive27(); ClearWords(); glcdSetAddress(82, LINE1); glcdPutStr("Get!"); glcdSetAddress(0, LINE3); //remove the current pieces on the screen remove(); //update the variables analyze(); //update the screen rewrite(); score(); ClearWords(); yourturn=1; //Start turn stuff, get out of receive mode //***For P1***** //***For P2***** //comment out if programming for P1 /* glcdSetAddress(85, LINE1); glcdPutStr("P2"); glcdSetAddress(85, LINE2); glcdPutStr("turn"); scanButton(); */ //***For P2***** glcdClearScreen(); void checkersinit() //initialize variables for checkers (in case you want to play again) unsigned int checkerstatus2[24]=1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1; //denotes status of each piece, normal (1), dead (0), or king (2) unsigned int checkerA[24]=1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8; //X position of piece (row) unsigned int checkerB[24]=1, 3, 5, 7, 2, 4, 6, 8, 1, 3, 5, 7, 2, 4, 6, 8, 1, 3, 5, 7, 2, 4, 6, 8; //Y position of piece (column) volatile unsigned char g[27]=0x00, 0x00, 0x00, 0x11, 0x13, 0x15, 0x17, 0x22, 0x24, 0x26, 0x28, 0x31, 0x33, 0x35, 0x37, 0x62, 0x64, 0x66, 0x68, 0x71, 0x73, 0x75, 0x77, 0x82, 0x84, 0x86, 0x88; volatile unsigned char vectA[17]=0x01, 0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x44, 0x44, 0x11, 0x11; cursorposX=1; //ranges from 1 to 8 cursorposY=1; //ranges from 1 to 8 for(int j=0;j<24;j++) checkerstatus[j]=checkerstatus2[j]; checkerX[j]=checkerA[j]; checkerY[j]=checkerB[j]; for(int j=0;j<27;j++) check[j]=g[j]; for(int d=0;d<17;d++) vect[d]=vectA[d]; for(int n=0;n<4;n++) possiblemoveX[n]=0; possiblemoveY[n]=0; gameover=0; void writeChecker(int row, int col)//display checker piece on given row and column if(row>0 && row<=8 && col>0 && col<=8) //row and column values must range from 0 < r,c <=8 glcdCircle(10*row-5, 8*col-4, 2); else //do nothing void writeCheckerB(int row, int col)//display black checker piece on given row and column if(row>0 && row<=8 && col>0 && col<=8) //row and column values must range from 0 < r,c <=8 glcdCircleFill(10*row-5, 8*col-4, 2); else //do nothing void removeChecker(int row, int col) //removes checker on given row and column if(row>0 && row<=8 && col>0 && col<=8) glcdCircleClear(10*row-5, 8*col-4, 2); else //do nothing void writeCursor(int row, int col) //shows cursor at specified coordinate if(row>0 && row<=8 && col>0 && col<=8) glcdRectangle((10*row)-8, (8*col)-7, 7,7 ); else //do nothing void removeCursor(int row, int col) //removes cursor at specified coordinate if(row>0 && row<=8 && col>0 && col<=8) glcdRectangleC((10*row)-8, (8*col)-7, 7,7 ); else //do nothing void indicator(int row,int col) //places a marker if a piece can move to a certain location (select mode) glcdSetDot(10*row-5, 8*col-4); glcdSetDot(10*row-4, 8*col-3); glcdSetDot(10*row-4, 8*col-5); glcdSetDot(10*row-6, 8*col-3); glcdSetDot(10*row-6, 8*col-5);

Page 28: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

28 void removeindicator(int row,int col) //removes the indicator //insert marker code here // glcdClearDot(10*row-5, 8*col-4); glcdClearDot(10*row-4, 8*col-3); glcdClearDot(10*row-4, 8*col-5); glcdClearDot(10*row-6, 8*col-3); glcdClearDot(10*row-6, 8*col-5); void scanButton() //scans for button presses if(bit_is_set(PINA, up)) //move cursor up _delay_ms(10); while(bit_is_set(PINA, up)) //stall until button is unpressed _delay_ms(10); if(cursorposY>1 && cursorposY<=8) //move the cursor removeCursor(cursorposX, cursorposY); cursorposY=cursorposY-1; writeCursor(cursorposX, cursorposY); else else if(bit_is_set(PINA, down)) //move cursor down _delay_ms(10); while(bit_is_set(PINA, down)) //stall until button is unpressed _delay_ms(10); if(cursorposY>=1 && cursorposY<8) //move the cursor removeCursor(cursorposX, cursorposY); cursorposY=cursorposY+1; writeCursor(cursorposX, cursorposY); else else if(bit_is_set(PINA, left)) //move cursor left _delay_ms(10); while(bit_is_set(PINA, left)) //stall until button is unpressed _delay_ms(10); if(cursorposX>1 && cursorposX<=8) //move the cursor removeCursor(cursorposX, cursorposY); cursorposX=cursorposX-1; writeCursor(cursorposX, cursorposY); else else if(bit_is_set(PINA, right)) //move cursor right _delay_ms(10); while(bit_is_set(PINA, right)) //stall until button is unpressed _delay_ms(10); if(cursorposX>=1 && cursorposX<8)//move the cursor removeCursor(cursorposX, cursorposY); cursorposX=cursorposX+1; writeCursor(cursorposX, cursorposY); else else if(bit_is_set(PINA, select)) //select _delay_ms(10); while(bit_is_set(PINA, select)) //stall until button is unpressed _delay_ms(10); if(occupied(cursorposX,cursorposY)==1)//if there is a piece where the cursor is at //check whether piece is own player's if(player[getPiece(cursorposX,cursorposY)]!=yourturn) //if it is your piece, enter select mode selected=1; selectpiece=getPiece(cursorposX,cursorposY); selectmode(cursorposX, cursorposY); else //if not, say "not your piece" //select mode, check if the piece can move or jump another piece else //do nothing else if(bit_is_set(PINA, cancel)) //cancel if(selected==1)//if piece is selected selected=0; else //do nothing else if(bit_is_set(PINA, reset)) //debug else //none pressed //do nothing ClearWords(); void scanButtonSelect() //scans for button presses (select mode) unsigned char r[27]; unsigned int x,y,z; if(bit_is_set(PINA, up)) //move cursor up _delay_ms(10); while(bit_is_set(PINA, up)) //stall until button is unpressed

_delay_ms(10); if(cursorposY>1 && cursorposY<=8) removeCursor(cursorposX, cursorposY); cursorposY=cursorposY-1; writeCursor(cursorposX, cursorposY); else else if(bit_is_set(PINA, down)) //move cursor down _delay_ms(10); while(bit_is_set(PINA, down)) //stall until button is unpressed _delay_ms(10); if(cursorposY>=1 && cursorposY<8) removeCursor(cursorposX, cursorposY); cursorposY=cursorposY+1; writeCursor(cursorposX, cursorposY); else else if(bit_is_set(PINA, left)) //move cursor left _delay_ms(10); while(bit_is_set(PINA, left)) //stall until button is unpressed _delay_ms(10); if(cursorposX>1 && cursorposX<=8) removeCursor(cursorposX, cursorposY); cursorposX=cursorposX-1; writeCursor(cursorposX, cursorposY); else else if(bit_is_set(PINA, right)) //move cursor right _delay_ms(10); while(bit_is_set(PINA, right)) //stall until button is unpressed _delay_ms(10); if(cursorposX>=1 && cursorposX<8) removeCursor(cursorposX, cursorposY); cursorposX=cursorposX+1; writeCursor(cursorposX, cursorposY); else else if(bit_is_set(PINA, select)) //select _delay_ms(10); while(bit_is_set(PINA, select)) //stall until button is unpressed _delay_ms(10); int valid=0; int h; for(h=0;h<4;h++) //check if you landed on a possible move if(possiblemoveX[h]==cursorposX&&possiblemoveY[h]==cursorposY) valid=1; break; if (valid==1) //if a valid move was made, int e; vect[0]=0x02; //a move is made //a jump is made if the new position is two diagonal squares away //vs the old position int s=abs(cursorposY-checkerY[selectpiece]); //debug code to check s value //if jump made, delete piece if(s==2)//jump is made if s=2 if(cursorposY-checkerY[selectpiece]<0&&yourturn==1)// e=getPiece(cursorposX-1, cursorposY+1); else if(cursorposY-checkerY[selectpiece]>0 &&yourturn==1)// e=getPiece(cursorposX-1, cursorposY-1); else if(cursorposY-checkerY[selectpiece]<0 &&yourturn==0)// e=getPiece(cursorposX+1, cursorposY+1); else if(cursorposY-checkerY[selectpiece]>0 &&yourturn==0)// e=getPiece(cursorposX+1, cursorposY-1); //find what piece this is //kill piece checkerstatus[e]=0; //dead piece removeChecker(checkerX[e],checkerY[e]); //remove piece from screen checkerX[e]=0; checkerY[e]=0; //set first byte of truth vector to piece killed byte if(player[e]==0) //if player 1 vect[0]=0x03; pointsB=pointsB+2; else //if player 2 vect[0]=0x04; pointsA=pointsA+2; score(); //after this, procedure is same //remove all indicators present removeindicator(cursorposX,cursorposY); for(int g=0;g<4;g++) if(possiblemoveX[g]!=0) removeindicator(possiblemoveX[g],possiblemoveY[g]); //move the piece's position removeChecker(checkerX[selectpiece], checkerY[selectpiece]); if(player[selectpiece]==0) //player 1, write light checker writeChecker(cursorposX, cursorposY); yourturn=0; selected=0; else //player 2, write dark checker writeCheckerB(cursorposX, cursorposY); yourturn=1;

Page 29: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

29 selected=0; checkerX[selectpiece]=cursorposX; checkerY[selectpiece]=cursorposY;//update new positions //check for king piece IsKing(selectpiece); clearposmov(); //convert new positions to byte vector to transmit //transmit data to other controller selected=0; //exit select mode //end of turn tvect(); checkwin(); done=0; //TX17 bytes NordicInitTX(); _delay_ms(500); while(done==0) _delay_ms(400); transmit17(); _delay_ms(400); glcdSetAddress(85, LINE1); glcdPutStr("Sending"); glcdSetAddress(85, LINE2); glcdPutStr("17"); //update 27 byte array for(int i=0;i<24;i++) //3-26 x=checkerX[i]; y=checkerY[i]; z=16*x+y; r[i+3]=(unsigned char)z; r[1]=(unsigned char)pointsA; r[2]=(unsigned char)pointsB; //update the 27 byte array for(int q=0;q<27;q++) //3-26 check[q]=r[q]; done=0; //TX27 bytes ClearWords(); glcdSetAddress(85, LINE1); glcdPutStr("Sending"); glcdSetAddress(85, LINE2); glcdPutStr("27"); NordicInitTXcont(); _delay_ms(500); while(done==0) //transmit 27 bytes _delay_ms(400); _delay_us(10); SPI_send2(0x27, 0x7E); //Clear interrupts, RX fifo empty _delay_us(10); SPI_send2(0x20, 0x5E); //Set Power up bit, TX mode, reflect TX_DS on IRQ _delay_us(10); SPI_send(0xE1); //Flush TX FIFO reset_CSN(); _delay_us(10); SPI_trans(0xA0); for(int t=0;t<27;t++) SPI_trans(r[t]); //Write TX payload, _delay_us(10); set_CSN(); _delay_us(10); set_CE(); _delay_ms(0.2); reset_CE(); ClearWords(); glcdSetAddress(85, LINE1); glcdPutStr("Get"); glcdSetAddress(85, LINE2); glcdPutStr("27"); done=0; else cantMove(); _delay_ms(1000); ClearWords(); clearposmov(); for(int g=0;g<4;g++) if(possiblemoveX[g]!=0) removeindicator(possiblemoveX[g],possiblemoveY[g]); selected=0; else if(bit_is_set(PINA, cancel)) //cancel _delay_ms(10); while(bit_is_set(PINA, cancel)) //stall until button is unpressed _delay_ms(10); for(int g=0;g<4;g++) if(possiblemoveX[g]!=0) removeindicator(possiblemoveX[g],possiblemoveY[g]); selected=0; clearposmov(); else //none pressed //do nothing void selectmode(int X, int Y) while(selected==1) //stay in this mode as long as piece is selected for(int g=0;g<4;g++)//show possible move array glcdSetAddress(82+6*g, LINE5); debugpiece(possiblemoveX[g]); glcdSetAddress(82+6*g, LINE6); debugpiece(possiblemoveY[g]); //if(selected==0) //break; int r=getPiece(X,Y); //the piece that is selected //debug code

ClearWords(); glcdSetAddress(82, LINE1); debugpiece(r); if(CheckMove(r)==0) glcdSetAddress(82, LINE2); glcdPutStr("0"); else glcdSetAddress(82, LINE2); glcdPutStr("1"); if(CheckJump(r)==0) glcdSetAddress(82, LINE3); glcdPutStr("0"); else glcdSetAddress(82, LINE3); glcdPutStr("1"); //end debug if(CheckMove(r)==0 && CheckJump(r)==0)//Check if piece can move, a piece can move if it can do a normal move or jump an enemy piece //if piece cannot move (cannot move when it can't make a normal move or jump) //display "piece cannot move" //insert display code cantMove(); _delay_ms(1000); selected=0; //exit select mode else //if piece can move //show indicators of where you can move Ind(r); //buttons go on as usual scanButtonSelect(); int CanJump(int p) //can ANY piece belonging to the current player jump? //p is the player identifier int jum=0; if(p==0) for(int m=0;m<12;m++) //check player 1 if(CheckJump(m)==1) //0-11 is player 1 jum=1; break; else for(int w=0;w<12;w++) //check player 2 if(CheckJump(w+12)==1) //12-23 is player 2 jum=1; break; return jum; int CanMove(int p) //can ANY piece belonging to the current player move? //p is the player identifier int mov=0; if(p==0) for(int m=0;m<12;m++) //check player 1 if(CheckMove(m)==1) //0-11 is player 1 mov=1; break; else for(int w=0;w<12;w++) //check player 2 if(CheckMove(w+12)==1) //12-23 is player 2 mov=1; break; return mov; int CheckJump(int g) //can selected piece jump? int jum=0; if(player[g]==0 &&checkerstatus[g]==1)//player 1, check upper, lower right if(CheckJumpUR(g)==1||CheckJumpLR(g)==1) //if player can jump jum=1; else jum=0; else if(player[g]==1 &&checkerstatus[g]==1)//player 2, check upper, lower left if(CheckJumpUL(g)==1||CheckJumpLL(g)==1) //if player can jump jum=1; else jum=0; else if(checkerstatus[g]==2)//king piece if(CheckJumpUR(g)==1||CheckJumpLR(g)==1||CheckJumpUL(g)==1||CheckJumpLL(g)==1) //if player can jump jum=1; else jum=0; else jum=0; return jum; void debugpiece(int k)//shows the value of the piece //For debugging purposes //glcdSetAddress(90, LINE1); if(k==0) glcdPutStr("0"); else if(k==1) glcdPutStr("1"); else if(k==2)

Page 30: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

30 glcdPutStr("2"); else if(k==3) glcdPutStr("3"); else if(k==4) glcdPutStr("4"); else if(k==5) glcdPutStr("5"); else if(k==6) glcdPutStr("6"); else if(k==7) glcdPutStr("7"); else if(k==8) glcdPutStr("8"); else if(k==9) glcdPutStr("9"); else if(k==10) glcdPutStr("10"); else if(k==11) glcdPutStr("11"); else if(k==12) glcdPutStr("12"); else if(k==13) glcdPutStr("13"); else if(k==14) glcdPutStr("14"); else if(k==15) glcdPutStr("15"); else if(k==16) glcdPutStr("16"); else if(k==17) glcdPutStr("17"); else if(k==18) glcdPutStr("18"); else if(k==19) glcdPutStr("19"); else if(k==20) glcdPutStr("20"); else if(k==21) glcdPutStr("21"); else if(k==22) glcdPutStr("22"); else if(k==23) glcdPutStr("23"); else if(k==24) glcdPutStr("24"); else glcdPutStr("F"); int occupied(int row, int col) //checks whether there is a piece in the current space int q=0; //q false initially for(int r=0; r<24;r++) if(checkerX[r]==row && checkerY[r]==col) //set q to true if there is a piece in space q=1; break; return q; int getPiece(int row, int col) //returns what piece is on the desired coordinates, if no piece, return 999 int pos=999; for(int r=0; r<24;r++) if(checkerX[r]==row && checkerY[r]==col) pos=r; return pos; int CheckMove(int piece) //can this piece move?, returns an indicator of whether the piece can move or not //used to check for normal moves int mov=0; //mov =0 if piece can't move if(checkerstatus[piece]==1 && player[piece]==0 ) //player 1 piece, not king //check player1 (not king) if(occupied(checkerX[piece]+1, checkerY[piece]+1)==0 || occupied(checkerX[piece]+1, checkerY[piece]-1)==0&&checkerX[piece]+1<9) mov=1; else mov=0; //check player2 (not king) else if(checkerstatus[piece]==1 && player[piece]==1) //player 2 piece, not king if(occupied(checkerX[piece]-1, checkerY[piece]+1)==0 || occupied(checkerX[piece]-1, checkerY[piece]-1)==0&&checkerX[piece]+1>0) mov=1; else mov=0; //check kinged piece else if(checkerstatus[piece]==2) //kinged piece if(occupied(checkerX[piece]-1, checkerY[piece]+1)==0 || occupied(checkerX[piece]-1, checkerY[piece]-1)==0 || occupied(checkerX[piece]+1, checkerY[piece]+1)==0 || occupied(checkerX[piece]+1, checkerY[piece]-1)==0) mov=1; else mov=0; else mov=0; return mov; void clearposmov()//resets the contents of the possible move arrays for(int y=0;y<4;y++) possiblemoveX[y]=0; possiblemoveY[y]=0; void Ind(int piece) //can this piece move?, shows an indicator of where the piece can move //used to check for possible moves int mov=0; //mov =0 if piece can't move if(CheckJump(piece)==1) //check if piece can jump

else //checl for normal moves if(checkerstatus[piece]==1 && player[piece]==0 ) //player 1 piece, not king //check player1 (not king) if(occupied(checkerX[piece]+1, checkerY[piece]+1)==0 || occupied(checkerX[piece]+1, checkerY[piece]-1)==0) if(occupied(checkerX[piece]+1, checkerY[piece]+1)==0&&checkerX[piece]+1>0&&checkerX[piece]+1<9&&checkerY[piece]+1>0&&checkerY[piece]+1<9) indicator(checkerX[piece]+1,checkerY[piece]+1); possiblemoveX[1]=checkerX[piece]+1; possiblemoveY[1]=checkerY[piece]+1; if(occupied(checkerX[piece]+1, checkerY[piece]-1)==0&&checkerX[piece]+1>0&&checkerX[piece]+1<9&&checkerY[piece]-1>0&&checkerY[piece]-1<9) indicator(checkerX[piece]+1,checkerY[piece]-1); possiblemoveX[0]=checkerX[piece]+1; possiblemoveY[0]=checkerY[piece]-1; //check player2 (not king) else if(checkerstatus[piece]==1 && player[piece]==1) //player 2 piece, not king if(occupied(checkerX[piece]-1, checkerY[piece]+1)==0 || occupied(checkerX[piece]-1, checkerY[piece]-1)==0&&checkerX[piece]-1>0) if(occupied(checkerX[piece]-1, checkerY[piece]+1)==0&&checkerX[piece]-1<9&&checkerX[piece]-1>0&&checkerY[piece]+1>0&&checkerY[piece]+1<9) indicator(checkerX[piece]-1,checkerY[piece]+1); possiblemoveX[3]=checkerX[piece]-1; possiblemoveY[3]=checkerY[piece]+1; if(occupied(checkerX[piece]-1, checkerY[piece]-1)==0&&checkerX[piece]-1<9&&checkerX[piece]-1>0&&checkerY[piece]-1>0&&checkerY[piece]-1<9) indicator(checkerX[piece]-1,checkerY[piece]-1); possiblemoveX[2]=checkerX[piece]-1; possiblemoveY[2]=checkerY[piece]-1; //check kinged piece else if(checkerstatus[piece]==2) //kinged piece if(occupied(checkerX[piece]-1, checkerY[piece]+1)==0 || occupied(checkerX[piece]-1, checkerY[piece]-1)==0 || occupied(checkerX[piece]+0, checkerY[piece]+1)==0 || occupied(checkerX[piece]+1, checkerY[piece]-1)==0) if(occupied(checkerX[piece]+1, checkerY[piece]+1)==0) indicator(checkerX[piece]+1,checkerY[piece]+1); possiblemoveX[1]=checkerX[piece]+1; possiblemoveY[1]=checkerY[piece]+1; if( occupied(checkerX[piece]+1, checkerY[piece]-1)==0) indicator(checkerX[piece]+1,checkerY[piece]-1); possiblemoveX[0]=checkerX[piece]+1; possiblemoveY[0]=checkerY[piece]-1; if(occupied(checkerX[piece]+1, checkerY[piece]+1)==0) indicator(checkerX[piece]-1,checkerY[piece]+1); possiblemoveX[3]=checkerX[piece]-1; possiblemoveY[3]=checkerY[piece]+1; if( occupied(checkerX[piece]+1, checkerY[piece]-1)==0) indicator(checkerX[piece]-1,checkerY[piece]-1); possiblemoveX[2]=checkerX[piece]-1; possiblemoveY[2]=checkerY[piece]-1; int CheckJumpUR(int p) //Check if piece can jump another (upper right) int j=0; int enemy; if(occupied(checkerX[p]+1, checkerY[p]-1)==1 &&player[getPiece(checkerX[p]+1, checkerY[p]-1)]==yourturn) //if enemy is present on upper right enemy=getPiece(checkerX[p]+1, checkerY[p]-1); if(occupied(checkerX[enemy]+1, checkerY[enemy]-1)==0&&checkerX[enemy]+1>0&&checkerX[enemy]+1<9&&checkerY[enemy]-1>0&&checkerY[enemy]-1<9) //if enemy piece has empty spot in direction //check if enemy piece has empty spot in direction relative to player piece j=1; //show indicators, write to possible move array indicator(checkerX[enemy]+1, checkerY[enemy]-1); possiblemoveX[0]=checkerX[enemy]+1; possiblemoveY[0]=checkerY[enemy]-1; return j; int CheckJumpUL(int p) //Check if piece can jump another (upper left) int j=0; int enemy; if(occupied(checkerX[p]-1, checkerY[p]-1)==1&&player[getPiece(checkerX[p]-1, checkerY[p]-1)]==yourturn) //if enemy is present on upper right enemy=getPiece(checkerX[p]-1, checkerY[p]-1); if(occupied(checkerX[enemy]-1, checkerY[enemy]-1)==0&&checkerX[enemy]-1>0&&checkerX[enemy]-1<9&&checkerY[enemy]-1>0&&checkerY[enemy]-1<9) //if enemy piece has empty spot in direction //check if enemy piece has empty spot in direction relative to player piece j=1; //show indicators, write to possible move array indicator(checkerX[enemy]-1, checkerY[enemy]-1); possiblemoveX[2]=checkerX[enemy]-1; possiblemoveY[2]=checkerY[enemy]-1; int CheckJumpLR(int p) //Check if piece can jump another (lower right) int j=0; int enemy; if(occupied(checkerX[p]+1, checkerY[p]+1)==1&&player[getPiece(checkerX[p]+1, checkerY[p]+1)]==yourturn) //if enemy is present on upper right enemy=getPiece(checkerX[p]+1, checkerY[p]+1);

Page 31: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

31 if(occupied(checkerX[enemy]+1, checkerY[enemy]+1)==0&&checkerX[enemy]+1>0&&checkerX[enemy]+1<9&&checkerY[enemy]+1>0&&checkerY[enemy]+1<9) //if enemy piece has empty spot in direction //check if enemy piece has empty spot in direction relative to player piece j=1; //show indicators, write to possible move array indicator(checkerX[enemy]+1, checkerY[enemy]+1); possiblemoveX[1]=checkerX[enemy]+1; possiblemoveY[1]=checkerY[enemy]+1; int CheckJumpLL(int p) //Check if piece can jump another (lower left) int j=0; int enemy; //check if enemy piece is present if(occupied(checkerX[p]-1, checkerY[p]+1)==1&&player[getPiece(checkerX[p]-1, checkerY[p]+1)]==yourturn) //if enemy is present on upper right enemy=getPiece(checkerX[p]-1, checkerY[p]+1); if(occupied(checkerX[enemy]-1, checkerY[enemy]+1)==0&&checkerX[enemy]-1>0&&checkerX[enemy]-1<9&&checkerY[enemy]+1>0&&checkerY[enemy]+1<9) //if enemy piece has empty spot in direction //check if enemy piece has empty spot in direction relative to player piece j=1; //show indicators, write to possible move array indicator(checkerX[enemy]-1, checkerY[enemy]+1); possiblemoveX[3]=checkerX[enemy]-1; possiblemoveY[3]=checkerY[enemy]+1; void IsKing(int piece) //checks whether to king a piece int king=0; //check player1 piece if(player[piece]==0 && checkerX[piece]==8) //king piece if piece is on enemy's back row king=1; checkerstatus[piece]=2; pointsA=pointsA+5; score(); //check player2 piece else if(player[piece]==1 && checkerX[piece]==1) //king piece if piece is on enemy's back row king=1; checkerstatus[piece]=2; pointsB=pointsB+5; score(); else checkerstatus[piece]=1; if(king==1) ClearWords(); glcdSetAddress(85, LINE1); glcdPutStr("Kinged!"); removeChecker(checkerX[piece], checkerY[piece]); checkerX[piece]=0; checkerY[piece]=0; void tvect() //update the truth vector //Notes: two bits per square, 00 - nothing, 01 - player 1, 02 - player 2 int ind; //index for the vector int index=0; //the index for the square vector int b; //bit to write for(int r=1;r<17;r++) //clear contents of vector except first byte vect[r]=0x00; for(int y=1;y<=8;y++) for(int x=1;x<=8;x++) int ind=8*((x-1)%8)+y-1; //gives a number from 0 to 63 if(getPiece(x,y)!=999) if(player[getPiece(x,y)]==0) square[ind]=1; else if(player[getPiece(x,y)]==1) square[ind]=2; else square[ind]=0; for(int r=0;r<16;r++) //the truth vector index for(int w=0;w<4;w++) index=(4*r)+w; //0 to 63 if(square[index]==1) //player 1 //write 01 vect[r+1]|=(1<<(3-w)*2); //1 to 16 for tvector //writes 1 to bit 6 if w=0, 1 to bit 4 if w=1, //1 to bit 2 if w=2, 1 to bit 0 if w=3, else if(square[index]==2) //player 2 //write 10 vect[r+1]|=(1<<(3-w)*2+1); //1 to 16 for tvector //writes 1 to bit 7 if w=0, 1 to bit 5 if w=1, //1 to bit 3 if w=2, 1 to bit 1 if w=3, else void controllervect() //translate piece positions and statuses into 25 byte vector //set first byte (gameover, win or lose if (gameover==0 ) //if game is not over, set first byte to 0 check[0]=0x00; else if (gameover==1 &&won==1) //you win, game over check[0]=0x01; else if (gameover==1 &&won==0) //you lose, game over check[0]=0x02;

else check[0]=0x00; //set other bytes for the position of pieces for(int f=1;f<25;f++)//get each piece data void update() //after the other controller finishes transmitting and //all data received, update the arrays checkerstatus, checkerX, checkerY int num; //the index for square array for(int g=1;g<17;g++) //check 1-16 for(int s=0;s<4;s++) num=(g-1)*4+s; if(vect[g] & (1<<(3-s)*2)==1||vect[g] & (1<<(3-s)*2+1)==1) //checks bits 6 and 7 for s=0, bits 4 and 5 for s=1, bits 2 and 3 for s=2, //and bits 0 and 1 for s=3 if(vect[g] & (1<<(3-s)*2)==1) //01, player 1 square[num]=1; else //10, player 2 square[num]=2; else square[num]=0; void kill(int piece) //kill piece checkerstatus[piece]=0; //dead piece removeChecker(checkerX[piece],checkerY[piece]); //remove piece from screen checkerX[piece]=0; checkerY[piece]=0; //set first byte of truth vector to piece killed byte if(player[piece]==0) //if player 1 vect[0]=0x03; pointsB=pointsB+2; else //if player 2 vect[0]=0x04; pointsA=pointsA+2; score(); void invalidMove() //display message "Invalid move" ClearWords(); glcdSetAddress(82, LINE1); glcdPutStr("Invalid"); glcdSetAddress(95, LINE2); glcdPutStr("move."); void cantMove() //display message "Can't move" ClearWords(); glcdSetAddress(85, LINE1); glcdPutStr("Can't"); glcdSetAddress(85, LINE2); glcdPutStr("move."); glcdSetAddress(85, LINE3); glcdPutStr("there."); void youwin() //display message "You win" ClearWords(); glcdSetAddress(95, LINE1); glcdPutStr("You"); glcdSetAddress(95, LINE2); glcdPutStr("win!"); void youlose() //display message "You lose" ClearWords(); glcdSetAddress(95, LINE1); glcdPutStr("You"); glcdSetAddress(95, LINE2); glcdPutStr("lose."); void send() //display message "Sending" ClearWords(); glcdSetAddress(95, LINE1); glcdPutStr("Sending"); void cannotmove() //display message "Can't move" ClearWords(); glcdSetAddress(95, LINE1); glcdPutStr("This"); glcdSetAddress(95, LINE2); glcdPutStr("piece"); glcdSetAddress(95, LINE3); glcdPutStr("can't"); glcdSetAddress(95, LINE4); glcdPutStr("move"); void score() //displays the score //scoring system: +5 for king, +2 for kill glcdSetAddress(85, LINE7); glcdPutStr("Score"); glcdSetAddress(84, LINE8); interpret(pointsA); glcdSetAddress(98, LINE8); glcdPutStr("-"); glcdSetAddress(112, LINE8); interpret(pointsB); void interpret(int scr) //translates the score to LCD display if(scr==0) glcdPutStr("0"); else if(scr==1) glcdPutStr("1"); else if(scr==2) glcdPutStr("2"); else if(scr==3) glcdPutStr("3"); else if(scr==4) glcdPutStr("4"); else if(scr==5) glcdPutStr("5"); else if(scr==6) glcdPutStr("6"); else if(scr==7)

Page 32: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

32 glcdPutStr("7"); else if(scr==8) glcdPutStr("8"); else if(scr==9) glcdPutStr("9"); else if(scr==10) glcdPutStr("10"); else if(scr==11) glcdPutStr("11"); else if(scr==12) glcdPutStr("12"); else if(scr==13) glcdPutStr("13"); else if(scr==14) glcdPutStr("14"); else if(scr==15) glcdPutStr("15"); else if(scr==16) glcdPutStr("16"); else if(scr==17) glcdPutStr("17"); else if(scr==18) glcdPutStr("18"); else if(scr==19) glcdPutStr("19"); else if(scr==20) glcdPutStr("20"); else if(scr==21) glcdPutStr("21"); else if(scr==22) glcdPutStr("22"); else if(scr==23) glcdPutStr("23"); else if(scr==24) glcdPutStr("24"); else if(scr==25) glcdPutStr("25"); else if(scr==26) glcdPutStr("26"); else if(scr==27) glcdPutStr("27"); else if(scr==28) glcdPutStr("28"); else if(scr==29) glcdPutStr("29"); else if(scr==30) glcdPutStr("30"); else if(scr==31) glcdPutStr("31"); else if(scr==32) glcdPutStr("32"); else if(scr==33) glcdPutStr("33"); else if(scr==34) glcdPutStr("34"); void debugvector(unsigned char scr) //Used to debug wireless if(scr==0x00) glcdPutStr("0"); else if(scr==0x01) glcdPutStr("1"); else if(scr==0x11) glcdPutStr("2"); else if(scr==0x13) glcdPutStr("3"); else if(scr==0x15) glcdPutStr("4"); else if(scr==0x17) glcdPutStr("5"); else if(scr==0x22) glcdPutStr("6"); else if(scr==0x24) glcdPutStr("7"); else if(scr==0x25) glcdPutStr("8"); else if(scr==0x26) glcdPutStr("9"); else if(scr==0x28) glcdPutStr("a"); else if(scr==0x31) glcdPutStr("b"); else if(scr==0x33) glcdPutStr("c"); else if(scr==0x35) glcdPutStr("d"); else if(scr==0x37) glcdPutStr("e"); else if(scr==0x62) glcdPutStr("f"); else if(scr==0x64) glcdPutStr("g"); else if(scr==0x66) glcdPutStr("h"); else if(scr==0x68) glcdPutStr("i"); else if(scr==0x71) glcdPutStr("j"); else if(scr==0x73) glcdPutStr("k"); else if(scr==0x75) glcdPutStr("l"); else if(scr==0x77) glcdPutStr("m"); else if(scr==0x81) glcdPutStr("n"); else if(scr==0x82) glcdPutStr("o"); else if(scr==0x84) glcdPutStr("p"); else if(scr==0x86) glcdPutStr("q"); else if(scr==0x87) glcdPutStr("r"); else if(scr==0x89) glcdPutStr("s"); else if(scr==0x88) glcdPutStr("t"); else glcdPutStr("x"); int checkwin() //checks to see if win condition is met and by whom //returns 0 if not met, 1 if player 1 wins, or 2 if player 2 wins unsigned int won=0; if(pointsA>=20||pointsB>=20) if(pointsA>=20) won=1; gameover=1; vect[0]=0x05; glcdSetAddress(85, LINE1); glcdPutStr("P1 wins!"); _delay_ms(2000); else

won=2; gameover=1; vect[0]=0x06; glcdSetAddress(85, LINE1); glcdPutStr("P2 wins!"); _delay_ms(2000); return won; void vect27()//update the 27 byte vector unsigned int x,y,z; for(int i=0;i<24;i++) //3-26 x=checkerX[i]; y=checkerY[i]; z=16*x+y; check[i+3]=(unsigned char)z; check[1]=(unsigned char)pointsA; check[2]=(unsigned char)pointsB; void analyze() //analyze the 27 byte vector unsigned int decode; //update the checkerX and checkerY vectors for(int i=0;i<24;i++) //3 to 26 //checkerX and checkerY go from 0 to 23 //extract checkerX and checkerY checkerX[i]=(check[i+3]>>4)%16; checkerY[i]=check[i+3]%16; pointsA=(unsigned int)check[1]; pointsB=(unsigned int)check[2]; void rewrite()//rewrites the grid for(int y=0;y<24;y++) if(player[y]==0) writeChecker(checkerX[y],checkerY[y]); else writeCheckerB(checkerX[y],checkerY[y]); void remove()//removes all pieces from the grid for(int h=0;h<24;h++) if(checkerX[h]>=1&&checkerX[h]<=8&&checkerY[h]<=8&&checkerY[h]>=1) removeChecker(checkerX[h],checkerY[h]); void endturn() //extra stuff that goes on at the end of a turn //update the truth vector, update the 27 byte vector tvect(); //transmit the truth vector _delay_ms(500); NordicInitTXcont(); //set to TX27 mode _delay_ms(1000); done=0; while(done==0) transmit17(); //transmit the 27 byte vector done=0; while(done==0) transmit27(); done=0; txrx=4; //go to receive mode NordicInitRX(); //set to RX27 mode yourturn=0; //opponent's turn void beginturn() //stuff that goes on at the start of a turn, //this is after the 27 byte vector is received //decrypt the vector, checkerX and checkerY are updated analyze(); //update the positions of the pieces and points remove(); rewrite(); score(); //initialize to TX17 mode //-----------------------END CHECKERS STUFF------------------------------ //-------------------------CONNECT FOUR STUFF----------------------------- void connectfour() //reset all variables gameover=0; numpiece1=0; numpiece2=0; vect[0]=0x08; NordicInitTX(); //get ready to send 17 bytes _delay_ms(500); while(done==0) if(done==1) break; _delay_ms(400); transmit17(); for(int g=0;g<32;g++) fourX[g]=0; fourY[g]=0; fourX2[g]=0; fourY2[g]=0; for(int r=0;r<8;r++)

Page 33: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

33 piececol[r]=0; for(int e=0;e<64;e++) square[e]=0; glcdClearScreen(); yourturn=1; generateGrid(); writeCursor(cursorposX, cursorposY); //compMove(); while(gameover==0) //play the game as long as the game is not over yet if(gameover==1) break; if(yourturn==1) glcdSetAddress(85, LINE1); glcdPutStr("Your"); glcdSetAddress(85, LINE2); glcdPutStr("turn"); scan4(); //check for button presses else ClearWords(); glcdSetAddress(85, LINE1); glcdPutStr("Not yet"); compMove(); void scan4() //check for button presses, only left, right, select used here if(bit_is_set(PINA, left)) //move cursor left _delay_ms(10); while(bit_is_set(PINA, left)) //stall until button is unpressed _delay_ms(10); if(cursorposX>1 && cursorposX<=8) removeCursor(cursorposX, cursorposY); cursorposX=cursorposX-1; writeCursor(cursorposX, cursorposY); else else if(bit_is_set(PINA, right)) //move cursor right _delay_ms(10); while(bit_is_set(PINA, right)) //stall until button is unpressed _delay_ms(10); if(cursorposX>=1 && cursorposX<8) removeCursor(cursorposX, cursorposY); cursorposX=cursorposX+1; writeCursor(cursorposX, cursorposY); else else if(bit_is_set(PINA, select)) //select //if column selected, ask for confirmation //ask player for confirmation //if the column is full if(candrop(cursorposX)==0) //if you cannot drop a piece on the column ClearWords(); invalidMove(); _delay_ms(500); ClearWords(); else _delay_ms(10); while(bit_is_set(PINA, select)) //stall until button is unpressed _delay_ms(10); askconfirm(); //confirm mode int candrop(int X) //can a piece be dropped on this column? int can=1; if(piececol[X-1]==8)//if there are 8 pieces in a column, can't drop can=0; return can; int occupied4(int X, int Y) //Checks whether the current square is occupied int occ=0; for(int h=0;h<32;h++) if((fourX[h]==X&&fourY[h]==Y)||(fourX2[h]==X&&fou rY2[h]==Y)) occ=1; break; return occ; int drop(int X) //drops a piece on column, returns the row where the piece is dropped //checks the column for the lowest empty space int k; vect[0]=0x02; for( k=0;k<8;k++) //use 8-k, ranges from 8 to 1 if(occupied4(X, 8-k)==1)//if a piece exists //skip else //if the lowest empty piece is found piececol[X-1]++; //increment the column counter; //check if it is your turn if(yourturn==1) //your piece writeChecker(X,8-k); //displays piece on screen yourturn=0; fourX[numpiece1]=X; //update array fourY[numpiece1]=8-k; numpiece1++; //

if(checkFour(X,8-k)==1)//if connect four found gameover=1; ClearWords(); _delay_ms(500); youwin(); vect[0]=0x05; while(done==0) if(done==1) break; _delay_ms(400); transmit17(); done=0; vect[0]=0x07; _delay_ms(4000); glcdClearScreen(); else //not your piece writeCheckerB(X,8-k); //displays piece on screen yourturn=1; fourX2[numpiece2]=X; //update array fourY2[numpiece2]=8-k; numpiece2++; if(checkFour(X,8-k)==1)//if connect four found gameover=1; ClearWords(); youlose(); _delay_ms(500); vect[0]=0x06; while(done==0) if(done==1) break; _delay_ms(400); transmit17(); done=0; vect[0]=0x07; //transmit17(); _delay_ms(4000); glcdClearScreen(); //save the position of the new piece to the player array break; //drop only once //update and transmit vector glcdSetAddress(85, LINE1); //glcdPutStr("Sending"); tvectconnect(); //update square arrays, form the truth vector NordicInitTX(); //get ready to send 17 bytes _delay_ms(500); while(done==0) if(done==1) break; _delay_ms(400); transmit17(); ClearWords(); glcdSetAddress(85, LINE1); glcdPutStr("Sent!"); _delay_ms(500); ClearWords(); //checkvect(); done=0; // ClearWords(); return 8-k; int checkFour(int X, int Y) //checks for 4 in a row int isfour=0; if(checkDiag(X,Y)==1||checkVert(X,Y)==1||checkHorz(X,Y)==1) isfour=1; return isfour; void checkvect()//debug code for the truth vector glcdSetAddress(0, LINE1); for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[1],(7-d)));//find the bit value for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[2],(7-d)));//find the bit value glcdSetAddress(0, LINE2); for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[3],(7-d)));//find the bit value for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[4],(7-d)));//find the bit value glcdSetAddress(0, LINE3); for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[5],(7-d)));//find the bit value for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[6],(7-d)));//find the bit value glcdSetAddress(0, LINE4); for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[7],(7-d)));//find the bit value for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[8],(7-d)));//find the bit value glcdSetAddress(0, LINE5); for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[9],(7-d)));//find the bit value for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[10],(7-d)));//find the bit value glcdSetAddress(0, LINE6); for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[11],(7-d)));//find the bit value for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[12],(7-d)));//find the bit value glcdSetAddress(0, LINE7); for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[13],(7-d)));//find the bit value for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[14],(7-d)));//find the bit value

Page 34: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

34 glcdSetAddress(0, LINE8); for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[15],(7-d)));//find the bit value for(int d=0;d<8;d++) debugpiece(bit_is_set(vect[16],(7-d)));//find the bit value _delay_ms(5000); int checkDiag(int X, int Y)//checks if a diagonal 4 is made int ind=0; int p= whatPlayer(X,Y); if(whatPlayer(X-1,Y-1)==p &&whatPlayer(X-2,Y-2)==p &&whatPlayer(X-3,Y-3)==p ) ind=1; if(whatPlayer(X-1,Y+1)==p &&whatPlayer(X-2,Y+2)==p &&whatPlayer(X-3,Y+3)==p ) ind=1; if(whatPlayer(X+1,Y+1)==p &&whatPlayer(X+2,Y+2)==p &&whatPlayer(X+3,Y+3)==p ) ind=1; if(whatPlayer(X+1,Y-1)==p &&whatPlayer(X+2,Y-2)==p &&whatPlayer(X+3,Y-3)==p ) ind=1; if(whatPlayer(X-1,Y-1)==p &&whatPlayer(X-2,Y-2)==p &&whatPlayer(X+1,Y+1)==p ) ind=1; if(whatPlayer(X-1,Y-1)==p &&whatPlayer(X+2,Y+2)==p &&whatPlayer(X+1,Y+1)==p ) ind=1; if(whatPlayer(X-1,Y+1)==p &&whatPlayer(X+2,Y-2)==p &&whatPlayer(X+1,Y-1)==p ) ind=1; if(whatPlayer(X-1,Y+1)==p &&whatPlayer(X-2,Y+2)==p &&whatPlayer(X+1,Y-1)==p ) ind=1; return ind; int checkVert(int X, int Y) //checks if a vertical 4 made int p= whatPlayer(X,Y);//finds player int ind=0; if(whatPlayer(X-1,Y)==p &&whatPlayer(X-2,Y)==p &&whatPlayer(X-3,Y)==p ) ind=1; if(whatPlayer(X+1,Y)==p &&whatPlayer(X+2,Y)==p &&whatPlayer(X+3,Y)==p ) ind=1; if(whatPlayer(X+1,Y)==p &&whatPlayer(X+2,Y)==p &&whatPlayer(X-1,Y)==p ) ind=1; if(whatPlayer(X+1,Y)==p &&whatPlayer(X-2,Y)==p &&whatPlayer(X-1,Y)==p ) ind=1; return ind; int checkHorz(int X, int Y) int p= whatPlayer(X,Y); int ind=0; if(whatPlayer(X,Y+1)==p &&whatPlayer(X,Y+2)==p &&whatPlayer(X,Y+3)==p ) ind=1; if(whatPlayer(X,Y-1)==p &&whatPlayer(X,Y-2)==p &&whatPlayer(X,Y-3)==p ) ind=1; if(whatPlayer(X,Y+1)==p &&whatPlayer(X,Y+2)==p &&whatPlayer(X,Y-1)==p ) ind=1; return ind; if(whatPlayer(X,Y+1)==p &&whatPlayer(X,Y-2)==p &&whatPlayer(X,Y-1)==p ) ind=1; return ind; return ind; int whatPiece(int X, int Y) //returns the index of the piece in the coordinates //return 999 if no piece int e; int m =999; for(e=0;e<32;e++) if(fourX[e]==X&&fourY[e]==Y) m=e; break; for(e=0;e<32;e++) if(fourX2[e]==X&&fourY2[e]==Y) m=e; break; return m; int whatPlayer(int X, int Y) //returns the owner of the piece //return 2 if no piece, 0 if yours, or 1 if opponents int e; int m =2; for(e=0;e<32;e++)//check player 1 if(fourX[e]==X&&fourY[e]==Y) m=0; return m; for(e=0;e<32;e++) if(fourX2[e]==X&&fourY2[e]==Y) m=1; return m; return m; int random() //call this function if time is up, select a random # from 0 to 7 int x=rand(800); x=x%8; return x; void askconfirm() //ask for confirmation when column is selected int isdone=0; cont(); while(isdone!=1) //stay in confirm mode until select or cancel is pressed

int t; //y-coordinate if(bit_is_set(PINA, select)) // player is sure _delay_ms(10); while(bit_is_set(PINA, select)) //stall until button is unpressed _delay_ms(10); drop(cursorposX); isdone==1; //check if connect four is made //after turn is made, check if win condition is met, update tvector, variables //convert to tvector, transmit the bytes (need code) //vect[0]=0x02; break; if(bit_is_set(PINA, cancel)) // player declines _delay_ms(10); while(bit_is_set(PINA, cancel)) //stall until button is unpressed _delay_ms(10); isdone==1; break; ClearWords(); void compMove() //computer makes a move int m; int y=random(); //random column y++; while(candrop(y)==0) //if you cannot drop a piece on the column, pick a new number y=random(); //random column y++; m=drop(y); //check if connect four is made yourturn==1; //turn over to player void cont() //display message "Are you sure? Press select to proceed" ClearWords(); glcdSetAddress(85, LINE1); glcdPutStr("Are you"); glcdSetAddress(85, LINE2); glcdPutStr("sure?"); void tvectconnect() //update the truth vector //call this function after every turn //Notes: two bits per square, 00 - nothing, 01 - player 1, 02 - player 2 unsigned int ind; //index for the vector unsigned int a=0; unsigned int index=0; //the index for the square vector unsigned int b; //bit to write for(int r=1;r<17;r++) //clear contents of vector except first byte vect[r]=0x00; for(int x=1;x<=8;x++) for(int y=1;y<=8;y++) int ind=8*((x-1))+y-1; //gives a number from 0 to 63 if(whatPlayer(y,x)==0) //player 1 square[ind]=1; else if(whatPlayer(y,x)==1) //player 2 square[ind]=2; else //no piece square[ind]=0; for(int r=0;r<16;r++) //the truth vector index for(int w=0;w<4;w++) index=(4*r)+w; //0 to 63 if(square[index]==1) //player 1 //write 01 vect[r+1]|=(1<<(3-w)*2); //1 to 16 for tvector //writes 1 to bit 6 if w=0, 1 to bit 4 if w=1, //1 to bit 2 if w=2, 1 to bit 0 if w=3, else if(square[index]==2) //player 2 //write 10 vect[r+1]|=(1<<((3-w)*2+1)); //1 to 16 for tvector //writes 1 to bit 7 if w=0, 1 to bit 5 if w=1, //1 to bit 3 if w=2, 1 to bit 1 if w=3, else //-------------------------END CONNECT FOUR STUFF------------------------- ///////////WIRELESS STUFF//////////////// void set_TX_ADDR() PORTB &= 0xFD; SPI_trans(0x30); for(int k=0;k<5;k++) SPI_trans(0xE7); PORTB |= 0x02; void set_RX_ADDR() PORTB &= 0xFD; SPI_trans(0x2A); for(int k=0;k<5;k++) SPI_trans(0xE7); PORTB |= 0x02;

Page 35: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

35 void set_TX_ADDR2() PORTB &= 0xFD; SPI_trans(0x30); //Set TX_ADDR = RX_ADDR_P0 SPI_trans(0xB3); SPI_trans(0xB3); SPI_trans(0xB3); SPI_trans(0xB3); SPI_trans(0xB3); PORTB |= 0x02; void set_RX_ADDR2() PORTB &= 0xFD; SPI_trans(0x2A); SPI_trans(0xB3); SPI_trans(0xB3); SPI_trans(0xB3); SPI_trans(0xB3); SPI_trans(0xB3); PORTB |= 0x02; void transmit17() //transmit the truth vector SPI_send2(0x27, 0x7E); //Clear interrupts, RX fifo empty // _delay_us(20); SPI_send2(0x20, 0x5A); //Set Power up bit, TX mode // _delay_us(20); SPI_send(0xE1); //Flush TX FIFO // _delay_us(20); reset_CSN(); // _delay_us(10); SPI_trans(0xA0); for(int t=0;t<17;t++) SPI_trans(vect[t]); //Write TX payload, _delay_us(10); set_CSN(); // _delay_us(10); set_CE(); _delay_us(130); reset_CE(); void receive17() //receive payload reset_CSN(); _delay_us(20); SPI_trans(0x61); _delay_us(10); //m = SPI_trans(0); //debug with glcd for(int c=0;c<17;c++) vect[c]=SPI_trans(0); _delay_us(10); set_CSN(); _delay_us(20); reset_CSN(); SPI_trans(0xE2); _delay_us(10); set_CSN(); _delay_us(20); reset_CSN(); _delay_us(20); SPI_trans(0x27); _delay_us(20);//clear interrupts SPI_trans(0x40); _delay_us(20); set_CSN(); void receive27() //receive payload reset_CSN(); _delay_us(20); SPI_trans(0x61); _delay_us(10); for(int c=0;c<27;c++) check[c]=SPI_trans(0); _delay_us(10); set_CSN(); _delay_us(20); reset_CSN(); SPI_trans(0xE2); _delay_us(10); set_CSN(); _delay_us(20); reset_CSN(); _delay_us(20); SPI_trans(0x27); _delay_us(20);//clear interrupts SPI_trans(0x40); _delay_us(20); set_CSN(); void transmit27() _delay_us(10); SPI_send2(0x27, 0x7E); //Clear interrupts, RX fifo empty _delay_us(10); SPI_send2(0x20, 0x5E); //Set Power up bit, TX mode, reflect TX_DS on IRQ _delay_us(10); SPI_send(0xE1); //Flush TX FIFO reset_CSN(); _delay_us(10); SPI_trans(0xA0); for(int t=0;t<27;t++) SPI_trans(check[t]); //Write TX payload, _delay_us(10);

set_CSN(); _delay_us(10); set_CE(); _delay_ms(0.2); reset_CE(); void set_CE() PORTB |=0x01; void reset_CE() PORTB &= 0xFE; void set_CSN() PORTB |=0x02; void reset_CSN() PORTB &= 0xFD; //-------------------------------------------- void NordicInitTX() //initialize for transmitter (controller to board) //17 bytes reset_CE(); SPI_send2(0x20, 0x00); //Mask Interrupts, CRC enabled SPI_send2(0x24, 0x00); //Disable retransmit SPI_send2(0x22, 0x01); //enable data pipe 0 SPI_send2(0x23, 0x03); //set address width to 5 bytes SPI_send2(0x26, 0x07); //RF output power 0 dBm SPI_send2(0x31, 0x11); //Data payload width 17 bytes SPI_send2(0x25, 0x42); //set RF channel (default is 2, can be from 0 to 83 decimal) set_TX_ADDR(); //sets Transmit address to E7E7E7E7E7 (default SPI_send2(0x21, 0x00); //disable auto-ACK, change 0x00 to 0x01 to enable void NordicInitRX() //initialize for receiver (controller to controller) //27 bytes reset_CSN(); reset_CE(); //Enable RX_DR interrupt SPI_send2(0x20, 0x39); //Mask interrupts TX_DS and MAX_RT, receive mode SPI_send2(0x21, 0x00); //disable auto-ACK, change 0x00 to 0x01 to enable SPI_send2(0x23, 0x03); //set address width to 5 bytes SPI_send2(0x22, 0x01); //enable data pipe 0 SPI_send2(0x26, 0x0F); //Data Rate 1mbps, RF power 0 dBm SPI_send2(0x31, 0x1B); //Data payload width 27 bytes SPI_send2(0x25, 0x20); //set channel (0 to 83, default 2) set_RX_ADDR2(); //set to B3B3B3B3B3 SPI_send2(0x20, 0x3F); //set PWR_UP bit, enable PRIM_RX (set as RX), Disable TX_DS and MAX_RT interrupts //SPI_send2(0x20, 0x33); SPI_send2(0x21, 0x00); set_CE(); //starts RX mode _delay_us(150); //checks for packets after 130us void NordicInitTXcont() //initialize for transmitter (27bytes) (controller to controller) //27 bytes reset_CE(); SPI_send2(0x20, 0x00); //Mask Interrupts, CRC enabled SPI_send2(0x24, 0x00); //Disable retransmit SPI_send2(0x22, 0x01); //enable data pipe 0 SPI_send2(0x23, 0x03); //set address width to 5 bytes SPI_send2(0x26, 0x0F); //RF output power 0 dBm SPI_send2(0x31, 0x1B); //Data payload width 27 bytes SPI_send2(0x25, 0x20); //set RF channel (default is 2, can be from 0 to 83 decimal) set_TX_ADDR2(); //sets Transmit address to B3B3B3B3B3 SPI_send2(0x21, 0x00); //disable auto-ACK, change 0x00 to 0x01 to enable //-------------------------------------------- void SPI_MasterInit() //SPCR &= 0x00; /* Set MOSI, SS and SCK output, all others input */ DDRB = (1<<DDB5)|(1<<DDB7)|(1<<DDB4)|(1<<DDB0)|(1<<DDB1)|(1<<DDB3); /* Enable SPI, Master, set clock rate fck/16 */ SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); ; //-------------------------------------------- void SPI_send(unsigned int data) PORTB &= 0xFD; SPDR = data; //sends data while(!(SPSR & (1<<SPIF))); // wait for transmission to finish PORTB |= 0x02; unsigned char SPI_trans(unsigned char data) SPDR = data; //sends data while(!(SPSR & (1<<SPIF))); // wait for transmission to finish return SPDR; //-------------------------------------------- void SPI_send2(unsigned int reg1, unsigned int data2) PORTB &= 0xFD; //set CSN low, lets it know it is about to receive spi data SPDR = reg1; //sends data while(!(SPSR & (1<<SPIF))); // wait for transmission to finish _delay_us(10); SPDR = data2; //sends data while(!(SPSR & (1<<SPIF))); // wait for transmission to finish _delay_us(10); PORTB |= 0x02; //transmission done, set CSN back to high

Audience Board Code #include <avr/io.h> #include <avr/pgmspace.h> //use to store sounds in flash #include <avr/eeprom.h> //eeprom saving #include <util/delay.h>

#include <avr/interrupt.h> /*#include <avr/wdt.h> #define soft_reset() \

Page 36: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

36 do \ \ wdt_enable(WDTO_15MS); \ for(;;) \ \ \ while(0) void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3"))); void wdt_init(void) MCUSR = 0; wdt_disable(); return; */ //interupt access variables volatile char plays = 0x00; //protocol from wirelessinfo volatile char playsdem = 0x00; //protocol from wirelessinfo volatile char func = 0x00; //volatile bool pass = 0; volatile char d[17] =0x00, 0x30,0x31,0x32,0x33,0,0,0,0,0,0,0,0,0,0,0,0; //17 bytes from game info, first byte represents a function/sound, next 16bytes are for LED truth statements volatile char stuff[17]=0x3F, 0x34,0x35,0x36,0x37,0xFF,0x3F,0,0,0,0,0,0,0,0,0,0; volatile char ledvectA[8]=0,0,0,0,0,0,0,0;//0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,;//0xFF,0x41,0x41,0x41,0x41,0x41,0x14,0xFF; volatile char ledvectB[8]=0,0,0,0,0,0,0,0;//0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,;//0xFF,0xAA,0x80,0xA8,0x80,0x80,0x80,0xFF; volatile char row =0x01; const double time = 1; // Note: quick load 2 cycle ram, 3 cycle flash, 4 cycle eeprom volatile uint8_t start1[5]=0,1,2,3,4; volatile uint8_t start2[5]=5,6,7,0,1; volatile uint8_t start3[5]=2,3,4,5,6; volatile uint8_t start4[5]=7,0,1,2,3; volatile uint8_t start5[5]=4,5,6,7,0; volatile uint8_t start6[5]=1,2,3,4,5; volatile uint8_t start7[5]=6,7,0,1,2; volatile uint8_t start8[5]=3,4,5,6,7; //create tone //Matlab code /*Ts=1/100/100; t=0:Ts:(1/100-Ts); y=2.5*(sin(t*2*pi*100))+2.5; plot(t,y) yh=y/5*255; ym=round(yn); yhex=reshpe(dec2hex(round(yh))',1,2*100);*/ /* Define Sounds 8BIT const char tone[] PROGMEM=; */ /*-------------------------Timer--------------------// TCCR1B |= (1 << WGM12); //CTC mode OCR1A =999; //1ms timer TCCR1B |= (1 << CS11); //fck/8 //if (TIFR & (1 << OCF1A)) check //TIFR = (1 << OCF1A); clear //TCNT1 = 0; reset timer */ //-------------------------------------------------------------------// //------------------------Alphanumeric Driver------------------------// //-------------------------------------------------------------------// // 0-9 numbers, 10-35 letters, 36-39 ?.-fill symbols // 0AKU 1BLV 2CMW 3DNX 4EOY 5FPZ 6GQ? 7HR. 8IS- 9JT| const char row2D[40] PROGMEM = 0xFF,0x03,0xFF,0xFF,0xCC,0xFF,0xFF,0xFF,0xFF,0xFF, 0x3C,0xFC,0x3C,0xFC,0xFF,0xFF,0x3C,0xC3,0xFF,0xFF, 0xC3,0xC0,0xC3,0xC3,0x3C,0xFC,0x3C,0xFC,0x3F,0xFF, 0xC3,0xC3,0xC3,0xC3,0xC3,0xFF,0xFF,0x00,0x00,0xFF; const char row3D[40] PROGMEM = 0xC3,0x03,0x03,0x03,0xCC,0xC0,0xC0,0x03,0xC3,0xC3, 0xC3,0xC3,0xC3,0xC3,0xC0,0xC0,0xC3,0xC3,0x3C,0x0C, 0xCC,0xC0,0xFF,0xF3,0xC3,0xC3,0xC3,0xC3,0xC0,0x3C, 0xC3,0xC3,0xC3,0xC3,0xC3,0x03,0xC3,0x00,0x00,0xFF; const char row4D[40] PROGMEM = 0xC3,0x03,0xFF,0x3F,0xFF,0xFF,0xFF,0x03,0xFF,0xFF, 0xFF,0xFC,0xC0,0xC3,0xFC,0xFC,0xC0,0xFF,0x3C,0x0C, 0xF0,0xC0,0xC3,0xCF,0xC3,0xFC,0xC3,0xFC,0x3C,0x3C, 0xC3,0xC3,0xC3,0x3C,0x3C,0x0C,0x0F,0x00,0xFF,0xFF; const char row5D[40] PROGMEM = 0xC3,0x03,0xC0,0x03,0x0C,0x03,0xC3,0x03,0xC3,0x03, 0xC3,0xC3,0xC0,0xC3,0xC0,0xC0,0xCF,0xC3,0x3C,0x0C, 0xF0,0xC0,0xC3,0xC3,0xC3,0xC0,0xC3,0xF0,0x03,0x3C, 0xC3,0x33,0xC3,0x3C,0x0C,0x30,0x30,0x00,0x00,0xFF; const char row6D[40] PROGMEM = 0xC3,0x03,0xC0,0x03,0x0C,0x03,0xC3,0x03,0xC3,0x03, 0xC3,0xC3,0xC3,0xC3,0xC0,0xC0,0xC3,0xC3,0x3C,0xCC, 0xCC,0xC0,0xC3,0xC3,0xC3,0xC0,0xCF,0xCC,0x03,0x3C, 0xC3,0x0F,0xFF,0xC3,0x0C,0xC0,0x00,0x0F,0x00,0xFF; const char row7D[40] PROGMEM = 0xFF,0x03,0xFF,0xFF,0x0C,0xFF,0xFF,0x03,0xFF,0x03, 0xC3,0xFC,0x3C,0xFC,0xFF,0xC0,0x3C,0xC3,0xFF,0x30, 0xC3,0xFF,0xC3,0xC3,0x3C,0xC0,0x3F,0xC3,0xFC,0x3C, 0x3C,0x03,0xC3,0xC3,0x0C,0xFF,0x30,0x0F,0x00,0xFF; //-------------------------------------------------------------------// //---------------------------Sound Files-----------------------------// //-------------------------------------------------------------------// char sine[10]=; char sawtooth[10]=; char bell[10]=; char square[10]=; //1550 bytes 11k const char check[] PROGMEM=127,127,127,127,127,127,127,127,127,127,128,126,128,126,127,130,120,138,122,85,109,147,140,101,111,112,90,62,62,139,161,119,110,82,98,162,155,91,75,184,170,68,97,146,151,197,177,25,128,247 ,111,79,152,169,140,150,171,185,179,116,101,160,195,193,164,124,133,176,128,116,199,170,105,154,175,137,175,153,98,166,195,145,138,162,156,143,145,131,135,160,139,134,150,137,154,153,112,124,145,145 ,151,136,127,143,150,132,147,157,105,138,148,89,153,150,83,129,143,125,128,136,129,112,139,135,127,132,123,126,128,142,139,112,111,126,120,116,118,101,109,162,135,82,131,156,128,117,118,118,122,120 ,107,119,147,127,95,118,130,111,107,115,118,115,125,126,112,122,132,115,115,125,125,116,101,111,125,111,109,120,120,115,121,118,102,115,124,114,112,119,123,113,110,120,118,109,119,116,103,124,121,107 ,124,119,90,104,131,126,110,100,113,120,105,103,110,101,104,111,107,103,117,82,142,162,29,114,182,117,59,108,255,103,42,204,58,79,232,99,78,102,136,112,110,159,59,62,154,146,73,142,132,53 ,101,97,115,92,81,92,79,171,154,104,127,107,108,101,97,99,51,94,147,77,130,171,88,121,132,105,115,130,112,100,146,89,103,180,96,99,163,112,97,142,171,122,124,147,121,104,76,104,88,57 ,124,127,75,104,150,148,147,167,166,147,152,146,139,139,118,105,111,122,113,97,115,122,112,131,133,118,126,139,129,117,127,133,105,106,134,113,114,127,116,118,115,111,105,119,118,106,112,130,137,127 ,135,138,147,130,120,128,132,149,121,95,129,145,119,154,152,116,130,90,106,177,155,135,148,99,119,173,141,135,124,137,162,137,126,145,140,129,120,98,124,143,137,130,123,162,173,141,133,128,120,115

,127,146,133,119,140,137,114,131,145,121,110,131,144,133,140,148,131,122,121,134,141,127,126,126,131,137,130,133,126,122,138,141,133,124,130,129,127,138,134,129,129,133,141,139,125,118,125,125,132,146 ,129,119,171,107,79,190,115,92,155,186,199,115,97,61,7,8,12,17,73,98,65,84,47,1,59,102,109,154,214,163,148,197,133,117,199,235,161,171,227,121,129,149,115,132,76,151,217,156,224,220 ,128,113,131,156,121,161,193,214,242,225,180,131,163,169,201,195,145,153,110,143,176,154,183,161,170,201,197,200,198,198,173,139,146,134,120,160,191,190,204,198,164,132,125,143,127,137,163,158,160,175 ,191,158,149,139,135,172,119,209,198,44,170,139,127,157,100,166,86,35,39,20,22,52,151,143,77,81,75,63,75,179,188,48,125,142,73,171,159,128,151,155,165,135,168,167,138,159,141,142,191,175 ,174,201,166,163,106,78,159,225,134,138,225,136,148,198,228,190,137,107,63,130,234,156,70,196,155,79,116,101,115,109,37,36,180,169,37,67,111,80,107,218,170,5,104,189,85,110,219,185,52,121 ,143,61,128,150,108,111,147,171,85,36,157,166,102,129,124,100,205,226,85,143,162,61,98,168,121,60,134,183,113,127,154,84,109,136,97,132,98,42,139,179,106,46,94,123,44,67,143,91,30,110 ,115,47,83,119,104,81,107,112,126,144,102,119,86,45,101,101,111,106,84,73,107,114,75,127,112,96,109,83,102,116,111,112,95,72,78,109,100,82,84,79,83,77,79,106,91,61,97,151,102,100 ,120,83,86,112,113,88,141,109,146,148,71,171,168,75,63,110,108,132,141,77,113,118,131,114,119,121,12,89,68,43,123,91,84,39,83,118,31,56,105,133,108,124,171,89,32,91,102,41,169,110 ,58,220,109,41,122,138,79,89,95,90,177,103,87,186,138,74,115,166,121,157,202,140,115,110,141,159,106,106,184,173,109,173,212,106,107,174,137,141,148,142,159,150,161,143,103,104,153,180,118,118 ,180,143,106,142,146,140,140,119,128,150,139,141,144,138,116,118,164,129,127,158,126,119,135,133,124,148,150,132,148,141,149,139,107,139,147,117,128,146,133,136,167,146,128,141,130,139,151,151,139,139 ,139,145,158,133,133,149,141,143,154,137,134,157,133,123,158,152,147,148,134,142,142,139,141,149,137,132,152,137,138,148,136,136,144,141,140,151,141,137,138,135,142,132,130,147,132,135,147,134,135,138 ,135,129,139,144,131,135,140,140,141,135,141,140,123,141,145,122,136,139,132,133,131,147,140,123,135,142,132,129,146,146,128,140,138,131,136,137,139,129,134,138,139,137,124,123,136,139,138,137,164,148 ,89,148,188,119,107,158,162,111,115,161,139,125,133,131,158,152,116,134,146,122,140,139,134,148,127,122,138,137,119,127,134,145,153,124,145,150,139,135,117,131,128,116,140,144,130,149,145,136,144,140 ,139,127,144,152,126,127,122,138,156,135,134,139,137,144,143,146,142,130,130,138,141,139,147,141,128,137,140,134,133,144,136,127,142,136,133,144,144,135,134,144,136,127,135,142,136,128,130,135,137,140 ,135,128,138,140,133,136,137,134,135,139,137,135,133,138,141,127,134,139,132,136,136,137,134,135,140,133,131,136,135,132,135,135,130,137,139,132,135,132,128,136,137,130,132,134,132,136,137,130,131,136 ,134,136,136,129,130,131,131,131,132,136,135,131,131,132,133,137,132,128,130,128,128,129,132,132,131,131,130,132,131,129,131,129,128,126,128,134,132,130,132,129,127,129,128,124,125,130,127,121,128,124 ,123,132,127,127,126,125,127,127,128,127,123,123,126,126,125,126,121,122,127,126,125,126,127,124,123,123,129,125,125,128,121,125,126,122,127,126,120,121,124,123,122,126,124,125,127,122,121,124,127,128 ,123,123,124,116,127,127,116,121,117,119,124,125,130,126,131,122,110,124,119,120,138,135,122,127,118,117,134,117,117,118,113,132,118,119,115,104,139,121,112,130,113,120,131,130,123,107,108,126,114,111 ,132,117,124,120,113,140,123,105,119,127,126,126,121,118,123,116,123,130,115,120,129,113,118,126,114,119,120,119,125,123,125,125,124,118,113,112,111,122,121,119,121,120,123,118,117,116,118,123,119,119 ,120,120,118,119,120,119,117,115,119,124,120,116,117,116,119,119,118,120,122,122,117,120,122,119,121,120,119,120,119,120,122,118,116,121,118,116,121,121,121,120,120,122,120,122,122,120,123,117,118,124 ,119,120,116,115,123,127,121,117,132,128,110,115,117,120,118,121,135,126,119,119,126,128,112,113,125,116,114,119,118,126,118,121,131,114,122,127,105,121,131,118,124,122,113,116,124,123,123,130,125,122 ,123,118,124,121,118,127,124,119,125,129,126,123,123,124,121,120,124,124,123,124,124,128,125,122,124,123,126,127,124,122,122,121,120,125,123,122,129,126,127,120,119,123,123,132,123,120,136,123,113,131 ,123,113,132,125,117,129,125,124,126,124,121,119,126,124,122,127,122,124,129,119,122,130,120,127,124,117,130,126,125,130,120,122,133,126,124,131,127,110,100,90,80,70,60,50,40,30,20,10,0,0; //4400 bytes 16k const char slay[] PROGMEM=124,122,124,124,126,127,129,132,134,134,133,132,130,129,129,125,124,123,123,123,125,127,128,130,130,129,129,130,131,130,130,129,128,128,124,122,123,123,122,121,137,110,130,175,145,139,148,127,132,138 ,99,137,135,48,80,190,141,176,205,189,42,30,107,140,67,82,101,112,146,119,59,97,124,48,102,150,137,172,200,195,201,151,123,136,112,84,100,83,86,181,142,106,155,169,114,102,128,173,164,134 ,133,176,167,121,109,114,92,91,192,182,64,74,100,66,98,150,109,104,192,211,197,77,58,48,48,56,70,72,69,87,117,142,147,163,203,198,179,132,112,114,130,134,115,118,147,139,121,110,90,82 ,79,81,98,160,171,141,121,113,128,154,174,153,144,170,185,200,196,155,68,70,76,90,100,103,119,110,104,123,125,79,86,115,122,118,110,96,87,116,129,130,112,97,120,146,156,125,115,109,66,59 ,87,106,119,115,95,128,134,122,130,112,94,101,99,112,142,155,164,176,174,166,164,169,180,178,126,110,116,141,149,154,140,130,157,161,143,143,133,77,93,135,143,131,134,133,134,141,118,98,108,112 ,99,112,145,160,144,135,124,125,144,145,153,106,85,76,34,62,60,48,89,63,96,179,194,192,218,197,136,174,208,161,114,147,171,161,121,110,158,104,118,146,137,151,165,145,128,89,113,113,52,66 ,85,137,136,121,126,118,106,76,64,110,127,150,123,93,87,85,93,84,109,173,140,89,41,60,90,63,53,125,147,157,86,47,66,83,108,169,158,140,155,137,150,173,174,161,140,118,143,150,121,116 ,155,219,192,151,88,44,112,140,103,111,144,162,189,197,170,149,140,131,115,129,121,117,87,91,125,158,124,110,137,128,128,172,192,138,89,30,53,85,92,98,92,71,73,64,95,140,160,129,121,193 ,200,151,117,109,104,110,167,162,146,109,108,122,155,112,86,99,91,115,114,75,58,68,124,162,174,130,121,154,176,175,179,163,138,112,149,187,130,80,122,149,145,163,143,105,118,121,117,121,112,71 ,81,140,137,135,110,115,138,177,211,241,214,182,169,166,155,152,152,141,161,175,156,143,142,165,147,121,101,78,79,69,59,67,68,111,136,147,165,167,155,163,179,189,178,176,161,137,91,85,78,60 ,69,83,84,97,136,125,117,126,129,119,83,68,48,68,89,106,117,127,154,178,205,209,215,200,174,132,126,116,71,73,75,39,31,75,93,99,128,157,164,118,105,94,91,92,119,134,124,90,102,148 ,169,184,170,154,148,153,153,147,119,107,93,84,93,101,99,95,99,128,150,152,154,159,170,139,114,106,87,76,83,91,113,142,150,150,158,184,206,198,188,152,134,120,125,117,89,90,102,147,151,146 ,142,122,106,106,100,96,68,62,74,78,127,138,141,190,206,219,204,183,161,144,126,119,109,124,126,112,125,151,159,135,144,183,173,160,122,88,74,69,66,71,71,82,117,160,197,237,248,215,196,176 ,154,149,124,102,82,60,59,73,99,125,185,178,165,168,145,117,109,95,91,83,83,119,112,107,128,133,136,148,163,194,213,202,166,157,147,141,121,99,112,104,97,117,146,147,159,174,161,110,90,74 ,60,49,45,72,57,70,101,120,204,241,251,233,193,102,70,44,70,99,100,128,153,165,185,203,190,186,198,182,163,145,139,125,61,49,64,69,74,106,126,143,185,194,180,185,190,155,127,104,72,66 ,58,60,84,162,148,121,115,116,116,108,104,98,80,58,51,44,12,24,50,74,90,137,173,192,209,228,237,227,203,166,153,132,77,92,90,62,63,78,106,114,118,136,134,196,220,151,148,169,155,118 ,126,184,191,149,111,102,213,235,138,118,118,113,107,107,83,38,67,128,150,79,103,156,167,160,191,210,195,123,119,97,54,72,57,28,11,38,52,79,156,162,177,193,197,207,210,173,135,144,100,93 ,92,88,70,63,97,120,108,138,165,131,148,222,206,154,58,40,42,80,81,105,86,74,149,189,209,185,142,71,76,72,84,113,135,168,153,138,141,131,108,104,140,151,153,158,137,104,67,68,85,74 ,60,49,68,127,203,217,217,215,221,238,232,213,183,159,112,70,47,54,34,14,6,20,51,45,68,144,139,119,206,250,246,238,221,178,138,120,139,143,122,123,121,88,84,127,140,120,53,57,69,28 ,13,75,99,104,124,149,169,162,163,169,152,131,150,166,164,141,153,137,102,80,66,58,46,72,105,128,148,185,231,227,220,187,149,104,90,92,92,97,98,108,127,154,180,208,247,247,237,213,164,88 ,100,118,77,62,78,85,94,127,171,216,202,192,151,141,137,130,146,112,94,115,168,172,184,224,220,177,173,171,126,105,97,77,58,70,95,106,93,110,131,145,162,216,238,244,214,206,200,154,126,94 ,79,56,31,24,9,10,19,57,87,112,126,132,176,196,204,200,194,180,137,111,81,82,84,88,89,79,53,58,77,90,104,117,110,97,82,97,125,120,120,143,160,156,143,130,133,136,133,113,96,79 ,76,86,109,84,52,28,15,11,30,56,95,113,148,223,234,231,221,215,179,130,87,45,16,9,10,8,7,6,49,192,224,229,195,179,163,153,127,114,115,104,111,115,85,91,123,150,190,239,237,227 ,163,147,109,96,96,67,78,97,129,154,172,179,188,199,190,169,115,97,63,53,56,63,44,8,33,61,104,153,199,228,229,223,221,216,222,216,178,90,65,94,67,14,52,89,84,81,67,45,38,28 ,62,92,107,184,214,237,252,239,223,236,239,246,248,251,243,212,152,113,57,67,77,94,82,50,44,53,93,146,181,215,217,198,198,214,188,172,171,163,151,147,137,127,128,128,132,141,137,128,112,104 ,84,77,65,38,40,53,76,104,155,174,205,251,248,248,248,247,243,213,164,92,56,20,13,9,8,10,26,70,84,167,199,211,248,249,246,244,213,123,80,60,78,84,95,80,70,83,62,71,148,140 ,150,132,87,90,91,78,106,127,142,158,186,165,154,174,184,164,133,106,80,81,68,48,35,15,26,49,51,100,148,171,202,234,243,233,227,204,168,111,89,58,8,8,9,9,5,59,111,138,121,144 ,177,166,152,156,158,163,157,156,148,160,186,135,95,80,45,37,48,71,62,37,33,38,85,131,178,184,178,154,155,146,145,150,144,165,184,162,145,149,194,148,61,70,84,73,71,73,35,13,9,21 ,25,33,80,122,210,244,247,248,246,253,226,173,97,48,22,28,23,17,9,31,46,59,126,132,143,158,137,159,153,143,222,236,218,149,134,155,125,94,117,131,141,118,88,67,72,87,120,109,92,75 ,84,132,133,139,172,157,104,98,114,135,118,85,34,62,109,118,132,146,168,184,170,162,101,96,90,87,118,157,218,230,233,232,222,206,200,185,132,111,49,24,16,12,10,26,56,92,154,188,225,248 ,249,223,181,158,145,148,165,163,176,211,187,147,72,70,83,111,126,116,80,42,8,20,45,99,124,170,178,171,167,181,191,204,211,205,195,169,115,108,92,90,86,40,28,41,80,92,109,91,84,126 ,130,147,192,187,185,197,203,221,232,227,193,179,134,113,81,52,70,66,36,50,101,109,108,141,169,200,193,181,162,165,185,176,140,114,112,108,101,98,98,98,83,99,122,146,120,101,111,134,120,111 ,120,125,140,140,144,157,128,104,120,130,93,89,98,120,125,163,176,157,123,122,132,119,89,66,63,69,103,102,145,182,207,243,232,192,175,180,126,134,118,55,55,52,54,83,117,93,74,92,118,142 ,148,156,177,178,179,153,135,138,135,111,77,79,82,96,104,140,152,153,141,134,132,131,130,144,148,152,157,160,164,153,150,146,147,148,117,98,80,53,59,105,123,136,170,186,194,181,146,130,159,161 ,143,168,174,171,167,154,154,127,66,66,80,83,77,137,175,177,164,170,169,145,120,141,149,134,120,138,144,110,88,124,123,113,136,143,133,143,160,177,159,136,138,132,92,77,72,100,131,157,152,162 ,210,199,177,154,138,103,108,117,103,111,122,100,98,119,134,158,186,155,127,138,128,91,93,112,156,152,117,110,114,143,150,145,163,173,122,98,86,63,66,70,68,76,102,115,127,122,123,133,169,194 ,219,224,226,203,186,159,109,111,114,86,43,11,28,50,73,75,106,124,132,191,231,215,204,208,178,138,113,122,117,70,59,63,93,104,107,97,107,118,99,82,79,67,63,93,89,88,107,127,163,167 ,160,148,160,161,149,155,160,143,100,78,57,23,29,44,60,66,76,89,113,164,176,171,166,188,196,185,182,176,168,169,176,134,39,27,19,46,64,75,134,146,139,98,52,42,62,86,117,127,115,102 ,102,144,141,133,147,147,90,56,36,24,17,17,16,22,42,52,70,107,128,161,176,189,181,175,173,163,167,161,156,151,114,112,120,125,125,137,134,123,110,92,62,68,71,66,80,87,87,107,129,121 ,123,164,156,138,143,147,118,100,86,79,81,80,55,62,106,113,124,158,185,207,210,206,169,160,157,119,95,64,64,77,81,90,109,130,126,119,136,159,149,142,142,159,174,170,144,123,143,152,144,106 ,100,112,125,121,115,130,134,105,99,122,140,166,222,208,168,170,201,185,160,157,196,178,120,124,130,115,99,63,17,30,33,43,67,70,68,111,181,157,170,210,241,198,157,143,173,174,152,148,143,134 ,124,110,86,90,101,96,85,84,110,134,123,116,120,132,149,164,169,196,196,193,192,176,153,102,98,103,99,92,79,83,90,77,69,108,147,166,174,181,189,179,165,177,171,163,152,162,163,131,119,106 ,109,109,97,106,92,102,109,112,107,80,91,92,97,118,148,147,158,190,194,185,158,130,108,79,70,80,114,139,151,134,119,99,100,107,119,112,116,134,151,172,155,111,95,83,123,163,183,166,144,114 ,114,109,90,76,75,120,142,163,137,101,69,71,83,111,107,139,176,204,216,211,195,175,170,156,146,126,100,112,118,105,92,51,44,59,87,90,106,121,145,164,162,159,134,126,139,143,138,144,150,148 ,125,113,100,87,80,103,121,139,196,192,146,147,141,116,121,125,119,121,153,168,172,153,141,154,135,94,58,62,74,89,89,97,110,138,168,156,139,92,85,109,131,144,143,135,130,169,188,169,141,125 ,116,110,113,106,80,48,53,74,130,154,159,148,143,184,194,185,143,110,67,74,86,74,54,33,23,38,73,90,98,88,97,123,176,193,199,186,168,152,148,128,51,30,36,31,39,103,138,154,111,97

Page 37: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

37 ,126,142,133,86,59,33,49,72,121,135,140,121,114,121,142,154,129,125,116,103,114,113,111,111,110,118,145,200,191,139,105,93,140,163,170,110,74,89,129,159,166,147,90,115,178,214,167,113,44,49 ,115,127,126,106,104,114,156,176,208,219,226,233,233,230,222,221,179,150,132,147,148,126,89,107,150,177,186,181,186,191,229,231,212,200,195,201,198,194,187,177,170,179,200,235,233,225,224,227,218,210 ,205,154,138,129,127,149,207,223,232,222,222,235,223,211,206,179,140,132,140,142,128,92,72,77,120,174,202,178,176,167,108,122,114,74,47,18,29,76,121,102,81,83,84,84,79,75,48,27,29,30 ,43,36,49,71,35,72,91,56,48,42,32,23,28,38,41,41,37,32,28,25,26,25,27,28,24,51,66,84,99,101,85,79,62,25,26,26,27,23,57,78,72,63,56,39,56,64,72,91,101,135 ,129,150,167,162,178,186,182,210,228,154,138,133,77,70,131,163,166,143,168,207,226,228,232,228,198,117,104,99,83,87,95,117,153,145,133,167,232,234,176,130,101,40,57,102,101,123,194,206,198,201 ,212,205,177,149,128,128,132,134,157,143,112,95,48,44,60,135,151,154,147,160,180,159,142,152,134,137,159,152,126,120,116,76,73,125,134,129,130,157,180,188,196,191,192,197,211,190,151,193,202,138 ,129,125,101,106,84,71,88,139,167,196,219,213,211,213,212,212,197,142,78,84,55,38,46,100,100,93,107,102,58,48,39,34,38,32,40,61,84,73,77,100,96,119,136,142,115,112,105,76,85,65 ,48,43,42,46,52,99,123,90,100,117,88,74,128,151,150,125,114,107,100,89,94,118,132,129,136,148,113,89,89,78,73,74,79,99,161,173,165,184,194,169,166,137,55,51,67,60,59,95,112,123 ,179,188,174,203,215,185,190,208,174,145,137,133,141,192,211,195,169,168,212,205,193,214,205,187,195,199,192,204,217,205,207,195,194,192,194,193,168,133,134,131,154,175,213,219,201,194,192,196,194,199 ,215,213,212,217,221,215,200,187,133,124,143,144,143,137,106,79,88,68,82,124,139,129,156,182,193,199,218,222,210,196,181,166,176,180,147,139,161,216,219,221,218,196,165,176,179,149,168,185,183,192 ,188,198,217,195,196,171,155,156,94,104,127,82,99,128,80,81,190,151,106,116,95,42,33,46,82,78,77,70,85,132,143,148,75,53,65,58,52,49,42,42,73,87,90,77,61,53,54,48,38,39 ,50,43,39,43,52,63,61,63,61,53,50,42,40,50,59,77,99,103,113,121,118,149,158,159,162,165,158,147,157,183,178,176,195,189,183,198,195,212,218,212,186,166,151,102,85,89,96,95,64,42 ,47,71,60,67,69,67,86,89,59,79,97,71,64,75,75,75,92,98,112,112,103,108,148,157,171,189,210,211,206,204,194,187,186,189,192,201,208,209,210,209,165,147,140,127,112,90,100,115,117,130 ,145,162,171,159,150,138,121,112,99,69,60,42,44,45,46,50,57,66,67,74,84,88,64,66,72,51,55,60,45,44,69,74,73,66,65,74,75,72,48,44,45,45,45,45,50,52,53,81,104,112 ,139,140,133,133,148,150,125,126,126,111,110,120,102,95,99,98,92,113,115,123,140,122,106,78,70,78,75,81,70,53,47,47,48,44,56,61,56,66,76,75,75,71,65,50,47,48,48,48,48,48 ,49,60,64,65,67,69,68,55,51,48,48,48,49,48,48,52,51,61,63,58,54,48,72,71,63,84,73,67,96,102,122,132,144,186,203,208,207,205,200,200,200,191,199,202,188,181,182,189,193,201 ,200,197,201,205,206,206,207,204,199,172,146,123,136,98,69,68,67,54,56,56,56,59,63,77,77,70,64,61,58,54,54,52,52,51,51,52,51,58,70,87,87,86,85,85,77,78,79,78,86,104 ,101,90,135,126,120,122,128,110,96,104,83,111,108,103,109,167,171,173,184,188,184,176,171,161,168,163,165,180,177,198,197,193,205,204,196,194,197,187,179,174,175,185,191,196,203,202,202,202,202,202 ,200,193,181,179,177,179,185,193,195,199,201,201,201,201,201,194,190,188,186,186,187,185,185,194,195,191,181,179,183,177,178,196,197,193,196,199,199,200,200,196,192,188,172,172,183,187,190,194,197,200 ,197,198,194,190,181,160,153,146,141,140,152,147,140,133,133,142,145,136,152,151,141,139,133,128,128,123,118,124,131,133,137,140,145,151,142,149,156,149,147,156,164,172,184,180,179,184,175,183,194,190 ,189,196,198,197,197,194,195,194,180,176,171,177,183,180,174,178,194,195,195,189,187,192,188,188,196,198,180,172,175,173,173,179,182,184,182,178,180,191,186,181,195,196,195,195,188,179,185,174,155,142 ,141,144,146,170,171,149,158,179,197,193,181,183,194,170,162,167,176,180,172,165,183,190,167,152,171,165,157,156,143,132,140,150,159,156,150,138,141,148,135,121,123,123,119,112,99,74,79,91,99,100 ,94,100,105,98,96,83,62,63,71,73,68,64,65,69,75,71,67,72,80,77,71,71,66,63,75,73,66,66,73,82,82,82,82,71,65,66,66,67,67,66,65,66,70,82,83,73,71,72,85,91 ,87,67,65,67,76,89,87,82,77,81,79,67,72,73,66,65,69,80,78,95,103,99,76,70,67,67,67,67,67,67,67,68,71,69,68,67,71,82,101,94,70,69,69,68,69,69,67,68,99,96 ,78,78,91,87,71,88,121,116,101,76,72,81,76,69,69,69,69,69,69,69,69,70,87,96,98,105,107,96,92,85,69,69,70,70,69,74,74,70,79,93,103,96,96,125,122,112,96,86,86,96 ,88,107,114,109,109,114,111,104,95,97,100,98,102,103,92,92,105,117,111,108,106,108,109,107,110,129,135,138,144,140,119,121,131,133,122,109,102,99,110,130,143,127,119,130,138,145,160,159,141,136 ,169,146,141,162,168,155,147,162,179,171,149,144,166,171,178,173,164,166,164,164,178,178,179,180,160,148,162,157,138,141,144,146,142,135,147,163,181,182,181,180,181,181,181,181,176,172,166,167,174,180 ,173,169,179,182,176,171,171,179,182,177,160,164,175,178,174,159,166,169,158,161,174,175,169,163,171,169,170,178,179,179,179,179,180,174,169,170,177,172,163,162,160,156,162,170,174,177,179,178,179,178 ,180,176,159,166,172,167,167,170,163,150,160,175,172,164,167,175,167,164,178,180,144,132,145,171,166,153,144,142,154,165,163,154,156,151,148,158,171,167,165,164,163,166,170,172,172,168,162,147,140,140 ,159,156,138,144,147,147,157,155,151,158,155,146,144,140,136,148,155,154,145,153,160,167,167,148,146,147,129,124,125,115,116,125,125,131,135,126,127,129,127,141,139,136,146,143,128,129,133,142,144,137 ,118,116,122,119,122,145,145,140,142,154,144,146,162,147,135,129,129,122,98,103,110,95,87,93,101,93,101,117,127,122,115,111,122,130,132,129,122,110,123,147,137,129,132,126,125,114,108,115,109,99 ,99,101,102,109,98,83,87,89,93,92,87,90,90,110,121,114,109,115,115,121,112,97,92,96,91,85,87,94,96,92,95,90,95,105,98,92,94,95,87,86,94,92,90,87,86,87,86,86,93,93 ,86,86,88,93,89,87,87,89,101,100,94,89,92,90,88,89,88,87,87,89,95,91,88,89,101,108,108,92,93,89,87,88,88,88,89,99,98,92,97,102,103,95,89,94,98,91,89,89,89,93 ,93,89,95,99,94,89,91,95,97,98,100,93,90,89,89,90,93,94,95,94,92,90,90,92,91,90,89,97,101,101,105,106,97,98,99,91,90,91,90,90,90,90,92,93,91,92,100,108,114,109 ,99,95,99,99,96,93,95,94,92,91,91,91,91,92,92,92,92,93,99,106,102,100,103,105,103,99,98,92,92,92,92,92,92,92,92,99,109,115,111,105,97,95,95,96,96,95,93,93,93,93 ,93,101,104,104,98,94,98,99,98,93,93,94,94,94,94,96,99,100,105,113,113,108,106,106,107,100,101,108,108,107,108,107,108,116,113,101,98,99,98,99,100,107,109,101,98,97,101,101,98,95 ,96,108,112,110,110,109,108,115,119,118,113,109,111,114,112,110,107,105,108,112,110,103,101,104,104,102,102,103,105,101,104,111,114,115,120,121,119,122,116,116,124,126,121,120,114,110,113,115,119,127 ,125,124,123,122,117,116,116,115,113,121,119,112,111,117,122,125,124,125,126,126,128,129,129,130,125,116,120,125,125,125,127,123,123,128,124,122,121,123,125,123,119,113,114,116,118,121,126,127,126,118 ,118,121,126,124,130,133,133,130,129,128,126,125,126,125,126,132,132,130,129,129,134,139,142,136,132,130,128,127,135,136,131,123,124,128,135,132,129,132,135,136,135,140,144,145,141,144,147,149,148,146 ,144,142,138,133,131,131,126,123,127,130,123,123,126,127,125,125,128,129,133,136,136,134,133,136,137,136,133,134,137,135,131,134,134,131,126,125,124,125,128,130,126,126,127,127,127,126,125,125,127,129 ,129,129,134,136,135,132,133,134,136,136,132,132,133,136,136,133,133,134,136,134,132,130,129,129,130,131,126,123,124,122,117,122,122,118,116,118,118,119,120,119,122,124,123,121,122,130,131,133,134,133 ,134,134,133,126,125,124,124,123,121,123,122,122,125,124,124,126,127,126,124,124,123,123,124,125,125,122,122,126,125,122,126,127,121,121,119,119,123,127,126,124,124,124,128,120,100,80,60,40,20,0; //6300 byes 11k const char explode[] PROGMEM=127,127,127,126,126,126,126,126,126,126,126,126,126,127,126,126,127,127,127,126,125,126,126,126,126,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,129,147,173,154,109,99,154,138,127 ,119,113,107,103,100,98,98,98,98,99,100,99,82,34,24,54,84,115,140,162,180,195,206,216,237,244,191,191,218,242,252,241,175,68,44,71,102,150,101,62,84,89,95,100,103,105,106,107,107,106 ,105,104,102,100,99,98,95,93,91,89,88,87,86,86,86,86,86,88,90,94,112,174,208,126,18,10,38,62,110,167,199,131,81,174,181,152,138,127,118,112,108,106,106,107,109,113,119,125,130,136 ,143,150,157,164,171,177,183,188,193,196,196,197,207,209,209,210,209,208,206,205,204,202,200,197,194,190,185,181,176,172,167,162,157,152,147,141,136,130,122,98,64,62,67,72,80,86,91,127,216,220 ,131,29,22,49,116,221,173,47,106,186,154,115,50,0,0,6,105,171,71,0,21,151,149,35,0,0,0,7,33,60,84,109,128,149,195,247,252,252,249,180,36,0,0,5,80,214,226,134,93,138 ,114,47,0,8,32,3,32,73,120,204,252,233,189,241,221,117,72,159,244,251,234,212,197,170,114,15,0,28,66,106,144,179,212,244,252,252,252,252,205,69,79,75,97,132,156,177,194,206,213,217 ,220,225,242,252,239,114,48,88,98,106,112,118,121,123,124,124,125,124,123,120,116,118,151,171,78,62,77,79,83,86,88,95,116,187,230,146,45,101,77,12,92,81,27,79,79,58,51,45,42,40 ,37,14,0,76,141,115,118,121,125,127,131,136,140,145,150,155,159,162,166,169,172,175,178,181,182,183,184,185,184,183,182,181,179,177,174,171,168,165,161,157,153,149,144,140,135,131,127,123,119,115 ,111,106,101,98,95,84,75,75,83,100,87,66,67,69,70,71,72,68,65,63,61,61,62,68,79,107,200,239,229,168,100,14,3,26,48,73,141,240,189,64,24,45,63,80,93,107,118,126,132,137 ,140,143,144,145,145,144,143,142,141,139,137,136,134,133,132,131,130,130,130,130,130,131,132,133,135,138,150,167,137,130,139,142,147,152,155,159,162,166,169,172,175,178,180,182,184,186,190,193,196,198 ,198,198,197,196,195,194,192,191,194,190,187,188,188,182,175,176,177,179,213,210,168,210,174,86,112,106,107,124,142,195,214,132,99,88,89,92,106,125,150,148,125,118,113,117,125,120,145,205,193,75 ,19,36,82,168,112,8,4,27,47,61,68,83,98,104,107,109,110,111,112,111,110,108,105,103,100,96,93,91,88,85,83,81,80,78,76,77,75,68,68,68,69,71,75,87,125,134,91,49,73,88 ,72,62,55,52,50,50,52,56,61,67,73,80,86,93,101,110,117,124,130,136,142,147,151,155,158,161,164,166,168,170,171,173,174,175,177,178,178,178,179,179,179,179,179,180,179,178,178,177,176,175 ,175,174,174,173,172,170,170,169,168,166,165,164,163,161,160,159,158,157,155,154,153,152,151,150,148,147,146,145,144,142,141,140,138,137,136,135,134,132,131,130,129,128,127,127,126,124,123,123,122,121 ,120,119,119,118,117,117,116,116,115,115,114,114,114,115,122,127,125,116,106,100,96,94,93,87,85,89,99,108,105,94,105,115,106,102,105,114,113,121,117,108,110,98,80,91,89,85,90,97,104,110 ,115,119,123,126,127,128,129,130,131,135,143,150,157,162,164,164,163,160,156,151,146,139,133,127,121,115,109,103,98,94,90,86,83,79,77,75,75,76,76,77,78,79,81,83,85,87,90,94,98,101 ,105,109,112,116,120,124,127,131,135,140,144,147,151,156,160,165,170,174,177,178,177,173,167,163,162,160,157,157,156,151,143,127,122,127,133,140,148,156,161,167,178,186,183,181,187,193,198,194,191,201 ,206,187,163,153,157,168,162,148,150,135,129,150,145,115,107,108,103,89,73,74,81,90,98,97,102,107,110,113,108,111,121,121,111,108,109,110,118,122,118,127,123,111,116,120,128,128,125,123,117,106 ,111,119,129,138,180,222,170,54,21,38,55,80,117,125,109,95,103,127,149,146,136,139,157,152,126,124,127,124,127,127,122,123,130,142,141,139,133,122,125,135,132,130,142,134,116,116,119,107,104,113 ,111,98,95,89,99,98,99,112,103,85,94,98,96,106,104,94,98,97,97,106,107,114,129,116,107,106,109,129,152,172,141,113,92,87,169,167,58,65,174,175,85,81,148,184,65,55,84,148,85,32 ,95,134,167,190,144,167,170,154,162,158,163,176,210,212,169,180,188,193,183,190,199,178,163,166,176,151,117,124,144,140,138,145,122,131,128,103,98,134,175,146,161,104,41,34,34,87,91,113,182,94 ,27,120,196,97,15,71,121,65,82,186,248,175,29,22,88,119,92,92,156,221,150,123,193,246,197,74,83,179,170,144,84,45,115,165,143,145,143,153,148,145,183,162,166,194,169,154,151,162,171,179 ,156,182,240,141,13,71,184,194,60,0,0,26,98,192,169,54,95,177,128,58,55,87,127,209,161,69,124,156,158,123,77,106,146,208,201,62,77,147,181,143,146,107,61,200,220,114,12,0,16,102 ,179,158,79,24,59,76,127,105,88,116,148,135,151,184,212,222,113,117,164,218,177,71,127,218,112,69,172,92,46,165,164,126,84,103,74,36,5,96,210,155,69,1,13,121,190,206,164,195,206,73 ,53,200,179,49,22,180,214,155,142,96,114,224,234,96,12,80,184,249,201,75,74,130,182,231,235,134,122,211,251,234,101,74,162,201,221,145,88,18,62,95,47,0,16,18,61,136,145,155,90,24 ,62,37,136,187,121,32,1,16,99,227,172,54,47,91,43,63,152,231,201,160,127,154,49,88,213,207,135,231,206,122,126,214,252,252,252,236,105,3,33,117,110,140,238,187,72,0,13,86,177,203 ,113,178,189,48,0,55,191,127,12,44,88,124,137,168,211,249,252,179,69,103,168,230,245,183,193,210,110,86,125,84,110,58,0,60,127,101,96,30,92,181,75,38,99,215,225,108,7,8,100,153

,116,228,212,93,41,34,57,107,107,144,207,250,252,252,249,153,43,113,212,240,129,84,184,246,189,63,1,36,196,239,142,16,0,13,86,200,250,241,214,138,18,15,114,138,149,174,178,202,173,77 ,78,148,94,12,10,109,138,41,0,3,41,100,162,238,252,247,209,226,233,235,243,140,79,189,191,172,131,64,1,0,4,68,90,164,147,12,43,115,129,121,108,189,249,252,232,188,121,18,8,52 ,53,81,144,225,203,141,130,113,26,102,147,48,0,0,8,102,229,234,249,252,252,230,211,184,132,40,52,193,172,140,119,68,7,0,0,4,44,127,237,252,252,252,242,167,105,21,0,51,167,173 ,196,247,165,117,233,226,185,209,140,77,110,135,133,73,9,0,23,148,104,33,19,130,245,215,121,94,83,197,229,196,235,208,158,127,130,108,84,90,90,73,53,69,78,62,90,98,97,101,104,106 ,97,66,113,151,147,161,156,154,152,150,140,82,23,108,232,248,223,174,73,73,178,169,94,121,152,174,190,204,214,220,222,223,221,219,228,249,240,123,64,92,95,97,105,133,120,81,89,91,94,118 ,140,73,57,77,136,231,169,20,0,0,58,187,176,112,76,47,21,3,0,0,0,0,0,0,0,7,20,31,32,52,89,101,115,129,144,157,167,176,193,206,213,221,228,234,239,243,246,248,249,249 ,248,246,245,242,239,236,231,226,220,212,196,141,74,81,112,136,162,186,205,218,227,233,237,239,247,252,252,230,99,43,72,76,79,81,82,81,79,76,73,69,63,58,54,52,50,47,46,57,119,110 ,8,0,0,0,7,26,73,178,201,134,87,47,16,0,0,0,0,0,0,0,0,0,0,7,22,38,55,72,89,104,123,138,153,167,181,194,206,215,213,222,249,252,251,252,252,252,252,252,246,203 ,173,240,210,137,188,227,249,252,252,252,252,252,252,252,252,252,252,252,250,218,193,193,188,168,203,212,141,199,188,123,107,48,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,38 ,65,61,117,156,197,238,225,228,249,252,234,227,237,235,233,229,224,217,211,204,196,188,179,172,163,155,147,157,197,181,185,90,7,30,40,55,82,64,54,70,74,88,145,135,41,56,79,85,85,92 ,101,109,116,121,127,130,136,142,145,146,152,162,165,195,246,251,228,195,164,135,86,62,106,98,88,84,78,74,68,34,0,0,0,30,117,228,252,252,252,252,190,68,162,231,106,13,87,206,252,252 ,252,252,241,209,188,159,115,25,0,34,197,234,195,166,142,116,68,69,91,53,55,106,95,85,81,75,63,63,70,69,67,60,58,77,79,48,33,70,34,3,24,47,79,116,146,176,229,251,183,125 ,166,179,188,194,198,199,201,213,247,250,195,127,150,238,210,143,85,41,6,0,0,0,0,0,0,0,0,0,0,0,0,29,82,57,80,106,106,110,123,128,133,129,82,30,166,252,250,247,244,241 ,237,232,229,226,223,215,208,223,225,221,219,215,210,209,212,209,209,206,201,186,167,169,186,212,205,183,184,188,177,154,117,103,161,196,190,174,163,151,140,123,80,43,59,116,192,181,151,121,125,131 ,118,100,39,25,98,111,42,13,44,62,77,95,109,119,128,136,142,146,148,148,148,148,147,147,147,167,176,157,229,252,221,79,14,101,36,53,125,78,30,2,0,0,0,0,81,179,154,179,145,49 ,0,66,200,158,58,0,4,46,169,250,202,134,221,252,252,247,164,61,146,244,252,249,224,199,175,155,139,128,120,113,108,106,105,106,108,111,114,118,122,127,131,136,139,143,147,150,153,155,158,160 ,161,163,164,164,164,163,162,161,158,156,154,154,157,141,129,127,124,103,122,150,133,133,125,94,76,106,122,102,80,95,92,40,8,56,121,127,98,93,107,95,85,71,75,68,72,81,20,0,30,93 ,91,126,132,29,27,63,82,103,125,148,158,164,220,252,248,218,175,123,47,0,32,85,51,26,93,117,66,73,50,42,129,182,96,69,112,111,150,160,112,127,178,160,148,165,183,212,230,204,200,201 ,206,219,245,250,249,252,230,212,188,96,65,93,121,121,90,86,127,190,224,183,138,156,197,171,148,129,113,103,93,86,81,79,79,80,84,90,96,102,109,114,113,118,144,156,157,162,169,169,151,111 ,134,205,201,240,250,236,228,218,201,207,197,185,161,144,178,174,157,131,127,156,117,85,98,47,3,52,135,215,204,154,137,159,221,206,159,116,42,0,3,69,110,56,34,45,84,70,111,127,84,54 ,34,30,17,8,1,0,2,11,10,11,17,21,16,42,61,59,64,83,90,91,106,114,120,117,93,105,123,190,200,185,182,177,137,132,202,196,181,147,112,154,207,161,122,137,131,163,186,211,248,252 ,252,252,251,235,202,171,139,90,74,135,120,96,84,38,0,3,42,95,137,212,251,251,217,124,37,90,197,248,196,85,43,79,134,133,125,164,233,233,173,185,240,229,132,15,30,150,239,220,174,137 ,82,24,0,3,37,66,104,128,129,150,190,245,238,216,248,224,152,119,126,83,110,164,170,210,127,9,3,47,130,192,197,124,41,0,30,133,222,160,140,50,0,24,60,67,92,103,124,166,161,157 ,178,230,218,166,148,136,151,147,178,240,252,226,165,59,0,0,0,17,43,61,82,123,133,109,127,165,240,172,53,36,40,60,120,131,108,123,175,176,101,139,199,224,119,25,70,121,88,8,51,144 ,204,157,19,35,128,144,114,76,127,194,224,192,159,196,194,56,0,24,86,181,242,210,243,252,228,131,13,45,88,86,157,103,116,149,148,127,104,115,146,172,175,174,185,197,205,204,213,221,208,219 ,248,205,142,133,124,111,183,219,117,23,0,2,7,0,25,60,68,69,125,164,66,8,30,51,98,149,223,211,103,67,95,108,91,150,229,207,93,8,12,103,138,127,169,203,101,119,208,201,170,117 ,49,120,149,58,27,26,141,228,107,35,153,237,128,52,133,178,232,252,252,223,138,63,109,145,174,220,251,230,174,206,169,145,156,203,249,188,30,26,63,86,107,115,126,125,131,126,109,119,132,117 ,121,203,225,138,114,33,0,0,0,12,103,175,88,3,0,0,2,16,65,147,101,57,55,104,200,167,158,162,108,97,106,130,166,209,247,212,119,128,104,114,134,149,171,193,182,169,173,178,178,180 ,183,187,201,238,252,231,87,37,72,94,118,152,210,209,120,131,176,119,69,97,117,100,92,63,23,2,24,147,151,106,124,113,97,74,35,81,115,40,8,113,213,191,174,154,78,3,16,79,170,246 ,252,192,114,159,203,243,252,216,163,193,206,213,222,219,211,208,202,193,184,174,165,154,144,134,136,138,126,179,209,150,105,65,33,7,0,0,0,0,0,0,0,0,0,2,24,53,79,105,157,240 ,250,212,169,142,140,145,134,142,133,111,97,82,60,54,67,94,104,101,103,106,108,113,113,122,145,152,158,163,166,168,175,182,185,189,193,196,199,201,204,205,206,207,207,207,207,206,205,203,201,199 ,191,161,141,198,222,189,167,177,181,145,145,178,154,113,147,157,146,175,175,149,113,83,100,156,173,154,167,176,142,111,84,56,50,41,29,20,13,11,10,9,10,11,8,10,33,40,42,41,45,67 ,75,77,77,48,5,11,42,73,108,144,164,182,179,187,200,211,235,252,250,195,150,167,170,173,175,182,192,215,249,226,159,100,76,138,192,162,117,84,69,83,175,201,91,44,46,96,180,154,127,126 ,82,12,0,1,43,47,7,68,152,153,135,104,112,139,99,86,123,151,225,252,243,192,171,179,222,251,188,84,103,179,244,243,148,106,147,167,188,228,252,252,252,250,214,125,15,0,84,203,174,128 ,91,86,98,82,38,0,0,8,111,157,45,0,26,79,150,238,252,252,240,199,179,135,119,115,117,170,159,127,101,80,69,54,65,76,72,59,53,58,56,50,54,75,90,92,93,91,87,91,104,103 ,111,151,166,158,140,123,131,147,157,153,131,113,131,147,144,141,133,135,125,133,159,161,151,142,139,135,127,115,92,100,131,129,115,92,101,128,115,81,66,110,151,135,93,55,53,62,88,118,140,171 ,176,127,88,90,129,182,220,200,156,201,238,223,148,79,57,78,122,150,184,191,170,105,57,66,110,122,151,170,106,38,1,18,122,155,124,66,81,88,26,30,64,110,148,194,248,252,252,239,147,69 ,68,127,211,203,156,147,159,176,191,169,126,73,49,82,124,148,158,176,201,230,216,160,89,96,176,234,233,195,175,173,166,161,158,159,136,131,164,156,137,143,154,152,162,156,155,155,155,153,155,157 ,149,129,69,46,122,99,63,119,174,187,178,186,205,223,237,248,252,252,251,227,215,184,78,71,125,145,142,121,82,37,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,116,100,40,26 ,84,152,157,135,124,117,90,19,1,46,142,232,252,207,168,186,141,122,165,196,183,159,185,235,252,227,163,186,244,252,225,155,121,109,120,118,105,109,83,63,66,58,40,36,51,66,86,114,128,134 ,130,152,185,165,156,140,111,106,135,172,181,168,162,116,79,111,169,182,141,124,165,222,209,180,139,105,127,205,212,179,168,158,144,98,67,98,106,157,208,200,162,93,37,85,166,220,222,160,130,168 ,172,151,132,92,57,42,90,134,118,126,114,102,95,115,125,150,135,127,132,122,108,93,66,57,72,162,182,158,140,129,130,113,65,48,127,185,127,59,81,123,137,148,135,151,202,223,193,191,202,189 ,153,127,149,151,89,60,108,164,159,96,69,92,142,146,94,103,149,154,146,55,2,42,92,71,33,48,74,78,81,97,114,133,164,157,138,151,160,147,146,167,181,159,143,148,150,147,140,144,143,141 ,146,142,139,147,132,100,98,108,107,117,129,130,121,109,101,105,124,138,127,132,186,167,71,47,75,114,115,105,106,111,124,141,176,149,98,98,112,130,151,159,155,163,155,132,128,135,140,148,157,154 ,162,173,168,150,150,160,165,208,220,171,102,41,46,55,59,70,71,65,128,177,144,92,75,83,107,121,127,156,173,154,123,127,146,178,227,251,238,156,63,57,152,235,163,43,10,23,56,83,97,114 ,118,108,116,129,147,165,149,142,187,245,252,223,158,83,82,110,86,55,37,23,12,2,0,0,0,0,0,0,4,44,96,145,182,205,225,243,251,252,252,252,252,252,252,236,182,148,137,136,135,139 ,164,168,121,133,193,188,146,134,123,80,35,44,140,201,143,97,115,113,95,64,43,13,0,0,0,24,47,44,36,38,54,71,69,75,102,136,140,144,151,147,158,179,184,193,218,240,216,179,189,212 ,196,194,203,197,201,227,239,241,226,214,206,196,192,175,151,161,176,166,157,149,143,142,136,131,130,128,125,121,118,115,114,111,110,109,107,107,106,104,104,103,102,101,100,99,97,94,88,98,102,98 ,94,85,94,103,98,97,94,89,77,56,68,107,120,113,103,96,85,83,100,117,115,122,117,101,70,67,90,100,68,58,77,98,124,146,154,163,158,152,165,179,178,161,172,195,170,128,126,130,139,162 ,175,151,113,107,136,161,152,109,81,87,91,88,93,98,100,110,152,232,242,122,7,4,30,65,93,101,114,123,155,157,127,139,127,117,153,205,225,240,216,167,107,30,21,46,51,56,79,109,195,239 ,184,134,168,227,227,227,226,214,223,240,251,236,212,210,203,186,162,132,123,149,153,132,116,87,38,39,80,95,111,124,116,115,118,123,111,84,68,103,139,150,123,105,118,157,173,152,135,129,136,153 ,144,126,121,112,107,108,117,114,77,62,107,142,147,127,101,81,79,103,109,100,91,74,62,71,108,127,126,124,118,60,16,35,106,159,111,56,85,125,134,105,45,66,129,123,81,47,34,68,136,161 ,152,126,96,78,68,49,36,35,90,152,132,107,95,83,91,113,112,107,117,142,121,65,51,75,109,151,176,185,192,207,205,172,127,98,160,188,151,161,198,219,216,199,185,164,158,181,194,200,197,192 ,198,209,183,154,161,154,144,161,196,192,197,159,91,80,121,165,155,118,132,141,99,50,60,130,200,199,193,196,155,110,120,156,164,174,186,156,144,158,159,159,157,168,167,144,127,120,124,155,194,179 ,144,121,113,96,85,94,115,131,120,96,96,126,152,173,163,159,162,140,122,152,177,160,140,110,68,66,90,112,107,109,115,96,86,67,55,60,37,51,82,81,73,57,67,92,108,133,150,146,117,94 ,101,105,93,62,44,28,2,0,1,13,33,80,138,143,106,84,93,133,174,131,81,109,156,185,220,248,234,170,120,138,156,97,10,33,140,212,195,123,62,58,75,73,82,89,88,108,138,152,138,124 ,129,151,178,201,204,176,152,157,189,217,183,132,103,123,139,130,143,176,194,176,134,124,128,93,58,74,117,137,141,129,127,156,168,159,147,158,192,189,148,129,145,164,161,146,145,151,130,113,126,135 ,133,139,123,112,107,109,117,121,115,106,107,113,112,114,105,100,121,110,69,67,105,137,149,161,161,153,142,129,108,95,95,86,115,180,182,131,74,57,74,117,163,183,173,135,108,104,117,117,121,137 ,146,161,179,177,177,178,156,128,115,117,122,118,106,108,117,134,132,93,65,69,81,111,147,167,145,119,117,137,154,134,108,114,122,115,116,140,156,142,112,69,51,71,93,106,106,90,93,115,127,128 ,133,161,167,147,124,103,95,118,154,154,126,88,82,91,100,112,107,102,113,151,194,195,195,184,135,111,104,127,146,150,148,147,171,202,205,217,217,178,158,165,209,227,200,183,181,167,142,113,96,98 ,88,91,126,154,144,128,103,55,23,44,96,124,112,95,89,82,66,72,99,127,130,107,88,105,155,149,118,126,156,194,170,130,114,114,112,90,88,124,151,135,80,39,61,130,179,185,148,131,142,127 ,106,107,104,66,75,146,176,131,73,79,111,139,161,148,130,115,107,112,95,56,37,67,148,194,167,106,80,110,155,180,177,128,69,41,64,127,175,174,144,147,174,193,185,167,149,109,82,105,176,218 ,219,216,182,129,68,66,91,90,63,58,91,135,155,137,121,111,113,122,149,206,239,208,176,149,108,113,133,128,144,158,143,118,91,82,83,67,55,57,76,111,136,138,121,92,46,27,44,82,118,128 ,138,139,127,120,110,99,95,93,104,109,117,112,107,99,82,88,94,98,128,120,127,144,153,187,212,190,177,171,153,149,135,125,155,163,142,145,153,160,167,197,240,252,252,211,97,53,69,42,35,75 ,123,172,232,252,247,214,202,219,199,138,95,105,133,134,109,99,124,120,111,141,154,137,162,200,198,182,163,130,96,79,71,33,1,11,72,126,111,29,8,45,117,174,153,115,80,17,1,1,1,1 ,13,64,110,127,145,173,200,242,251,251,251,251,247,200,127,79,78,105,102,106,115,91,59,23,1,1,1,3,49,131,137,101,81,102,148,169,175,175,215,251,242,201,225,250,250,221,161,144,156,226 ,204,54,2,2,15,82,99,68,77,116,132,131,151,174,152,149,190,138,147,211,211,138,116,179,222,152,34,2,28,70,113,124,104,132,188,186,154,122,100,79,86,99,85,82,72,61,51,47,37,10 ,9,30,31,39,78,138,174,147,169,232,248,248,249,240,201,173,144,125,95,71,102,158,215,246,248,247,227,230,247,248,248,248,232,203,218,245,248,198,86,67,92,100,100,115,106,86,88,94,148,139 ,46,58,55,59,68,71,98,171,159,112,79,33,5,5,5,5,26,76,98,78,73,73,74,123,192,131,27,71,136,83,155,200,150,145,159,140,118,98,90,90,90,89,87,86,85,90,92,88,94,111 ,127,133,134,138,150,160,171,181,183,188,192,194,195,195,199,206,209,208,207,206,204,203,202,200,197,194,191,188,184,181,177,173,168,163,159,155,151,146,139,133,130,129,123,118,114,107,94,88,97,98

Page 38: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

38 ,96,87,73,74,92,103,104,97,90,77,50,31,41,77,91,80,74,74,85,93,89,81,94,108,97,65,47,74,105,110,120,104,70,45,51,86,108,110,140,187,168,114,84,80,107,157,181,155,124,130 ,162,173,135,103,103,130,159,194,211,178,134,108,96,95,103,146,188,192,191,176,118,63,78,122,141,127,113,75,47,70,108,147,159,142,124,126,139,135,155,167,161,154,151,139,127,143,162,168,166,168 ,172,171,169,175,179,178,177,176,172,174,182,180,178,181,184,185,181,170,168,180,181,176,172,176,183,181,174,168,161,152,146,146,139,129,128,127,123,123,122,118,111,97,83,83,103,109,109,100,93,84 ,57,55,62,78,113,131,110,91,83,77,74,70,64,55,46,33,57,94,83,71,67,57,64,78,108,135,151,149,125,87,55,52,49,66,81,84,95,105,111,130,151,141,93,49,47,66,74,83,101,116 ,117,126,156,188,167,118,101,121,154,148,122,132,173,198,167,136,133,148,156,156,155,131,134,153,139,104,62,60,112,145,144,156,176,177,154,153,166,158,143,146,144,134,150,167,135,57,27,60,119,181 ,223,226,226,219,217,218,223,212,194,192,201,221,225,221,207,205,220,224,206,179,167,164,178,208,205,167,145,154,167,137,68,31,29,31,63,88,70,59,63,51,46,46,34,46,68,75,60,53,73,99 ,99,86,73,60,41,31,31,51,104,129,113,93,113,147,148,144,137,126,125,119,111,130,150,128,91,68,92,122,109,95,95,98,149,200,190,160,165,169,146,142,169,186,199,209,197,191,197,206,199,176 ,159,160,186,214,206,164,125,107,105,101,82,62,66,74,69,47,36,36,37,37,62,98,98,80,78,90,92,56,37,51,95,132,130,113,110,133,141,145,143,139,139,138,135,134,144,153,154,156,156,148 ,143,160,179,182,183,180,180,180,179,172,172,187,185,179,164,138,148,170,180,201,210,187,149,133,155,199,206,186,172,155,141,126,102,89,99,114,124,135,144,126,116,143,164,150,127,112,99,84,74,64 ,78,97,90,87,81,71,72,74,72,57,59,84,99,89,72,71,74,79,99,122,120,129,144,141,127,131,143,151,160,162,154,158,170,167,156,144,137,136,139,149,170,168,134,113,109,120,131,135,129,124 ,129,126,103,83,73,85,121,143,115,58,52,75,99,98,103,122,132,150,145,127,110,79,64,86,125,163,174,174,164,156,149,142,150,164,186,199,191,197,190,162,148,148,152,160,172,171,169,164,148,149 ,166,182,180,149,126,118,101,78,65,61,75,106,109,100,115,132,121,91,76,99,124,115,92,83,108,135,152,181,176,131,71,81,136,147,119,99,105,112,117,129,123,103,81,75,86,106,110,118,135,141 ,133,135,158,161,141,128,127,126,132,139,134,121,121,133,148,157,155,151,144,131,119,113,108,89,77,77,90,103,104,97,90,88,92,99,103,106,111,115,115,116,126,132,128,123,119,121,127,136,140,131 ,117,113,126,140,138,122,112,114,121,137,149,149,150,156,160,152,134,116,98,86,82,98,121,140,155,151,152,154,135,120,132,153,173,184,165,141,139,152,160,153,143,147,159,168,175,172,168,164,160,162 ,171,183,182,164,151,138,129,129,135,145,148,133,115,111,115,116,119,124,126,123,120,122,125,129,135,135,124,113,110,117,118,110,109,124,133,119,99,87,85,100,111,104,104,116,121,115,119,122,120,110 ,99,94,93,87,82,97,107,106,104,104,101,94,99,112,115,113,119,130,131,114,101,131,166,164,140,127,131,136,157,176,177,172,154,147,149,153,153,162,149,129,144,153,144,140,131,125,115,96,90,97 ,115,134,131,115,112,117,126,126,120,122,122,125,130,135,129,123,123,126,137,153,149,126,111,111,115,107,97,89,93,105,114,122,120,100,92,95,93,90,93,100,108,113,114,111,105,104,107,116,133,138 ,131,124,123,116,116,130,153,169,170,170,166,148,120,101,106,114,128,151,163,154,138,135,150,162,156,142,139,146,152,158,161,165,167,164,160,156,143,133,136,134,131,135,145,153,152,140,127,121,118,116 ,117,120,121,121,120,118,117,115,116,118,121,119,109,108,112,116,118,122,132,139,133,123,115,111,114,119,124,129,134,131,128,131,135,135,133,128,124,126,125,128,134,136,131,117,99,92,92,94,104,116 ,117,114,123,145,146,129,111,102,104,113,129,139,137,142,142,129,109,99,106,120,135,142,137,138,143,139,133,136,147,155,149,139,138,142,142,135,124,119,124,128,131,133,138,143,140,127,118,120,129,137 ,131,122,116,111,111,115,120,122,120,119,119,119,118,115,117,119,116,112,113,116,123,127,121,110,103,107,120,134,137,129,122,125,130,132,133,134,131,127,128,135,143,141,134,131,129,125,123,121,122,124 ,128,135,138,136,133,128,123,121,127,131,131,131,131,130,130,130,128,124,119,120,123,129,136,142,144,142,142,140,140,143,145,146,143,141,142,144,142,136,135,139,143,143,136,130,132,136,135,130,127,128 ,130,132,131,122,115,112,113,117,121,120,110,106,106,109,115,123,127,120,109,107,112,112,111,113,118,124,127,127,126,129,134,135,133,130,126,124,127,129,128,127,126,127,130,130,128,127,126,124,126,131 ,133,131,127,126,124,124,127,130,131,128,126,127,127,126,129,131,130,130,131,133,131,126,124,125,124,124,129,134,136,134,128,123,121,124,129,129,133,137,134,127,127,133,132,130,126,120,118,116,114,119 ,130,135,134,132,130,133,137,136,130,130,136,137,138,136,137,140,141,141,140,141,141,140,136,136,136,134,127,119,119,123,125,125,126,128,125,120,116,115,115,116,119,120,120,120,119,119,120,121,122,123 ,123,125,125,121,117,118,123,129,130,127,124,124,126,127,129,131,129,125,122,121,123,127,129,130,134,136,134,129,126,127,127,126,124,126,131,133,132,130,129,127,122,118,120,121,122,125,128,129,131,131 ,128,126,127,128,129,131,132,131,129,127,124,124,125,126,125,123,124,124,125,128,127,124,124,125,128,129,127,125,127,127,126,126,127,126,122,122,125,130,134,134,130,127,126,127,127,128,129,131,133,134 ,134,133,131,130,128,128,127,127,128,129,131,133,133,133,133,132,131,129,127,128,129,129,129,129,128,127,124,122,122,123,125,127,127,125,125,127,128,127,127,128,127,126,125,120,100,80,60,40,20,0; //1700 11k repeatable const char Siren[] PROGMEM=123,123,117,117,123,130,133,131,131,126,125,130,125,124,133,145,144,138,131,119,116,119,119,126,144,152,144,136,129,116,109,112,119,129,140,150,147,137,123,106,97,96,111,129,140,147,140,129,113,99 ,89,91,106,125,143,152,147,131,116,102,87,89,104,124,144,153,150,132,118,105,91,97,120,143,151,157,146,125,111,99,95,102,119,140,151,154,150,130,110,95,91,96,113,136,144,146,144,126,104,97 ,105,110,123,136,144,151,145,129,111,109,113,125,133,138,144,147,143,126,113,118,130,143,143,139,143,139,126,120,117,117,125,139,136,131,137,136,125,111,111,118,130,136,130,137,140,125,111,105,110,117 ,129,133,133,143,147,140,133,123,117,120,137,139,138,145,143,131,123,116,112,118,136,140,144,153,157,140,123,112,104,111,129,131,131,143,151,143,124,117,111,117,126,125,129,144,157,144,129,117,104,109 ,117,120,136,154,159,145,138,119,98,103,118,125,138,153,158,147,137,113,90,92,109,124,143,158,164,154,139,112,84,82,102,123,146,167,172,164,143,109,75,70,95,120,147,171,184,167,132,99,66,61 ,85,120,151,177,191,171,132,104,71,59,84,120,158,195,208,178,137,106,70,50,80,119,158,206,226,187,139,106,66,44,76,124,165,211,233,191,140,99,51,32,63,112,157,207,232,194,140,97,59,37 ,59,109,159,205,227,201,147,92,55,43,63,104,154,199,222,212,158,95,54,48,59,95,146,191,212,207,164,102,54,43,55,82,130,184,205,193,160,106,55,35,54,84,130,186,211,188,166,125,66,32 ,48,90,136,184,219,201,165,124,73,34,46,97,152,205,239,220,172,123,77,35,36,85,144,195,233,221,167,119,77,35,23,64,130,186,219,220,170,113,71,41,27,50,109,171,208,218,184,120,75,48 ,41,56,103,157,202,219,194,139,91,59,46,64,102,139,177,208,205,158,109,82,61,63,95,125,151,180,198,171,124,99,85,69,82,117,133,143,165,179,146,120,118,96,80,103,124,118,131,165,171,145 ,137,131,106,98,110,116,118,143,170,171,152,137,123,103,84,96,116,129,154,186,180,152,143,124,80,66,92,118,133,161,180,161,143,132,102,69,69,102,131,145,160,164,147,132,116,85,73,95,124,140 ,143,150,147,132,124,113,104,105,118,138,146,138,137,146,143,133,140,145,136,138,145,133,113,112,131,136,145,164,161,146,137,126,98,77,96,130,145,161,177,164,143,126,103,76,76,104,133,159,179,185 ,167,138,109,83,66,71,97,136,170,181,185,173,140,103,82,77,75,89,124,164,179,185,173,140,106,87,76,68,78,103,132,172,194,179,151,131,104,73,64,75,89,117,164,198,191,154,130,111,89,70 ,76,96,129,167,191,184,153,123,111,102,91,92,116,144,153,154,153,139,112,105,118,116,118,132,139,130,119,116,118,129,133,143,159,165,146,117,104,95,83,91,132,164,173,181,191,164,116,77,69,71 ,80,111,158,191,191,184,167,132,85,68,80,98,109,131,167,191,180,161,140,116,89,78,90,103,109,124,159,187,178,152,146,137,102,70,80,95,92,116,161,187,177,161,151,120,83,64,75,89,106,139 ,173,186,184,165,138,110,85,71,82,109,131,145,171,188,180,160,144,120,90,69,76,98,117,132,152,171,180,166,138,109,82,69,75,97,118,133,150,165,170,150,116,95,83,78,87,113,139,154,164,167 ,152,136,118,105,98,98,116,137,153,154,144,136,124,113,109,106,109,118,137,143,129,123,125,118,105,103,117,123,113,119,139,140,116,103,120,119,99,105,132,145,136,131,147,154,132,112,119,130,110,111 ,139,152,140,133,147,154,133,116,119,137,139,126,138,153,146,123,110,118,129,117,117,139,158,150,136,136,130,105,89,91,113,139,145,150,161,161,138,110,90,85,97,112,126,147,165,161,150,146,140,120 ,97,95,110,116,106,106,132,153,145,136,144,158,152,120,104,104,91,82,92,119,152,170,174,178,170,145,109,85,83,85,98,118,151,179,179,157,137,129,120,102,87,98,116,123,124,132,147,145,130,132 ,152,160,140,119,117,109,85,76,89,109,131,159,188,195,186,164,125,90,61,50,66,84,105,137,172,188,173,150,137,118,85,61,62,75,83,103,125,147,164,164,166,158,132,109,91,84,78,78,97,124 ,144,157,171,186,185,154,133,131,116,90,75,96,124,130,131,147,173,194,184,147,131,131,105,73,64,87,105,110,124,161,201,214,185,151,145,133,87,46,51,82,99,104,131,181,220,212,178,161,157,123 ,71,50,59,68,85,118,153,185,214,221,199,167,139,110,66,35,36,64,95,123,158,194,221,215,188,161,140,111,68,41,49,77,95,109,137,184,211,206,194,185,159,118,78,55,51,59,75,112,154,191 ,214,219,207,192,164,113,64,41,41,44,51,77,125,177,202,208,213,214,191,137,80,46,36,30,32,64,117,171,202,213,221,220,195,150,92,59,48,41,42,59,97,145,173,184,198,207,208,181,137,99 ,73,49,34,36,59,91,132,177,200,208,208,195,170,118,73,55,51,54,59,83,125,161,178,188,199,199,187,159,123,90,70,69,70,70,80,109,147,178,193,199,205,198,170,129,85,63,61,62,57,66 ,102,154,194,201,199,207,206,170,118,80,73,63,44,46,78,120,152,170,179,188,194,174,140,109,87,66,50,43,54,73,96,124,158,187,195,188,181,177,154,109,64,51,55,51,51,78,124,167,198,213 ,219,218,206,177,125,77,59,56,50,50,70,116,159,186,201,219,221,193,147,116,95,69,43,34,50,83,111,132,153,181,206,205,174,144,125,113,87,57,48,66,91,117,131,140,167,193,199,179,160,159 ,157,131,90,69,64,64,76,92,99,123,166,202,212,205,192,177,152,111,62,30,22,29,55,87,110,136,181,222,234,222,193,171,152,102,43,21,14,22,55,92,124,159,207,242,255,235,187,153,130,85 ,44,25,20,46,89,117,136,160,199,233,247,215,161,133,120,98,56,21,25,66,105,118,113,125,166,212,227,199,164,152,146,120,77,36,29,55,77,82,91,119,167,218,242,222,186,167,154,124,84,49 ,37,50,71,83,97,129,166,206,228,220,206,187,161,124,89,62,50,49,54,73,104,132,151,167,187,200,199,181,158,137,118,97,75,56,61,75,87,103,124,152,174,191,195,205,201,179,147,119,105,87 ,59,35,34,56,90,117,137,177,214,240,236,208,171,132,103,75,41,22,27,55,91,117,140,172,207,235,239,212,172,136,109,82,49,29,36,66,97,125,153,174,200,221,221,201,179,151,119,96,73,50 ,43,56,71,90,112,137,166,202,228,220,202,187,164,124,85,61,44,41,48,64,84,123,164,200,236,253,234,206,187,164,118,70,41,23,28,51,78,102,126,159,193,221,234,221,192,167,150,120,84,46 ,21,25,59,102,117,118,133,160,191,208,201,172,144,138,146,126,84,54,46,68,102,112,92,90,130,180,208,205,179,157,157,170,150,97,62,59,64,75,89,91,95,125,172,198,200,194,180,160,146,138 ,113,87,76,70,70,87,106,112,123,147,172,185,186,177,157,145,139,123,92,69,61,61,63,66,82,106,137,159,167,166,166,177,187,167,125,97,91,89,71,51,44,57,92,136,151,144,154,177,192,212 ,207,166,125,111,103,82,63,50,36,49,95,137,137,132,164,179,186,195,191,158,123,106,92,77,70,54,41,51,91,132,152,174,194,201,201,202,191,166,136,104,87,78,87,89,75,73,103,157,192,206 ,208,200,191,191,181,151,105,75,59,54,73,96,89,85,111,146,178,198,186,160,146,151,146,132,110,78,63,64,83,111,129,120,119,140,171,187,184,158,130,125,143,140,106,120,100,80,60,40,20,0; //end //-------------------------------------------------------------------// //-------------------------50 Images save slots----------------------// //-------------------------------------------------------------------// char EEMEM truthVA[400]=0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0; char EEMEM truthVB[400]=0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0; //eeprom_read_byte(&eeprombyte) to read //eeprom_is_ready() to check first //eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val)) to wirte byte //do while (!eeprom_is_ready()) waits for eeprom to be done void lcd_command(char,volatile uint8_t[] ); void lcd_char(char,volatile uint8_t[] ); void displayload(void); void displaydone(void ); void changeM(char,char); void InitSPI(void) DDRB = (1<<PB0)|(1<<PB1) |(1<<PB3)|(1<<PB4)|(1<<PB5) | (1<<PB7)|(0<<PB6); // Set MOSI , SCK , and SS's output SPCR = ( (1<<SPE)|(1<<MSTR) |(0<<SPI2X)| (0<<SPR1) |(1<<SPR0)); // Enable SPI, Master, set clock rate fck/16 //-------------------------------------------------------------------// //-----------------------------Buttons-------------------------------// //-------------------------------------------------------------------// ISR(INT0_vect) /* signal handler for external interrupt int0 */ cli(); _delay_ms(8); //bounce immunity plays = 0x11; sei(); ISR(INT1_vect) /* signal handler for external interrupt int0 */ cli(); _delay_ms(8); //bounce immunity plays = playsdem;//playsdem; playsdem++; if(playsdem== 0x18) playsdem=0x00; sei(); //-------------------------------------------------------------------// //------------------------------Saving-------------------------------// //-------------------------------------------------------------------// //EEprom is 4byes a page thus write in multiples of 4 to maximize endurance void saver(uint8_t slot) int start = slot*8; eeprom_write_block((void*)&ledvectA, (void*)&truthVA[start], 8); //eeprom is 4bytes a page while (!eeprom_is_ready()); eeprom_write_block((void*)&ledvectB, (void*)&truthVA[start], 8); // instead eeprom_write_byte ((uint8_t*)&truthVA[k], (char)trutha[cc]); while (!eeprom_is_ready()); void loader(uint8_t slot) int start = slot*8; eeprom_read_block((void*)&ledvectA, (void*)&truthVA[start], 8); //eeprom is 4bytes a page while (!eeprom_is_ready()); eeprom_read_block((void*)&ledvectB, (void*)&truthVA[start], 8); // instead eeprom_write_byte ((uint8_t*)&truthVA[k], (char)trutha[cc]); while (!eeprom_is_ready()); void blockloader(int stop,char *truthanima[], char *truthanimb[]) stop=stop*8; displayload(); for (int start=0; start<stop;start++) *truthanima[start]=eeprom_read_byte((uint8_t*) &truthVA[start]); while (!eeprom_is_ready()); *truthanimb[start]=eeprom_read_byte((uint8_t*) &truthVB[start]); while (!eeprom_is_ready()); displaydone(); //-------------------------------------------------------------------// //------------------------------DAC----------------------------------// //-------------------------------------------------------------------// void SPI_MT(char data ) //transmit at 444kbit spi ->> 444/16 =>fs= 27.75kHz /* LT1661 needs 4 bit protocol 10 bit data and 2 bit dud space*/ char word1, word2; word1 = data >> 4; //shift to make (8 bit) top nibble word2 = data<<4; //shift to make bottom nibble word1 = word1 | 0x90; // control nible 1001 +top nibble PORTB &=~(1<<4); //ss for dac SPDR= word1; while (!(SPSR & (1 << SPIF))); // transmit first SPDR= word2; while (!(SPSR & (1 << SPIF))); //transmit second PORTB |=(1<<4); //ss for dac void playslay(volatile char trutha[8],volatile char truthb[8], uint8_t start) uint8_t counter=start; for(int i=0;i<4401;i++) SPI_MT(pgm_read_byte(&slay[i])); changeM(trutha[counter],truthb[counter]); counter++; if (counter ==8) counter =0; _delay_us(4); void playtap( volatile char trutha[8],volatile char truthb[8], uint8_t start) uint8_t counter=start; for(int i=0;i<1551;i++) SPI_MT(pgm_read_byte(&check[i])); changeM(trutha[counter],truthb[counter]); counter++; if (counter ==8) counter =0; _delay_us(32);

Page 39: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

39 void playsiren( volatile char trutha[8],volatile char truthb[8], uint8_t start) uint8_t counter=start; for(uint8_t a=1; a<6; a++) for(int i=0;i<1701;i++) SPI_MT(pgm_read_byte(&Siren[i])); changeM(trutha[counter],truthb[counter]); counter++; if (counter ==8) counter =0; _delay_us(32); void playexplode(volatile char trutha[8],volatile char truthb[8], uint8_t start) uint8_t counter=start; for(int i=0;i<6301;i++) SPI_MT(pgm_read_byte(&explode[i])); changeM(trutha[counter],truthb[counter]); counter++; if (counter ==8) counter =0; _delay_us(32); void playtone(char row, volatile char trutha[8],volatile char truthb[8], uint8_t start, char tone[10], double delay, uint8_t length) uint8_t counter=start; for(uint8_t a=1; a<length; a++) for(int i=0;i<10;i++) SPI_MT(tone[i]); changeM(trutha[counter],truthb[counter]); counter++; if (counter ==8) counter =0; _delay_us(delay); //-------------------------------------------------------------------// //----------------------------Multiplex------------------------------// //-------------------------------------------------------------------// void changeM(char trutha,char truthb) PORTB &= ~(1<<PB3); //rck/ SPDR = row; while(!(SPSR & (1<<SPIF))); //19us PORTC=0x00; PORTA=0x00; _delay_us(1); //prevent dim glow in previous light PORTB |= (1<<PB3); //rck rise PORTA = trutha; PORTC= truthb; row=row<<1; //20us if (row==0x00) row=0x01; //21us //eye can't detect <1ms delays void driverdig(char* truth[8], uint8_t digit,char color) *truth[1] =row2D[digit]|color; *truth[2] =row3D[digit]|color; *truth[3] =row4D[digit]|color; *truth[4] =row5D[digit]|color; *truth[5] =row6D[digit]|color; *truth[6] =row7D[digit]|color; void runanim(int start, int finish, char *truthanima[800], char *truthanimb[800]) finish++; row=0x01; for (int q = start; start <finish;start++) for (uint8_t run=1; run <8; run++) for(int k=(q*8); k<(8*(q+1)); k++ )changeM(*truthanima[k],*truthanimb[k]); _delay_ms(1); //-------------------------------------------------------------------// //------------------------------LCD----------------------------------// //-------------------------------------------------------------------// // Original Code by Kyle Thortan. //Modified to PIN PORTD D3.D2.D1.D0.-.-.E.RS arrangement //Modified faster Delays and integrated multiplexing char charnum(int num) char array[10]= '0','1','2','3', '4','5', '6', '7', '8','9'; return (char) array[num]; void lcd_init() //only need to call once // 76543210 uint8_t nulls[5]=0 ,1 ,2 ,3 ,4; DDRD = 0xF3; //0b11001111original port c lcd_command(0x33,nulls); //Initialize LCD Driver lcd_command(0x32,nulls); //Four bit mode lcd_command(0x2C,nulls); //2 Line Mode lcd_command(0x0C,nulls); //Display On, Cursor Off, Blink Off Change to 0x0F if cursor is desired lcd_command(0x01,nulls); //Clear Screen, Cursor Home //Display Standby lcd_char('S',nulls); lcd_char('t',nulls); lcd_char('a',nulls); lcd_char('n',nulls); lcd_char('d',nulls); lcd_char('b',nulls); lcd_char('y',nulls); lcd_command(0xC0,nulls); //line 2 lcd_char('E',nulls); lcd_char('-',nulls); lcd_char('B',nulls); lcd_char('o',nulls); lcd_char('a',nulls); lcd_char('r',nulls); lcd_char('d',nulls); lcd_command(0x80,nulls); //line 1 void lcd_command(char cmd,volatile uint8_t start[10]) char temp = cmd; PORTD=0; changeM(ledvectA[start[0]],ledvectB[start[0]]); _delay_ms(1); changeM(ledvectA[start[1]],ledvectB[start[1]]); _delay_ms(1);

changeM(ledvectA[start[2]],ledvectB[start[2]]); _delay_ms(1); changeM(ledvectA[start[3]],ledvectB[start[3]]); _delay_ms(1); changeM(ledvectA[start[4]],ledvectB[start[4]]); //delay 5ms~ _delay_ms(.91); cmd = (cmd & 0xF0) | 0x02; //Write Upper Nibble (RS=0) E --> 1 PORTD = cmd; _delay_us(20); cmd ^= 0x02; //E --> 0 PORTD = cmd; _delay_us(20); cmd = temp; cmd = ( (cmd & 0x0F)<<4 ) | 0x02; //Write Lower Nibble (RS=0) E --> 1 PORTD = cmd; _delay_us(20); cmd ^= 0x02; //E --> 0 PORTD = cmd; _delay_us(20); void lcd_char(char data,volatile uint8_t start[10]) char temp = data; PORTD = 0x02; changeM(ledvectA[start[0]],ledvectB[start[0]]); _delay_ms(1); changeM(ledvectA[start[1]],ledvectB[start[1]]); _delay_ms(1); changeM(ledvectA[start[2]],ledvectB[start[2]]); _delay_ms(1); changeM(ledvectA[start[3]],ledvectB[start[3]]); _delay_ms(1); changeM(ledvectA[start[4]],ledvectB[start[4]]); //delay 5ms~ _delay_ms(0.91); data = ( (data & 0xF0) ) | 0x03; //Write Upper Nibble (RS=1) E --> 1 PORTD = data; _delay_us(20); data ^= 0x02; // E --> 0 PORTD = data; _delay_us(20); data = temp; data = ( (data & 0x0F) <<4) | 0x03; //Write Lower Nibble (RS=1) E --> 1 PORTD = data; _delay_us(20); data ^= 0x02; //E --> 0 PORTD = data; _delay_us(20); //10 us~ void displayload(void) lcd_command(0x80,start1); lcd_char('L',start2); lcd_char('o',start3); lcd_char('a',start4); lcd_char('d',start5); lcd_char('i',start6); lcd_char('n',start7); lcd_char('g',start8); lcd_char('.',start1); lcd_char('.',start2); lcd_char('.',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_char(' ',start6); lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_command(0xC0,start6); //line 2 lcd_char('P',start7); lcd_char('l',start8); lcd_char('e',start1); lcd_char('a',start2); lcd_char('s',start3); lcd_char('e',start4); lcd_char(' ',start5); lcd_char('W',start6); lcd_char('a',start7); lcd_char('i',start8); lcd_char('t',start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_char(' ',start6); lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); void displaysave(void) lcd_command(0x80,start1); lcd_char('S',start2); lcd_char('a',start3); lcd_char('v',start4); lcd_char('i',start5); lcd_char('n',start6); lcd_char('g',start7); lcd_char(' ',start8); lcd_char('.',start1); lcd_char('.',start2); lcd_char('.',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_char(' ',start6); lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_command(0xC0,start6); //line 2 lcd_char('P',start7); lcd_char('l',start8); lcd_char('e',start1); lcd_char('a',start2); lcd_char('s',start3); lcd_char('e',start4); lcd_char(' ',start5); lcd_char('W',start6); lcd_char('a',start7); lcd_char('i',start8); lcd_char('t',start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_char(' ',start6);

Page 40: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

40 lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); void displaydone(void) lcd_command(0x80,start1); lcd_char('D',start2); lcd_char('o',start3); lcd_char('n',start4); lcd_char('e',start5); lcd_char('!',start6); lcd_char(' ',start7); lcd_char(' ',start8); lcd_char('.',start1); lcd_char('.',start2); lcd_char('.',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_char(' ',start6); lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_command(0xC0,start6); //line 2 lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_char(' ',start6); lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_char(' ',start6); lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); /*------------------------------------------------- -----------------------*/ /*------------------------------WIRELESS----------------------------------*/ /*------------------------------------------------- -----------------------*/ //Code by Justin Lu //NORDIC PIN SETUP // CE to PB0 // CSN to PB1 //SCK to PB7 //MOSI to PB5 //MISO to PB6 //IRQ to PB2 //void SPI_send(unsigned int); void SPI_send2(unsigned int,unsigned int); void NordicInitRX(); void Reciever(); char SPIget(unsigned int); unsigned char SPI_trans(unsigned char); void set_RX_ADDR(void); void resettz(void); void set_TX_ADDR(void); void NordicInitTX2() //initialize for transmitter (v2) PORTB &= 0xFE;//reset_CE(); SPI_send2(0x20, 0x38); //Mask Interrupts TX_DS and MAX_RT, CRC enabled SPI_send2(0x24, 0x00); //Disable retransmit SPI_send2(0x22, 0x01); //enable data pipe 0 SPI_send2(0x31, 0x11); //Data payload width 17 bytes SPI_send2(0x23, 0x03); //set address width to 5 bytes SPI_send2(0x26, 0x07); //RF output power 0 dBm SPI_send2(0x25, 0x42); //set RF channel (default is 2, can be from 0 to 83 decimal) set_TX_ADDR(); SPI_send2(0x21, 0x00); //set address width to 5 bytes void resettx() //reset the interrupts SPI_send2(0x27, 0x20); void set_TX_ADDR() PORTB &= 0xFD; SPI_trans(0x30); for(int k=0;k<5;k++) SPI_trans(0xE7); PORTB |= 0x02; void NordicInitRX() //initialize for receiver PORTB &= 0xFD;//reset_CSN(); PORTB &= 0xFE;//reset_CE(); //Enable RX_DR interrupt SPI_send2(0x20, 0x39); //Mask interrupts TX_DS and MAX_RT, receive mode SPI_send2(0x21, 0x00); //disable auto-ACK, change 0x00 to 0x01 to enable SPI_send2(0x23, 0x03); //set address width to 5 bytes SPI_send2(0x22, 0x01); //enable data pipe 0 SPI_send2(0x26, 0x07); //Data Rate 1mbps, RF power 0 dBm SPI_send2(0x31, 0x11); //Data payload width 17 bytes SPI_send2(0x25, 0x42); //set channel (0 to 83, default 2) set_RX_ADDR(); //set to E7E7E7E7E7 (default) SPI_send2(0x20, 0x3B); //set PWR_UP bit, enable PRIM_RX (set as RX), Disable TX_DS and MAX_RT interrupts //SPI_send2(0x20, 0x33); SPI_send2(0x21, 0x00); PORTB |=0x01;//set_CE(); //starts RX mode _delay_us(200); //checks for packets after 130us void set_RX_ADDR() PORTB &= 0xFD; SPI_trans(0x30); for(int k=0;k<5;k++) SPI_trans(0xE7); PORTB |= 0x02; void receive17() //receive payload PORTB &= 0xFD;//reset_CSN(); SPI_trans(0x61); _delay_us(20); for(int c=0;c<17;c++) d[c]=SPI_trans(0); _delay_us(20);

PORTB |=0x02;//set_CSN(); _delay_us(10); PORTB &= 0xFD;//reset_CSN(); SPI_trans(0xE2); _delay_us(20); PORTB |=0x02;//set_CSN(); _delay_us(10); PORTB &= 0xFD;//reset_CSN(); SPI_trans(0x27); //clear interrupts _delay_us(20); SPI_trans(0x40); _delay_us(20); PORTB |=0x02;//set_CSN(); unsigned char SPI_trans(unsigned char data) SPDR = data; //sends data while(!(SPSR & (1<<SPIF))); // wait for transmission to finish return SPDR; void SPI_send(unsigned int data) PORTB &= 0xFD; //CSN =0; SPDR = data; //sends data while(!(SPSR & (1<<SPIF))); // wait for transmission to finish PORTB |= 0x02; void SPI_send2(unsigned int reg1, unsigned int data2) PORTB &= 0xFD; //set CSN low, lets it know it is about to receive spi data SPDR = reg1; //sends data while(!(SPSR & (1<<SPIF))); // wait for transmission to finish _delay_us(10); SPDR = data2; //sends data while(!(SPSR & (1<<SPIF))); // wait for transmission to finish _delay_us(10); PORTB |= 0x02; //transmission done, set CSN back to high void transmit17() //use if 1< count <4 SPI_send2(0x27, 0x7E); //Clear interrupts, RX fifo empty SPI_send2(0x20, 0x3A); //Set Power up bit, TX mode SPI_send(0xE1); //Flush TX FIFO PORTB &= 0xFD;//reset_CSN(); SPI_trans(0xA0); for(int t=0;t<16;t++) SPI_trans(stuff[t]); //Write TX payload, PORTB |=0x02;//set_CSN(); PORTB |=0x01;//set_CE(); _delay_ms(0.2); PORTB &= 0xFE;//reset_CE(); ISR(INT2_vect)////triggers on falling edge of IRQ (data is received) while(!(SPSR & (1<<SPIF)));//make sure multiplex is done PORTB |= (1<<PB3); receive17(); plays=d[0]; if (plays ==0x33 || plays ==0x34 )func =d[1]; else if (plays != 0x00) //don't update vectors until uint8_t cc=0; for (uint8_t k =1; k<17;k++) ledvectA[cc]=d[k]; k++; ledvectB[cc]=d[k];cc++; else ; //----------------------------------------------------------------- //Transmitter mode notes //W_TX_PAYLOAD is used when you want to send packet //CE pin held low //send 0xA0 (Instruction of W_TX_PAYLOAD) then payload (must match length of receiver) //Once packet loaded, keep CE high for at least 10 us //TX_DS interrupt fires if packet sent // //----------------------------------------------------------------- //----------------------------------------------------------------- //Receiver mode notes //R_RX_PAYLOAD reads contents of RX FIFO once a packet is received //when receiving packets //CE is held high //CE goes low after packet received, R_RX_PAYLOAD is executed //send 0x61 (Instruction for R_RX_PAYLOAD) then send same amount of dummy bytes as payload width /*------------------------------------------------- -------------------------*/ /*----------------------------MAIN FUNCTION-------- -------------------------*/ /*------------------------------------------------- -------------------------*/ int main(void) //soft_reset(); char ledvectUFA[8]=0xFF,0x41,0x41,0x41,0x41,0x41,0x14,0xFF; char ledvectUFB[8]=0xFF,0xAA,0x80,0xA8,0x80,0x80,0x80,0xFF; char truthanimA[40]; char truthanimB[40]; row = 0x01; int playstat11=0; int playstat12=0; int playstat21=0; int playstat22=0; uint8_t countopt=0; //char data =0x00; //test //uint8_t x=0; DDRD = 0xF3; DDRA = 0xFF;//most significant LED DDRC = 0xFF;//second byte PORTA = 0x00; PORTC = 0x00; InitSPI(); lcd_init(); GIMSK |=(1<<INT0)|(1<<INT1); //int0 on GICR |= 0x20; //int2 on MCUCR |= (1<<ISC01) | (1<<ISC00)|(1<<ISC11) | (1<<ISC10); //int 0 rising edge MCUCSR &=~ 0x40; //int2 fall edge NordicInitRX(); //NordicInitTX2(); //remove for normal sei(); //while (1) //transmit17(); //_delay_ms(3000);_delay_ms(3000);_delay_ms(3000);_delay_ms(3000); // while(1) row=0x01; if (plays >0x3F) plays = 0x00; // Protocol code // This is a nested if structure to provide consistent delays, defined for 64 commands, double checked for correctness if ((plays>>5)==0x01) if ((plays>>4)==0x03)

Page 41: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

41 if ((plays>>3)==0x07) if ((plays>>2)==0x0F) if ((plays>>1)==0x1F) if ((plays>>0)==0x3F)//111111 test protocol lcd_command(0x80,start1); lcd_char(d[1],start2); lcd_char(d[2],start3); lcd_char(d[3],start4); lcd_char(d[4],start5); lcd_char(d[5],start6); lcd_char(d[6],start7); lcd_char(d[7],start8); lcd_char(d[8],start1); lcd_char(d[9],start2); lcd_char(d[10],start3); lcd_char(d[11],start4); lcd_char(d[12],start5); lcd_char(d[13],start6); lcd_char(d[14],start7); lcd_char(d[15],start8); lcd_char(d[16],start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); plays=0x00; else //111110 plays=0x00; else if ((plays>>0)==0x3D)//111101 plays=0x00; else //111100 plays=0x00; else if ((plays>>1)==0x1D) if ((plays>>0)==0x3B)//111011 plays=0x00; else //111010 plays=0x00; else if ((plays>>0)==0x39)//111001 plays=0x00; else //111000 plays=0x00; else if ((plays>>2)==0x0D) if ((plays>>1)==0x1B) if ((plays>>0)==0x37)//110111 plays=0x00; else //110110 plays=0x00; else //11010e if ((plays>>0)==0x35)//110101 plays=0x00; else //110100 plays=0x00; else if ((plays>>1)==0x19) if ((plays>>0)==0x33)//110011 plays=0x00; else //110010 plays=0x00; else if ((plays>>0)==0x31)//110001 plays=0x00; else //110000 plays=0x00; else if ((plays>>3)==0x05) if ((plays>>2)==0x0B) if ((plays>>1)==0x17) if ((plays>>0)==0x2F)//101111 plays=0x00; else //101110 plays=0x00;

else if ((plays>>0)==0x2D)//101101 plays=0x00; else //101100 plays=0x00; else if ((plays>>1)==0x15) if ((plays>>0)==0x2B)//101011 plays=0x00; else //101010 plays=0x00; else if ((plays>>0)==0x29)//101001 plays=0x00; else //101000 plays=0x00; else if ((plays>>2)==0x09) if ((plays>>1)==0x13) if ((plays>>0)==0x27)//100111 plays=0x00; else //100110 plays=0x00; else if ((plays>>0)==0x25)//100101 plays=0x00; else //100100 plays=0x00; else if ((plays>>1)==0x11) if ((plays>>0)==0x23)//100011 plays=0x00; else //100010 plays=0x00; else if ((plays>>0)==0x21)//100001 plays=0x00; else //100000 plays=0x00; else if ((plays>>4)==0x01) if ((plays>>3)==0x03) if ((plays>>2)==0x07) if ((plays>>1)==0x0F) if ((plays>>0)==0x1F)//011111 plays=0x00; else //011110 plays=0x00; else if ((plays>>0)==0x1D)//011101 plays=0x00; else //011100 plays=0x00; else if ((plays>>1)==0x0D) if ((plays>>0)==0x1D)//011011 plays=0x00; else //011010 plays=0x00; else if ((plays>>0)==0x19)//011001 plays=0x00; else //011000 plays=0x00; else if ((plays>>2)==0x05) if ((plays>>1)==0x0B) if ((plays>>0)==0x17)//010111 connect four move if (countopt%2==0) playstat12++; if (playstat12==10)playstat12=0x00;playstat11++; else playstat22++;

Page 42: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

42 if (playstat22==10)playstat22=0x00;playstat21++; countopt++; lcd_command(0x86,start1); //line 1 stat point lcd_char(charnum(playstat11),start2); lcd_char(charnum(playstat12),start3); lcd_command(0x92,start4); //line 1 2nd stat point lcd_char(charnum(playstat21),start5); lcd_char(charnum(playstat22),start6); row=0x01; playtap(ledvectA,ledvectB, 0); row=0x01; plays=0x00; else //010110 load what slot displayload(); row=0x01; loader(func); displaydone(); for(uint8_t k=2; k<8; k++ )changeM(ledvectA[k],ledvectB[k]); _delay_ms(1); plays=0x00; else if ((plays>>0)==0x15)//010101 save what slot displaysave(); row=0x01; saver(func); displaydone(); for(uint8_t k=2; k<8; k++ )changeM(ledvectA[k],ledvectB[k]); _delay_ms(1); plays=0x00; else //010100 animation 2 plays=0x00; else //0100de if ((plays>>1)==0x09)////01001e if ((plays>>0)==0x13)//010011 animation1 plays=0x00; else //010010 Demo 2 plays=0x00; else if ((plays>>0)==0x11)//010001 Demo1 for(uint8_t k=0;k<8;k++)ledvectA[k]=ledvectUFA[k]; ledvectB[k]=ledvectUFB[k]; lcd_command(0x80,start1); lcd_char('G',start2); lcd_char('o',start3); lcd_char(' ',start4); lcd_char('G',start5); lcd_char('a',start6); lcd_char('t',start7); lcd_char('o',start8); lcd_char('r',start1); lcd_char('s',start2); lcd_char('!',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_char(' ',start6); lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_command(0xC0,start6); //line 2 lcd_char('U',start7); lcd_char('F',start8); lcd_char(' ',start1); lcd_char('S',start2); lcd_char('e',start3); lcd_char('n',start4); lcd_char('i',start5); lcd_char('o',start6); lcd_char('r',start7); lcd_char(' ',start8); lcd_char('D',start1); lcd_char('e',start2); lcd_char('s',start3); lcd_char('i',start4);

lcd_char('g',start5); lcd_char('n',start6); lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); //for(uint8_t k=2; k<8; k++ )changeM(ledvectA[k],ledvectB[k]); _delay_ms(1); row=0x01; playexplode(ledvectA,ledvectB, 0); plays=0x00; else //010000 future demo else if ((plays>>3)==0x01) if ((plays>>2)==0x03) if ((plays>>1)==0x07) if ((plays>>0)==0x0F)//001111 square tone plays=0x00; else //001110 hump tone plays=0x00; else if ((plays>>0)==0x0D)//001101 sawtooth tone plays=0x00; else //001100 sine tone plays=0x00; else if ((plays>>1)==0x05) if ((plays>>0)==0x0B)//001011 spalsh else //001010 siren playsiren( ledvectA,ledvectB, 0); row=0x01; plays=0x00; else if ((plays>>0)==0x09)//001001 explode sound playexplode(ledvectA,ledvectB, 0); row=0x01; plays=0x00; else //001000 connect four playstat11=0; playstat12=0; playstat21=0; playstat22=0; lcd_command(0x80,start1); lcd_char('R',start2); lcd_char('e',start3); lcd_char('d',start4); lcd_char('1',start5); lcd_char(':',start6); lcd_char(' ',start7); lcd_char(charnum(playstat11),start8); lcd_char(charnum(playstat12),start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char('G',start4); lcd_char('r',start5); lcd_char('e',start6); lcd_char('e',start7); lcd_char('n',start8); lcd_char('2',start1); lcd_char(':',start2); lcd_char(' ',start3); lcd_char(charnum(playstat21),start4); lcd_char(charnum(playstat22),start5); lcd_command(0xC0,start6); //line 2 lcd_char('C',start7); lcd_char('o',start8); lcd_char('n',start1); lcd_char('n',start2); lcd_char('e',start3); lcd_char('c',start4); lcd_char('t',start5); lcd_char(' ',start6); lcd_char('F',start7); lcd_char('o',start8); lcd_char('u',start1); lcd_char('r',start2); lcd_char('!',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_char(' ',start6); lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); row=0x01; playtap( ledvectA,ledvectB, 0); plays=0x00;

Page 43: Final Project Report Project Name: E-Board · A dot matrix of LED’s has a multiplex configuration where one row of the matrix is driven and the column states are manipulated as

43 else if ((plays>>2)==0x01) if ((plays>>1)==0x03) if ((plays>>0)==0x07)//000111 Clear board for(uint8_t i=0; i<8;i++ ) ledvectA[i]=0;ledvectB[i]=0; lcd_init(); plays=0x00; else //000110 player 2 wins lcd_command(0x80,start1);//line 1 lcd_char('P',start2); lcd_char('l',start3); lcd_char('a',start4); lcd_char('y',start5); lcd_char('e',start6); lcd_char('r',start7); lcd_char(' ',start8); lcd_char('2',start1); lcd_char(' ',start2); lcd_char('W',start3); lcd_char('i',start4); lcd_char('n',start5); lcd_char('s',start6); lcd_char('!',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); //for(uint8_t k=4; k<8; k++ )changeM(ledvectA[k],ledvectB[k]); _delay_ms(1); ///play sound victory row=0x01; playsiren(ledvectA,ledvectB, 0); countopt=0; plays=0x00; else if ((plays>>0)==0x05)//000101 player 1 wins lcd_command(0x80,start1);//line 1 lcd_char('P',start2); lcd_char('l',start3); lcd_char('a',start4); lcd_char('y',start5); lcd_char('e',start6); lcd_char('r',start7); lcd_char(' ',start8); lcd_char('1',start1); lcd_char(' ',start2); lcd_char('W',start3); lcd_char('i',start4); lcd_char('n',start5); lcd_char('s',start6); lcd_char('!',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); //for(uint8_t k=4; k<8; k++ )changeM(ledvectA[k],ledvectB[k]); _delay_ms(1); row=0x01; playsiren( ledvectA,ledvectB, 0); countopt=0; plays=0x00; ///play sound victory else //000100 player 2 killes if (playstat12==0) playstat11=0; playstat12=9; else playstat12=playstat12-1; lcd_command(0x86,start1); //line 1 stat point lcd_char(charnum(playstat11),start2); lcd_char(charnum(playstat12),start3); lcd_command(0x92,start4); //line 1 2nd stat point lcd_char(charnum(playstat21),start5); lcd_char(charnum(playstat22),start6); row=0x01; playslay(ledvectA,ledvectB, 0); plays=0x00; else if ((plays>>1)==0x01)

if ((plays>>0)==0x03)//000011 player 1 kills if (playstat22==0) playstat21=0; playstat22=9; else playstat22=playstat22-1; lcd_command(0x86,start1); //line 1 stat point lcd_char(charnum(playstat11),start2); lcd_char(charnum(playstat12),start3); lcd_command(0x92,start4); //line 1 2nd stat point lcd_char(charnum(playstat21),start5); lcd_char(charnum(playstat22),start6); row=0x01; playslay(ledvectA,ledvectB, 0); //for(uint8_t k=2; k<8; k++ )changeM(ledvectA[k],ledvectA[k]); _delay_ms(1); plays=0x00; else //000010 playtap( ledvectA,ledvectB, 0); //row=0b01000000; //for(uint8_t k=6; k<8; k++ )changeM(ledvectA[k],ledvectB[k]); _delay_ms(1); plays=0x00; else if ((plays>>0)==0x01)//000001 playstat11=1; playstat12=2; playstat21=1; playstat22=2; lcd_command(0x80,start1); lcd_char('R',start2); lcd_char('e',start3);

lcd_char('d',start4); lcd_char('1',start5); lcd_char(':',start6); lcd_char(' ',start7); lcd_char(charnum(playstat11),start8); lcd_char(charnum(playstat12),start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char('G',start4); lcd_char('r',start5); lcd_char('e',start6); lcd_char('e',start7); lcd_char('n',start8); lcd_char('2',start1); lcd_char(':',start2); lcd_char(' ',start3); lcd_char(charnum(playstat21),start4); lcd_char(charnum(playstat22),start5); lcd_command(0xC0,start6); //line 2 lcd_char('C',start7); lcd_char('h',start8); lcd_char('e',start1); lcd_char('c',start2); lcd_char('k',start3); lcd_char('e',start4); lcd_char('r',start5); lcd_char('s',start6); lcd_char('!',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); lcd_char(' ',start3); lcd_char(' ',start4); lcd_char(' ',start5); lcd_char(' ',start6); lcd_char(' ',start7); lcd_char(' ',start8); lcd_char(' ',start1); lcd_char(' ',start2); //for(uint8_t k=2; k<8; k++ )changeM(ledvectA[k],ledvectB[k]); _delay_ms(1); plays=0x00; //start sound //finish last row if necccessary else //000000 for(uint8_t k=0; k<8; k++ )changeM(ledvectA[k],ledvectB[k]); _delay_ms(.7); return 1;