Source code:

https://github.com/ktakiman/mathquiz (main program)

https://github.com/ktakiman/eepromprogrammer (EEPROM programmer)


Details:

The code which interfaces with Nokia 5110 LCD was written from ground up. Both math questions and music data are stored in external EEPROM, allowing me to create a new set of questions or change music without re-programming the MCU. The current stage is stored in the ATMega's internal EEPROM so the user continues from the stage that she was on last time. Level Shifter chip was used to convert 5V output pins of ATMega to 3V input pins for the LCD monitor.

The data in EEPROM needs to be in a specific binary format which is described down below. I wrote a simple Windows Form app (WIndows only... lame, I know, sorry...) to create this binary data from text files which define math questions and music data. This tool can also program EEPROM through USB/FTDI cable, which is connected to the EEPROM programmer which is made with ATtiny 4313. All source codes are available in github.


EEPROM data format:

Data are divided into 4 sections:

Contents Size
Address table section 6 bytes
Question data section depends on number of questions
Sound data section depends on number of songs and length of each song
Reward key section 4 bytes


Address table section specifies the starting address of the three following sections:

Contents Size
Starting address of question data section (always 0x0006)
2 bytes
Starting address of sound data section
2 bytes
Starting address of reward key section2 bytes


Question data section is just a list of questions preceded by the stage count and number of questions in each stage:

Contents Size
Number of stages ( = nST ) 1 byte
Number of questions per stage ( = nQPS ) 1 byte
Questions:
5 * nST * nQPS bytes


Each Question consists of:

Contents Size
First number 2 bytes
Second number 2 bytes
Operand ( '+' or '-' or '*' or '/' ) 1 byte


Sound data section is the most complex section among all. It contains the data for arbitrary number of melodies.

ContentsSize
Number of melodies ( = nMEL)1 byte
Address table for the melodies. Address is in relative to the top of sound data section. First melody's address is always 0x00012 * nMEL bytes
Melody datadepends on the length of each melody


Melody data consists of :

ContentsSize
Tempo of the melody1 byte
Number of notes ( = nNOTE )1 byte
Data for each note4 * nNOTE bytes


Each note consists of:

ContentsSize
Key: 'C', 'c', 'D', 'd', 'E', 'F', 'f', 'G', 'g', 'A', 'a', 'B' ('x' for rest)1 byte
Octave (supported range is from A3 to B6)1 byte
Enumerator for length1 byte
Denominator for length1 byte