Anda di halaman 1dari 54

Autica Final Report

Group #42 (aka R2D2)

Ryan Saunders Ryan Sullenberger


Dan Yacobucci Dan Marvin
Table of Contents
Table of Contents……………………………………...……………………….…….1

Picture of Project..…………………………………………………………………....2

Design Overview………………………………………………………………….….3

List of Components……………………………………………………………….….4

Details of Design………………………………………………………………….….5

Method of Song Programming………………………………………………….…....7

Photos of the Project…………………………………………………………....…9-12

Software Flowchart……………………………………………………………….....14

Functional Diagram…………………………………………………………….…....15

Detailed Wiring Diagrams……………………………………………….............16-18

Partial Parts List…………......................……………………………………....……19

Project Evaluation……………………………………………………………....…...20

Program Source Code ……………………………………….............………….…. 23

Sample Excel Music Spreadsheets………………………………….…………….....42

1
Picture of Final Project

2
Design Overview

The goal of the Audica is to create a self-playing instrument in which the user can select from a
list of pre-programmed songs, which can then be played back on the melodica in real time. A
melodica is a reeded instrument in which the user blows into the mouthpiece and presses keys on
the outside. When a button is pressed air is directed over a reed and a note is produced. Our
system will control 2 octaves of the melodica or 25 notes.

The instrument is controlled by PIC micro controllers, which will take input from the user and
complete the necessary actions to start and play a song. The unit is powered on with toggle
switches at the back of the control box and begins a countdown sequence ending with a beep
indicating it is ready for song selection. Songs are listed next to the display and are played by
entering the coorisponding song number into the 12 key keypad. Once the number has been
typed, the name of the song will appear on the LCD display above the keypad along with song
duration and playback begins.

This begins a succession of events. Air, which is supplied via compressed air tank, is turned on
by a valve allowing it to flow through the instrument. Using solenoids, the PIC activates the
proper notes in succession and the song is played. When the song is finished the air valve closes
and the system waits for the next command.

3
List of Components

A. Output Display

• LED (2 – Indicates signal output from pic to relays)


• LED (Input received indicator)
• LCD (Display song name and track information)

B. Audio Output Device

• Speaker with software-generated sound effects (signal all clear)


• Melodica air powered keyboard instrument

C. Manual Data Input

• Switch (turn on/off air valve)


• Keypad (select song number, select manual or automatic mode)

D. Automatic Sensor Input

• Light sensor (for automatic song selection based on ambient light level)

E. Actuators

• 25 Solenoids (to press Melodica keys)


• 25 Relays
• 1 Air Valve

F. Logic, Counting, Integration, and Control

• Programmed logic
• Menu-driven software (LCD instructions)
• Multiple PIC microcontrollers
o 2 PIC16F88
o 2 PIC18F4680

4
Details of Design

At the heart of the design is the control box where all of the input, actuators and circuitry are
housed. The back panel of the box holds computer power supplies which take wall power and
convert it to 5V and 12V DC and is used to power the circuits and solenoids respectively.

On the front of the control box is the control panel which houses a 12 key keypad, lcd display
and PC speaker. Wires run from the panel to the circuit board inside. The melodica sits on top of
the control box with two slits just in front of it. Under each slit are the mounted solenoids which
are spaced to be underneath the respective keys they control. Solenoids for the white keys are on
the front of the board and black keys on the back. Using bent coat hanger wire the pull type
solenoids are connected to the keys on the melodica.

Inside the control box is the main circuit board which holds all of the components of the circuit
in the functional diagram. The circuit consists of 4 PIC microcontrollers and as can be seen from
the functional diagram, each PIC serves a unique purpose. Because PICs can only execute single
commands in succession we opted to use 4 to ensure smooth playback and operation of the
device. Also mounted on the circuit board are 3 LED indicator lights. One red light remains on
whenever power to the circuit is present and dims for a half of a second whenever input is
received from the keypad. This helps with troubleshooting the system. The other two LED’s (red
and yellow) flash alternatively to indicate when the pic has output a new signal to the relays.

The first PIC is a PIC18F4680 which connects to all input and serves strictly as system control. It
receives input from the keypad and light sensor system (explained later). The PIC is programmed
to interpret keystrokes and correlate them with a database of songs stored in EEPROM. Once
recognized, it outputs the name, duration and number of the track on the LCD display and
playback mode begins. The song number is output serially to the music playback PIC
(PIC18F4680). The music playback PIC recalls four 8-bit note patterns which are stored in its
memory for each note of the song. Each 8-bit pattern corresponds to set combinations of the 25
output pins, setting them to either high or low. A pin on “high” indicates the note is on, while
“low” is an indication the note is off. Each pin out is connected to the IDE output connection on
the back circuit board. When the song has completed the system waits for the next input
command.

An IDE cable runs from the control board to the relay board. Contained on this board are 25
relays where the input leads from the bus are connected to each relay. 12V power is supplied to
the relays so when a 5 volt signal is received the relay turns on and passes high power signal to
the respective solenoid, thus playing the appropriate note. High power output is sent via IDE
connection from the relay board to the solenoid mounting board.

When power is first supplied to the system, the PIC automatically initiates the power up
sequence and outputs an audio signal to the speaker which sounds like a series of musical beeps
indicating that the system is ready and it lights the red LED giving the “All Clear”. This entire
sequence is pre programmed into the PIC’s EEPROM.

5
The system has an automatic playback mode which is activated by pressing the star key. Once
activated, the control pic looks at input data from the light sensor to determine whether the lights
are on or off. Depending on this condition it will play “Taps” if the lights are off and “Revile” if
the lights are on. The light sensor is connected to its own PIC16F88 whose sole responsibility is
to process the incoming signal from the light sensor and send the data serially to the control pic.
This relives the control of extra processing duties.

The following is a list of songs the melodica can play and their corresponding keypad number.

1 - Test Pattern
2 - The Legend of Zelda theme song
3 - Greensleves
4 - The Chicken Dance
5 - It’s a Small World
6 - Moonlight Sonota

* - Activates automatic playback mode

6
Method of Song Programming

By using a spreadsheet to declare the output settings of PORTA, PORTB, PORTC, and PORTD
of a 40-pin PIC, potentially any musical composition can be converted into a form in which
PICBASIC can read and therefore output to the melodica.

In the spreadsheet, the first eight columns will represent PORTA, which will correspond to
musical notes F to C. The second set of eight columns will represent PORTB (corresponding to
musical notes C# through G#) and so on. There will also be a column for the duration of the note
configuration (in ms). A “1” entered into any cell means that the corresponding note is “on”, and
a “0” means that the corresponding note is “off”. After the set duration for any given note
configuration has passed, the new note configuration and duration is read from the next row.

Example showing what the F-major scale would look like:

F F# G G# A A# B C C# D D# E F Duration PORTA PORTB

1 500 %10000000 %00000000

1 250 %00100000 %00000000

1 250 %00001000 %00000000

1 250 %00000100 %00000000

1 250 %00000001 %00000000

1 250 %00000000 %01000000

1 250 %00000000 %00010000

1 500 %00000000 %00001000

1 250 %00000000 %00010000

1 250 %00000000 %01000000

1 250 %00000001 %00000000

1 250 %00000100 %00000000

1 250 %00001000 %00000000

7
1 250 %00100000 %00000000

1 500 %10000000 %00000000

After a song entry is completed, columns containing data for the Duration, PORTA, PORTB and
so on are transposed into rows. This allows easy export as common separated values (CSV).
Using the comma separated value export, the data can be copied and pasted into a PICBASIC
array containing all of the values. By using a loop and counter in PICBASIC PRO, the note
patterns in the arrays can be obtained one after the other and held for the given duration.

8
Photos of the Project

Figure 1 : The solenoid board before interfaced to the melodica. The solenoids in the picture are for the white keys.
The black key solenoids are located on the back of the board.

Figure 2 : IDE cable for sending the proper signal to the solenoids.

9
LCD

Music
playing PIC
(18F4680)
Relay board
interface
Jumpers for interface Master PIC
to the light sensor (18F4680)

Keypad
interface
LCD
PIC
PIC for A/D
(16F88)
conversion -
sensor
Figure 3 : The master circuit which controls the user interface and also houses the music playing PIC.

Figure 4 : The backside of the master circuit protoboard.

10
Figure 5 : The top of the relay board.

Figure 6 : The bottom of the relay board showing soldering connections.

11
Figure 7 : The TEMT6000, a light sensor obtained from SparkFun electronics.

Figure 8 : A picture looking inside of the project while it is on. Some solenoids can be seen.

12
Figure 9: The front side of the final product showing the LCD, keypad, speaker holes and the magical blue light
coming from inside of the box.

13
Software Flowchart

Master PIC Music Playing PIC

START START

Define I/O pins Define I/O pins

Define constants and Define constants and


variables variables

Initialize LCD and


await instruction
Has the PIC
from keypad received
instructions
yet? NO

Has a button on
the keypad YE
been pressed? S
NO Turn on solenoids

YE
S
Display
corresponding song END
on LCD

Send the music playing


PIC instructions.

Return to main menu

14
15
16
17
18
Partial Parts List

Item Quantity Description Supplier Part Price


Number
PIC16F88 2 10-bit A/D, 18 pin, PWM Microchip PIC16F88- Free
I/P
PIC18F4680 2 10-bit A/D, 40 pin, PWM Microchip PIC18F4680- Free
I/P
SH9543 25 24VDC PULL-TYPE SOLENOID All SOL-58 $1.50
Electronics
Aromat S4E13 13 4A1/20HP/125,250VAC,3A,30VDC LSI N/A Free
Relay
Aromat ST2E- 12 8A1/4HP/125,250VAC Relay LSI N/A Free
DC5V
TEMT6000 1 Ambient light sensor, analog, NPN SparkFun COM-08348 $1.25
transistor Electronics
Melodica 1 Horner Student 32 Key Melodica Musicians 702712 $40
Friend

Keeping costs down on this project was a priority for us both because we didn’t have much to
spend and because it forced us to be more creative. When it was possible we borrowed and had
parts donated. LSI Logic donated all of the relays, proto-boards and other miscillaneous supplies
for the project.

19
Project Evaluation

Output Display

Our project implements a 2 line LCD display which is interfaced with the project in a useful
manner improving operational easablitity and functionality. It provides useful information to the
user as to which song is playing, the duration of that song and whether the unit is powered on
and ready. In addition to the LCD display, LEDs were used on the circuit boards themselves for
ease of troubleshooting and demonstration. These are interfaced with the pic and run at all times
when the melodica is powered up and running. The two visual aids function with the project as a
whole and meet the requirements for this category. Extra research was needed to operate the
LCD and two different display types were tried before settling on this one. We ended up
programming our own pic to use a customized method of communication with the control pic
that worked better than the preprogrammed pic that came with the display.

Audio Output Device

There are two audio output devices on the melodica. The most obvious is the melodica itself.
While this is not electrically connected to the circuit, it is actuated and controlled by the
electronics contained inside and creates an audible output. This strong part of our project is a
unique as an audio device. It required extra research to design our mechanisms to depress the
keys the right amount, with enough force and quickly enough to be useful and we had to
calibrate an air supply to provide the right pressure. We found that the system worked better with
a controlled leak because the pressure which built up in the melodica when no note were playing
would prevent the first notes from being audible. The computer speaker beeps when the unit is
powered on and ready, serving as an indicator to the user and improving usability.

Manual Data Input

A 12 button keypad is incorporated as the main source of input for song selection. Each key
corresponds to an individual song and serves as an effective and intuitive method of controlling
the device.

Automatic Sensor Input

The light sensor came with very little documentation and required experimentation to determine
voltage output levels compared to ambient light levels. As a result of these experiments we were
able to calibrate the system to recognize “lights on” as a normally lit room and “lights off” to be

20
a darkened, but not dark, room. We were successfully able to implement the sensor into our
project.

Actuators

25 relays and 25 solenoids were employed to mechanically operate the keyboard of the melodica.
Considerable research went into finding solenoids that had the displacement and force we needed
at a cost which was reasonable for our project. The solenoids we found require a lot of current
and it became obvious that relays were going to be needed. Additional research and some trial
and error resulted as there is no specification for the instantaneous ‘power on’ current
requirements for the solenoids and we had no accurate way to measure it. Also, relays that could
handle our current requirements were prohibitively expensive and forced us to find an alternative
source. LSI Logic donated the relays for the entire project. Once the relays were found,
considerable time and effort was put into sodering them in an organized fashion such that the
100+ wires were organized and manageable.

Logic, Counting, Integration and Control

A total of 4 PICS were interfaced and programmed to work together as a whole. Research went in
to the operation of 40 pin PICS and their available memory for song storage. Memory storage
was extremely important to us because of the large amount of data it takes to store all of our
songs. It was found that the PIC18F4680 would work the best for us because of its 64 Kbytes of
program memory size, allowing us plenty of storage for our songs without having to use an
external EEPROM.

With the use of the 40 pin PICS we had to learn about MPASMWIN and how to use it. The 18F
and 18C series PICmicrocontrollers require a different assembler than the 16F series. Most of the
programming of the PICs was able to be done in house without having to utilize the mechatronics
engineering lab using simple JDM serial programmers. They were able to handle any of the types
of PICs that we needed.

One of the major tasks with our circuit was to find a method for all of the PIC microcontrollers to
communicate with one another. Serial communication came to mind, but noticing that all of our
PICs had many pins to spare, we decided to invent our own 4-bit communication protocol. How
it works is a handshake line goes HIGH from the master PIC which triggers all of the PIC
microcontrollers (mainly the LCD PIC and the music playing PIC) to listen for a signal. Using 4
pins on each PIC, a 4-bit number was sent after the handshake lines went high. This was a simple
yet extremely efficient way to communicate and send commands between one chip and another.

21
This method limits the entire system to 16 commands, but with only 9 songs requiring
commands to be played, this was not a problem for our project.

Obviously a lot of logic went into the programming of the music for the melodica, having to read
the next set of notes from an array everytime a note changes and holding it for a given amount of
time. This is of course explained in much greater detail in the section titled “Method of Song
Programming” above.

Qualitative Adjustments

There are two categories in which our project really stands out. When we decided to program
songs into the pic microprocessor we realized how tedious this would be if we had to input each
note into PicBasic one by one so a better solution was sought. After searching through alternative
methods of musical input revealed additional expense to the project, a custom software solution
was written. The details of this solution were explained on page 7 and involved using MS Excel
to graphically input each note and it’s duration. From there it was a simple cut and paste
operation that saved our group countless hours of programming and troubleshooting as we
solved timing issues. Without the aid of sheet music for several of our songs, programming was
largely trial and error and would not have been possible without this method.

Additionally, the components internal to the melodica are put together in an organized and clean
fashion. The use of standardized IDE cables makes the project both clean and reproducable. With
25 relays needing 4 wires each, 25 solenoids needing 2 wires each, 2 40 pin pics and 2 18 pin
pics, there are hundereds of wiring connections in the project. All of which were done neatly and
professionally as detailed in the pictures presented previously.

We feel that these two atributes go above and beyond the normal expectations outlined in the
project objectives.

22
PROGRAM SOURCE CODE:
'//////////////////////////////////////////////////////////////////////////////
'
' MUSIC DELIVERY MICROCHIP - MAIN CONTROLLING CHIP
' ==============================================================
' Date: November 24, 2008
' Author: Ryan Sullenberger
' Group: 42 (R2D2)
' Colorado State University, Mechanical Engineering
'
' PIC18F4510
'
'//////////////////////////////////////////////////////////////////////////////

DEFINE OSC 8 ' Tells the PIC what clock we are using
OSCCON.4 = 1 ' Sets the internal oscillator frequency to 8 MHz
OSCCON.5 = 1
OSCCON.6 = 1
ADCON1 = 15 ' Turns off analog to digital conversion
CMCON = 7 ' Turns off analog comparison pins

'VARIABLES
Cnt VAR word

'TRIS SETTINGS
TRISA = %00000000 ' Set all PORTA pins to OUTPUTS
TRISB = %00000000 ' Set all PORTB pins to OUTPUTS
TRISC = %11111111 ' Set all PORTC pins to INPUTS
TRISD = %11111111 ' Set all PORTD pins to INPUTS

INPUT PORTA.2
INPUT PORTA.5

PORTB = %00000000 ' Initially set all PORTB pins to 0

'BLINK POWER LED TO INDICATE CIRCUIT IS ON


LOW PORTA.1
PAUSE 500
HIGH PORTA.1
PAUSE 500

'SIGNAL ALL CLEAR THROUGH SPEAKER


'///////////////////////
FREQOUT PORTB.7,125,2500
PAUSE 125
FREQOUT PORTB.7,125,2250
PAUSE 125
FREQOUT PORTB.7,125,2000
PAUSE 125
FREQOUT PORTB.7,125,1750
PAUSE 2000
'////////////////////////

PORTB = %00000000 ' Initially set all PORTB pins to 0

'MAIN LOOP
main: ' This loop waits for input from keypad and sends the corresponding data to the LCD PIC
and the music playing PIC
IF PORTD.0 = 1 THEN ' Button 1
TOGGLE PORTA.1
PORTB = %00000011 ' Send bit-pattern to play song number 1
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
ENDIF
IF PORTD.1 = 1 THEN ' Button 2
TOGGLE PORTA.1
PORTB = %00000101 ' Send bit-pattern to play song number 2
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
ENDIF
IF PORTD.2 = 1 THEN ' Button 3
TOGGLE PORTA.1
PORTB = %00000111 ' Send bit-pattern to play song number 3
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
ENDIF
IF PORTD.3 = 1 THEN ' Button 4
TOGGLE PORTA.1
PORTB = %00001001 ' Send bit-pattern to play song number 4
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
ENDIF
IF PORTC.4 = 1 THEN ' Button 5

23
TOGGLE PORTA.1
PORTB = %00001011 ' Send bit-pattern to play song number 5
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
ENDIF
IF PORTC.5 = 1 THEN ' Button 6
TOGGLE PORTA.1
PORTB = %00001101 ' Send bit-pattern to play song number 6
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
ENDIF
IF PORTC.6 = 1 THEN ' Button 7
TOGGLE PORTA.1
PORTB = %00001111 ' Send bit-pattern to play song number 7
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
ENDIF
IF PORTC.7 = 1 THEN ' Button 8
TOGGLE PORTA.1
PORTB = %00010001 ' Send bit-pattern to play song number 8
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
ENDIF
IF PORTD.4 = 1 THEN ' Button 9
TOGGLE PORTA.1
PORTB = %00010011 ' Send bit-pattern to play song number 9
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
ENDIF
IF PORTD.5 = 1 THEN ' Button *
TOGGLE PORTA.1
PORTB = %00010101 ' Send bit-pattern to display automatic mode on LCD
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
PAUSE 6000
GOTO AUTOMATIC
ENDIF
IF PORTD.6 = 1 THEN ' Button 0
TOGGLE PORTA.1
PORTB = %00010111 ' Send bit-pattern to display fun message on LCD
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
ENDIF
IF PORTD.7 = 1 THEN ' Button #
TOGGLE PORTA.1
PORTB = %00011001 ' Send # bit-pattern to LCD. Does not really do anything.
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
ENDIF
GOTO main

'AUTOMATIC MODE
AUTOMATIC:
IF PORTA.5 = 1 && PORTA.2 = 0 THEN ' The light is DIM! Send the appropriate signal to the music playing PIC,
TOGGLE PORTA.1 ' and blink the indicator light quickly.
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
TOGGLE PORTA.1
PAUSE 50
HIGH PORTA.1

24
TOGGLE PORTA.1
PORTB = %00010001 ' Send the "light is dim" bit-pattern.
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
PAUSE 5
PORTB = %00010101 ' Send the "return to main menu" bit-pattern to the LCD PIC.
PAUSE 1000
PORTB = %00000000
GOTO main
ENDIF
IF PORTA.2 = 1 && PORTA.5 = 0 THEN ' The light is ON! Send appropriate signal.
TOGGLE PORTA.1
PAUSE 250
TOGGLE PORTA.1
PAUSE 250
TOGGLE PORTA.1
PAUSE 250
TOGGLE PORTA.1
PAUSE 250
TOGGLE PORTA.1
PAUSE 250
TOGGLE PORTA.1
PAUSE 250
TOGGLE PORTA.1
PAUSE 250
HIGH PORTA.1
TOGGLE PORTA.1
PORTB = %00010011 ' Send "light is on" bit-pattern.
PAUSE 1000
TOGGLE PORTA.1
PORTB = %00000000
PAUSE 5
PORTB = %00010101 ' Return the LCD to it's main menu.
PAUSE 1000
PORTB = %00000000
GOTO main
ENDIF
GOTO AUTOMATIC

25
'//////////////////////////////////////////////////////////////////////////////
'
' MUSIC DELIVERY MICROCHIP - MUSIC DELIVERY MICROCHIP
' ==============================================================
' Date: November 23, 2008
' Author: Ryan Sullenberger
' Group: 42 (R2D2)
' Colorado State University, Mechanical Engineering
'
' PIC18F4680
'
'//////////////////////////////////////////////////////////////////////////////

DEFINE OSC 8 ' Tells the PIC what clock we are using
OSCCON.4 = 1 ' Sets the internal oscillator frequency to 8 MHz
OSCCON.5 = 1
OSCCON.6 = 1
ADCON1 = 15 ' Turns off analog to digital conversion
CMCON = 7 ' Turns off analog comparison pins

'DEFINE ALL VARIABLES


Cnt VAR Word
CntTotal VAR Word
Choice VAR Byte
PatternB VAR Byte
PatternC VAR Byte
PatternD VAR Byte
PatternA VAR Byte
Time VAR Word

'TRIS SETTINGS
TRISB = %00000000
TRISC = %00000000
TRISD = %00000000

OUTPUT PORTA.0 ' Set PORTA.0 as an output for solenoid #25

'SEND ALL CLEAR SIGNAL TO THE INDICATOR LEDs


PAUSE 500
HIGH PORTA.1
HIGH PORTA.2
PAUSE 250
LOW PORTA.1
LOW PORTA.2
PAUSE 250
HIGH PORTA.1
HIGH PORTA.2
PAUSE 250
LOW PORTA.1
LOW PORTA.2
PAUSE 250
HIGH PORTA.1
HIGH PORTA.2

'LOOP THAT CHECKS FOR SIGNAL THAT TELLS WHICH SONG TO PLAY:
SONGCHECK:
IF PORTA.3 = 1 THEN
PAUSE 50
IF PORTE.2 = 1 && PORTE.1 = 0 && PORTE.0 = 0 && PORTA.5 = 0 THEN
Choice = 1
GOTO main
ENDIF
IF PORTE.2 = 0 && PORTE.1 = 1 && PORTE.0 = 0 && PORTA.5 = 0 THEN
Choice = 2
GOTO main
ENDIF
IF PORTE.2 = 1 && PORTE.1 = 1 && PORTE.0 = 0 && PORTA.5 = 0 THEN
Choice = 3
GOTO main
ENDIF
IF PORTE.2 = 0 && PORTE.1 = 0 && PORTE.0 = 1 && PORTA.5 = 0 THEN
Choice = 4
GOTO main
ENDIF
IF PORTE.2 = 1 && PORTE.1 = 0 && PORTE.0 = 1 && PORTA.5 = 0 THEN
Choice = 5
GOTO main
ENDIF
IF PORTE.2 = 0 && PORTE.1 = 1 && PORTE.0 = 1 && PORTA.5 = 0 THEN
Choice = 6
GOTO main
ENDIF
IF PORTE.2 = 1 && PORTE.1 = 1 && PORTE.0 = 1 && PORTA.5 = 0 THEN
Choice = 7
GOTO main
ENDIF
IF PORTE.2 = 0 && PORTE.1 = 0 && PORTE.0 = 0 && PORTA.5 = 1 THEN
Choice = 8
GOTO main

26
ENDIF
IF PORTE.2 = 1 && PORTE.1 = 0 && PORTE.0 = 0 && PORTA.5 = 1 THEN
Choice = 9
GOTO main
ENDIF
ENDIF
GOTO SONGCHECK

'MAIN MUSIC PLAYING LOOP


main:
HIGH PORTA.1 ' Indicator of note progression on
HIGH PORTA.2 ' Indicator light initially on
Cnt = 0 ' Initialize CNT to 0
NXT:
IF Choice = 1 THEN ' Song 1 was selected. Find the note patterns for song
GOSUB NOTEA1 ' Find the bit pattern to send to PORTA
GOSUB NOTEB1 ' Find the bit pattern to send to PORTB
GOSUB NOTEC1 ' Find the bit pattern to send to PORTC
GOSUB NOTED1 ' Find the bit pattern to send to PORTD
GOSUB DURATION1 ' NOTE: This is the same for selections
GOSUB SONGLENGTH1 ' 2 - 9 below, all depending on which song
ENDIF ' is being played.
IF Choice = 2 THEN ' Song 2 was selected. Find the note patterns for song
GOSUB NOTEA2
GOSUB NOTEB2
GOSUB NOTEC2
GOSUB NOTED2
GOSUB DURATION2
GOSUB SONGLENGTH2
ENDIF
IF Choice = 3 THEN ' Song 3 was selected. Find the note patterns for song
GOSUB NOTEA3
GOSUB NOTEB3
GOSUB NOTEC3
GOSUB NOTED3
GOSUB DURATION3
GOSUB SONGLENGTH3
ENDIF
IF Choice = 4 THEN ' Song 4 was selected. Find the note patterns for song
GOSUB NOTEA4
GOSUB NOTEB4
GOSUB NOTEC4
GOSUB NOTED4
GOSUB DURATION4
GOSUB SONGLENGTH4
ENDIF
IF Choice = 5 THEN ' Song 5 was selected. Find the note patterns for song
GOSUB NOTEA5
GOSUB NOTEB5
GOSUB NOTEC5
GOSUB NOTED5
GOSUB DURATION5
GOSUB SONGLENGTH5
ENDIF
IF Choice = 6 THEN ' Song 6 was selected. Find the note patterns for song
GOSUB NOTEA6
GOSUB NOTEB6
GOSUB NOTEC6
GOSUB NOTED6
GOSUB DURATION6
GOSUB SONGLENGTH6
ENDIF
IF Choice = 7 THEN ' Song 7 was selected. Find the note patterns for song
GOSUB NOTEA7
GOSUB NOTEB7
GOSUB NOTEC7
GOSUB NOTED7
GOSUB DURATION7
GOSUB SONGLENGTH7
ENDIF
IF Choice = 8 THEN ' Song 8 was selected. Find the note patterns for song
GOSUB NOTEA8
GOSUB NOTEB8
GOSUB NOTEC8
GOSUB NOTED8
GOSUB DURATION8
GOSUB SONGLENGTH8
ENDIF
IF Choice = 9 THEN ' Song 9 was selected. Find the note patterns for song
GOSUB NOTEA9
GOSUB NOTEB9
GOSUB NOTEC9
GOSUB NOTED9
GOSUB DURATION9
GOSUB SONGLENGTH9
ENDIF
' SEND MUSIC PATTERN TO ALL PORTS
PORTA.0 = PatternA
PORTB = PatternB
PORTC = PatternC
PORTD = PatternD
PAUSE Time ' Play the selected notes for the given duration.

27
PORTA.0 = 0 ' Reset all notes to NULL
PORTB = %00000000 ' Reset all notes to NULL
PORTC = %00000000 ' Reset all notes to NULL
PORTD = %00000000 ' Reset PORTD.0 to NULL
Cnt = Cnt + 1 ' Cnt ++
IF Cnt > CntTotal THEN GOTO ENDSONG ' If the song has played it's last note, end the song.
GOSUB BLINK ' Toggle the note progression LED.
GOTO NXT ' Go gather the next note pattern to play.

' ************************** SONG 1 - Test Pattern


' **************************
' ************************** In these sections you will find the song length (note count),
' ************************** and all of the note patterns that need to be sent to the
' ************************** different ports to played select music.
' **************************

SONGLENGTH1:
CntTotal = 236
RETURN

NOTEB1:
' Find which note to play.
Lookup
Cnt,[%10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000001,%00000010,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000,%00000000,%10000000,%01000000,%00100000,
%00010000,%00001000,%00000100,%00000010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000
000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0
0000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000010
,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000,%00000000,%10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%0000
0010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000010,%00000100,%00001000,%00010000,%001
00000,%01000000,%10000000,%00000000,%10000000,%00100000,%00000010,%00000100,%00001000,%00000000,%00000000,%00000100,%00100000,%00000000,
%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000
000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0
0000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000
0000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000010,%00000100,%00000010,%00000001,%00000010,%
00000100,%00001000,%00010000,%00100000,%01000000,%10000000],PatternB
RETURN
END ' End of program, in case PIC gets "lost"

NOTEC1:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%10000000,%01000000,%00100000,%00010000,%00001000,%
00000100,%00000010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000010,%00000100,%00001000,%00010000,%00100000,%010
00000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,
%00000000,%00000000,%00000000,%00000000,%00000000,%10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001,%00000
000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0
0000000,%00000000,%00000000,%00000000,%00000001,%00000010,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000,%00000000,%00000000
,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000
0000,%00000000,%10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000001,%00000010,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00100000,%01000000,%00000000,%00000100,%00001000,
%00010000,%00100000,%01000000,%00000010,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000,%01000000,%00100000,%00010000,%00001
000,%00000100,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0
0000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000
0001,%00000010,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000],PatternC
RETURN
END ' End of program, in case PIC gets "lost"

NOTED1:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001,%00000000,%00000001,%0000001
0,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,
%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%10000
000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001,%00000000,%00000001,%00000010,%00000100,%00001000,%00010000,%0
0100000,%01000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000
0000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%10000000,%01000000,%00100000,%00010000,%
00001000,%00000100,%00000010,%00000001,%00000000,%00000001,%00000010,%00000100,%00001000,%00010000,%00100000,%01000000,%10000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,

28
%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000
000,%00000000,%00000000,%01000000,%00010000,%00000100,%00000001,%00000000,%00000001,%00000000,%00000001,%00000000,%00000001,%00000000,%0
0000001,%00000000,%00000001,%00000000,%00000001,%00000000,%00000001,%00000010,%00000001,%00000010,%00000001,%00000010,%00000001,%00000010
,%00000100,%00000010,%00000100,%00000010,%00000100,%00000010,%00000100,%00000010,%00001000,%00010000,%00100000,%01000000,%10000000,%0000
0000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000],PatternD
RETURN
END ' End of program, in case PIC gets "lost"

NOTEA1:
' Find which note to play.
Lookup
Cnt,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],PatternA
RETURN
END ' End of program, in case PIC gets "lost"

DURATION1:
' Find out how long to play each note.
Lookup2
Cnt,[500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,50
0,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,1000,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,1
25,125,125,125,125,125,125,125,125,500,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,125,1
25,1000,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,6
0,60,60,60,60,60,60,60,1000,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50
,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,5
0,50,50,50],Time ' LOOKUP takes a given segment from an array.
RETURN
END ' End of program, in case PIC gets "lost"

' ************************************************************* SONG 2 - LEGEND OF ZELDA


' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************

SONGLENGTH2:
CntTotal = 145
RETURN

NOTEB2:
' Find which note to play.
Lookup
Cnt,[%00000100,%10000000,%00000000,%10000000,%00000100,%00010000,%01000000,%00010000,%00000100,%01000000,%00000000,%01000000,%00000100,%
00001000,%00100000,%00001000,%00000000,%00000100,%10000000,%00000000,%00000100,%00000100,%00000001,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,
%00000000,%00000000,%00000000,%00000000,%00000001,%00000000,%00000001,%00000000,%00000000,%00000000,%00000000,%10000000,%00000000,%10000
000,%00000000,%10000000,%00000000,%10000000,%00000000,%10000000,%00000000,%10000000,%00000000,%10000000,%00000000,%10000000,%00000000,%1
0000000,%00000000,%10000000,%00000100,%10000000,%00000000,%00000100,%00000100,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000
,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000
0000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000100,%00000001,%00000000,%
00000001,%00000000,%00000000,%00000000,%00000000,%10000000,%00000000,%10000000,%00000000,%10000000,%00000000,%10000000,%00000000,%1000000
0,%00000000,%10000000,%00000000,%10000000,%00000000,%10000000,%00000000,%10000000,%00000000,%10000000],PatternB
RETURN
END ' End of program, in case PIC gets "lost"

NOTEC2:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01000000,%00100000,%00001000,%0000000
0,%00001000,%00000000,%00001000,%00000100,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000100,%00000001,%000
00100,%00001000,%00000000,%00001000,%00100000,%00000000,%00100000,%00001000,%00000100,%00001000,%00100000,%10000000,%00000000,%10000000,
%00100000,%00001000,%00100000,%10000000,%00000000,%00000000,%00000000,%01000000,%00010000,%00000010,%00001000,%00000000,%00000000,%00000
000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0
0000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01000000,%00100000,%00001000,%00000000,%00001000
,%00000000,%00001000,%00000100,%00000001,%00000000,%00000000,%00000000,%00000000,%00001000,%00000100,%00000000,%00000000,%00001000,%0000
0000,%00001000,%00000100,%00000000,%00000000,%00001000,%01000000,%00100000,%00000100,%00001000,%10000000,%00000000,%00000000,%00000000,%
00000000,%01000000,%00010000,%00000010,%00001000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000],PatternC
RETURN
END ' End of program, in case PIC gets "lost"

NOTED2:
' Find which note to play.
Lookup

29
Cnt,[%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%01000000,%00000000,%01000000,%00000000,%01000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,
%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000
000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0
0000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
,%00000000,%00000000,%00000000,%00000000,%01000000,%00001000,%00010000,%10000000,%00000000,%00000000,%01000000,%10000000,%00000000,%0000
0000,%00000000,%00000000,%01000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000],PatternD
RETURN
END ' End of program, in case PIC gets "lost"

NOTEA2:
' Find which note to play.
Lookup
Cnt,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],PatternA
RETURN
END ' End of program, in case PIC gets "lost"

DURATION2:
' Find out how long to play each note.
Lookup2
Cnt,[1668,284,50,334,334,167,167,2334,1668,284,50,334,334,167,167,1667,667,667,667,334,334,167,167,167,167,1618,50,284,50,167,334,167,1
668,167,117,50,167,334,167,501,167,1284,50,667,284,50,167,167,1334,334,334,284,50,167,167,1334,334,334,284,50,167,167,1334,667,334,107,5
0,107,50,284,50,107,50,107,50,284,50,107,50,107,50,284,50,334,667,667,334,334,167,167,167,167,1618,50,284,50,167,334,167,2001,667,667,1
334,667,2001,667,667,1284,50,667,2001,667,667,1334,667,2001,667,667,1334,667,284,50,167,167,1334,667,334,107,50,107,50,284,50,107,50,107
,50,284,50,107,50,107,50,284,50,334],Time ' LOOKUP takes a given segment from an array.
RETURN
END ' End of program, in case PIC gets "lost"

' ************************************************************* SONG 3 - GREENSLEEVES


' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************

SONGLENGTH3:
CntTotal = 40
RETURN

NOTEB3:
' Find which note to play.
Lookup
Cnt,[%00000000,%10000000,%10000000,%10000000,%10000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000001,%00000001,%00000001,%00000000,%10000000,%10000000,%10000000,%10000000,%10000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000001,%00000001,%10000000,%00000000,%10000000],Pat
ternB
RETURN
END ' End of program, in case PIC gets "lost"

NOTEC3:
' Find which note to play.
Lookup
Cnt,[%00001000,%00000001,%00000000,%00000000,%00000000,%00000000,%00100000,%00100010,%00100000,%00101000,%00100010,%10000001,%10001000,%
10000000,%10001000,%10010000,%10001000,%00000010,%00010000,%00000000,%00001000,%00000001,%00000000,%00000000,%00000000,%00000000,%0010000
0,%00100010,%00100000,%00101000,%00100010,%10000001,%10000010,%10001000,%00010000,%01000000,%00010000,%00001000,%00000000,%00001000],Pat
ternC
RETURN
END ' End of program, in case PIC gets "lost"

NOTED3:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%01000000,%00010000,%00001000,%00010000,%01000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01000000,%00010000,%00001000,%00010000,%0100000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000],Pat
ternD
RETURN
END ' End of program, in case PIC gets "lost"

NOTEA3:
' Find which note to play.
Lookup Cnt,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],PatternA

30
RETURN
END ' End of program, in case PIC gets "lost"

DURATION3:
' Find out how long to play each note.
Lookup2
Cnt,[500,1000,500,750,250,500,1000,500,750,250,500,1000,450,50,750,250,500,1000,500,1000,500,1000,500,750,250,500,1000,500,750,250,500,
750,250,500,750,250,500,1450,50,1500],Time ' LOOKUP takes a given segment from an array.
RETURN
END ' End of program, in case PIC gets "lost"

' ************************************************************* SONG 4 - CHICKEN DANCE


' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************

SONGLENGTH4:
CntTotal = 117
RETURN

NOTEB4:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,
%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000
000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0
0000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000
0000,%00000000,%00000000,%00000000,%00000000,%00000001],PatternB
RETURN
END ' End of program, in case PIC gets "lost"

NOTEC4:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000010,%00000000,%00000010,%00000000,%00000000,%00000000,%00010000,%00000000,%00010000,%00000010,%00000000,%00000010,%
00000000,%00000010,%00000000,%00000000,%00000000,%00010000,%00000000,%00010000,%00000010,%00000000,%00000010,%00000000,%00000010,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01000000,%00001000,%00010010,%00001000,%00000000,%00001000,%000
00000,%00001000,%00000010,%00000000,%00000010,%01000000,%00000000,%01000000,%00001000,%00000000,%00001000,%00000000,%00001000,%00000010,
%00000000,%00000010,%01000000,%00000000,%01000000,%00001000,%00000000,%00001000,%00000000,%00001000,%00000010,%00000000,%00000010,%00000
000,%00000000,%00000000,%00000000,%00000000,%00010010,%00001000,%00000000,%00000010,%00000000,%00000010,%00000000,%00000010,%00000000,%0
0000000,%00000000,%00010000,%00000000,%00010000,%00000010,%00000000,%00000010,%00000000,%00000010,%00000000,%00000000,%00000000,%00010000
,%00000000,%00010000,%00000010,%00000000,%00000010,%00000000,%00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000
0000,%00000000,%00010010,%00001000,%00000010,%00010000],PatternC
RETURN
END ' End of program, in case PIC gets "lost"

NOTED4:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000000,%00000000,%10000000,%00000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%10000000,%00000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%1000000
0,%00000000,%10000000,%00010000,%00000000,%00010000,%00100000,%00000000,%00100000,%10000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,
%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00100
000,%00000000,%00100000,%10000000,%00000000,%00000000,%10000000,%10010000,%00100000,%00000000,%00000000,%00000000,%00000000,%10000000,%0
0000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%10000000,%00000000,%10000000,%00000000
,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%10000000,%00000000,%10000000,%00010000,%00000000,%00010000,%0010
0000,%00000000,%00000000,%10000000,%00100000,%00010000],PatternD
RETURN
END ' End of program, in case PIC gets "lost"

NOTEA4:
' Find which note to play.
Lookup
Cnt,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],PatternA
RETURN
END ' End of program, in case PIC gets "lost"

DURATION4:
' Find out how long to play each note.
Lookup2

31
Cnt,[375,113,38,150,113,38,150,113,38,150,263,38,113,38,150,113,38,150,113,38,150,263,38,113,38,150,113,38,150,113,38,150,150,150,300,3
00,300,300,300,113,38,150,113,38,150,113,38,150,263,38,113,38,150,113,38,150,113,38,150,263,38,113,38,150,113,38,150,113,38,150,300,150
,300,300,300,300,300,113,38,150,113,38,150,113,38,150,263,38,113,38,150,113,38,150,113,38,150,263,38,113,38,150,113,38,150,113,38,150,1
50,150,300,300,300,375],Time ' LOOKUP takes a given segment from an array.
RETURN
END ' End of program, in case PIC gets "lost"

' ************************************************************* SONG 5 - SMALL WORLD


' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************

SONGLENGTH5:
CntTotal = 68
RETURN

NOTEB5:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000001,%00000000,%00000000,%00000000,%00000001,%00000000,%00000000,%00000000,%00000010,%00000000,%00000000,%00000000,%
00000000,%00000010,%00000000,%00000000,%00000000,%00000010,%00000000,%00000000,%00000000,%00000010,%00000000,%00000000,%00000000,%0000000
1,%00000000,%00000000,%00000000,%00000000,%00000001,%00000000,%00000000,%00000000,%00000001,%00000000,%00000000,%00000000,%00000001,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,
%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000000,%00000000,%00000000,%00000001],PatternB
RETURN
END ' End of program, in case PIC gets "lost"

NOTEC5:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000010,%00010000,%00000010,%00000000,%00000010,%00010000,%00000010,%00000000,%00000010,%00001000,%00000010,%
00000010,%00000000,%00000010,%00001000,%00000010,%00000000,%00000010,%00001000,%00000010,%00000000,%00000010,%00001000,%00000010,%0000000
0,%00000010,%00010000,%00000010,%00000010,%00000000,%00000010,%00010000,%00000010,%00000000,%00000010,%00010000,%00000010,%00000000,%000
00010,%00010000,%00000010,%01000000,%00000010,%00001000,%00000010,%00000010,%01000000,%00000010,%00000100,%00000010,%00000000,%00000000,
%00001000,%00000000,%01000000,%00001000,%00010000,%01000000,%00000000,%00000010,%00010000,%00000010,%00000000],PatternC
RETURN
END ' End of program, in case PIC gets "lost"

NOTED5:
' Find which note to play.
Lookup
Cnt,[%00000000,%00010000,%00010000,%00000000,%00010000,%00000001,%00000001,%00010000,%00010000,%00000100,%00000100,%00000000,%00000100,%
00000000,%00000100,%00000100,%00000100,%00000000,%00000100,%00000100,%00000000,%00000100,%00000000,%00000000,%00000100,%00000100,%0000000
1,%00000001,%00000000,%00000001,%00000000,%00000001,%00000001,%00000001,%00000000,%00000001,%00000001,%00000000,%00000001,%00000000,%000
00000,%00000001,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%10000000,%10000000,
%10000000,%10000000,%00100000,%00100000,%00100000,%00100000,%00010000,%00010000,%00010000,%00010000,%00000000],PatternD
RETURN
END ' End of program, in case PIC gets "lost"

NOTEA5:
' Find which note to play.
Lookup
Cnt,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0
,0],PatternA
RETURN
END ' End of program, in case PIC gets "lost"

DURATION5:
' Find out how long to play each note.
Lookup2
Cnt,[500,200,200,200,200,200,200,200,200,200,200,200,170,30,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,30,170,200,
200,200,200,200,200,200,200,200,200,200,200,200,200,170,30,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,500],Time
' LOOKUP takes a given segment from an array.
RETURN
END ' End of program, in case PIC gets "lost"

' ************************************************************* SONG 6 - TEQUILA


' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************

32
SONGLENGTH6:
CntTotal = 151
RETURN

NOTEB6:
' Find which note to play.
Lookup
Cnt,[%00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%00000010,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%00000000,%00000000,
%00000000,%00000000,%00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000
000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%00000000,%00000000,%00000000,%0
0000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
,%00000000,%00000000,%00000000,%00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000
0010,%00000000,%00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000],PatternB
RETURN
END ' End of program, in case PIC gets "lost"

NOTEC6:
' Find which note to play.
Lookup
Cnt,[%00000000,%00010000,%00000000,%00010000,%01000000,%00000100,%00000000,%01000000,%00010000,%00000000,%00000000,%00000000,%00000000,%
00010000,%00000000,%00010000,%01000000,%00000100,%00000000,%01000000,%00010000,%00000000,%00000000,%00010000,%00000000,%00010000,%0100000
0,%00000100,%00000000,%01000000,%00010000,%00000000,%00000000,%00000000,%00000000,%00010000,%00000000,%00010000,%01000000,%00000100,%000
00000,%01000000,%00010000,%00000000,%00000000,%01000000,%00010000,%00000010,%00010000,%00000000,%00000000,%01000000,%00010000,%00000010,
%00010000,%00000000,%00000000,%01000000,%00010000,%00000010,%00010000,%00000000,%00000100,%00000000,%00000100,%00000000,%00000100,%00000
000,%00000100,%00000000,%00000100,%00000000,%00000100,%00000000,%00000000,%00000000,%00000000,%00010000,%00000000,%00010000,%01000000,%0
0000100,%00000000,%01000000,%00010000,%00000000,%00000000,%00000000,%00000000,%00010000,%00000000,%00010000,%01000000,%00000100,%00000000
,%01000000,%00010000,%00000000,%00000000,%00010000,%00000000,%00010000,%01000000,%00000100,%00000000,%01000000,%00010000,%00000000,%0000
0000,%00000000,%00000000,%00010000,%00000000,%00010000,%01000000,%00000100,%00000000,%01000000,%00010000,%00000000,%00000000,%01000000,%
00010000,%00000010,%00010000,%00000000,%00000000,%01000000,%00010000,%00000010,%00010000,%00000000,%00000000,%01000000,%00010000,%0000001
0,%00010000,%00000000,%00000100,%00000000,%00000100,%00000000,%00000100,%00000000,%00000100,%00000000,%00000100,%00000000,%00000100,%000
00000,%00000000,%00000000],PatternC
RETURN
END ' End of program, in case PIC gets "lost"

NOTED6:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,
%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000
000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00100000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0
0000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000
0000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00100000,%00000000],PatternD
RETURN
END ' End of program, in case PIC gets "lost"

NOTEA6:
' Find which note to play.
Lookup
Cnt,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],PatternA
RETURN
END ' End of program, in case PIC gets "lost"

DURATION6:
' Find out how long to play each note.
Lookup2
Cnt,[167,167,167,167,167,167,167,167,167,167,167,750,167,167,167,167,167,167,167,167,167,1000,167,167,167,167,167,167,167,167,167,167,1
67,500,167,167,167,167,167,167,167,167,167,750,167,167,167,1000,167,1000,167,167,167,1000,167,1000,167,167,167,1000,167,1000,122,20,122,
20,122,20,122,20,122,20,122,20,122,334,167,167,167,167,167,167,167,167,167,167,167,750,167,167,167,167,167,167,167,167,167,1000,167,167,
167,167,167,167,167,167,167,167,167,500,167,167,167,167,167,167,167,167,167,750,167,167,167,1000,167,1000,167,167,167,1000,167,1000,167,
167,167,1000,167,1000,122,20,122,20,122,20,122,20,122,20,122,20,122,334],Time ' LOOKUP takes a given segment from an array.
RETURN
END ' End of program, in case PIC gets "lost"

' ************************************************************* SONG 7 - MNT KING


' *************************************************************
' *************************************************************
' *************************************************************

33
' *************************************************************
' *************************************************************

SONGLENGTH7:
CntTotal = 151
RETURN

NOTEB7:
' Find which note to play.
Lookup
Cnt,[%00001000,%00000010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000000,%00000001,%00000010,%00000001,%
00001000,%00000010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000000,%00000000,%0000100
0,%00000010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000000,%00000001,%00000010,%00000001,%00001000,%000
00010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000000,%00000000,%00000000,%00000000,
%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000
000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0
0000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
,%00000000,%00000000,%00000000,%00000000,%00000000,%00001000,%00000010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%0000
0001,%00000000,%00000001,%00000010,%00000001,%00001000,%00000010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000001,%00000000,%00000000,%00001000,%00000010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%0000000
0,%00000001,%00000010,%00000001,%00001000,%00000010,%00000001,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00001,%00000000,%00000000],PatternB
RETURN
END ' End of program, in case PIC gets "lost"

NOTEC7:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000000,%01000000,%00010000,%01000000,%00010000,%01000000,%00000000,%01000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%01000000,%00010000,%01000000,%00010000,%00000000,%00000010,%00010000,%00000000,%00010000,%00000010,%0000000
0,%00000000,%00000000,%01000000,%00010000,%01000000,%00010000,%01000000,%00000000,%01000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%01000000,%00010000,%01000000,%00010000,%00000000,%00000010,%00010000,%00000000,%00010000,%00000010,%01000000,%00010000,
%00001000,%00000010,%00000000,%00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%01000000,%00010000,%00001
000,%00000010,%00000000,%00000010,%00000000,%00000000,%00000000,%00000000,%00000000,%01000000,%00010000,%00001000,%00000010,%00000000,%0
0000010,%00000000,%00000000,%00000000,%00000000,%00000000,%00000010,%00000000,%01000000,%00010000,%00001000,%00000010,%00000000,%00000010
,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01000000,%00010000,%01000000,%00010000,%01000000,%0000
0000,%01000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01000000,%00010000,%01000000,%00010000,%00000000,%00000010,%
00010000,%00000000,%00010000,%00000010,%00000000,%00000000,%00000000,%01000000,%00010000,%01000000,%00010000,%01000000,%00000000,%0100000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%01000000,%00010000,%01000000,%00010000,%00000000,%00000010,%00010000,%000
00000,%00010000,%00000010],PatternC
RETURN
END ' End of program, in case PIC gets "lost"

NOTED7:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,
%00000000,%00000000,%10000000,%00000000,%10000000,%01000000,%10000000,%01000000,%10000000,%00000000,%10000000,%00000000,%00000000,%00000
000,%00000000,%10000000,%00000000,%10000000,%01000000,%10000000,%01000000,%10000000,%00000000,%00000000,%00000000,%00000000,%10000000,%0
0000000,%10000000,%01000000,%10000000,%01000000,%10000000,%00000000,%10000000,%00000000,%00000000,%00000000,%00000000,%10000000,%00000000
,%10000000,%01000000,%10000000,%01000000,%10000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000
0000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%10000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%10000000,%00000000,%00000000,%000
00000,%00000000,%00000000],PatternD
RETURN
END ' End of program, in case PIC gets "lost"

NOTEA7:
' Find which note to play.
Lookup
Cnt,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],PatternA
RETURN
END ' End of program, in case PIC gets "lost"

DURATION7:
' Find out how long to play each note.
Lookup2
Cnt,[199,199,199,199,199,199,398,199,199,398,199,199,398,199,199,199,199,199,199,199,199,199,199,199,199,796,199,199,199,199,199,199,39
8,199,199,398,199,199,398,199,199,199,199,199,199,199,199,199,199,199,199,796,199,199,199,199,199,199,398,199,199,398,199,199,398,199,19
9,199,199,199,199,398,199,199,398,796,199,199,199,199,199,199,398,199,199,398,199,199,398,199,199,199,199,199,199,398,199,199,398,796,19
9,199,199,199,199,199,398,199,199,398,199,199,398,199,199,199,199,199,199,199,199,199,199,199,199,796,199,199,199,199,199,199,398,199,19
9,398,199,199,398,199,199,199,199,199,199,199,199,199,199,199,199,796],Time ' LOOKUP takes a given segment from an array.
RETURN
END ' End of program, in case PIC gets "lost"

34
' ************************************************************* AUTO - LIGHT OFF - TAPS
' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************

SONGLENGTH8:
CntTotal = 27
RETURN

NOTEB8:
' Find which note to play.
Lookup
Cnt,[%00100000,%00000000,%00100000,%00000001,%00100000,%00000001,%00000000,%00100000,%00000001,%00000000,%00100000,%00000001,%00000000,%
00100000,%00000001,%00000000,%00000001,%00000000,%00000000,%00000000,%00000001,%00100000,%00000000,%00100000,%00000000,%00100000,%0000000
1],PatternB
RETURN
END ' End of program, in case PIC gets "lost"

NOTEC8:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00010000,%00000000,%00000000,%00010000,%00000000,%00000000,%00010000,%
00000000,%00000000,%00010000,%00000000,%00010000,%00000010,%00010000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0],PatternC
RETURN
END ' End of program, in case PIC gets "lost"

NOTED8:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0],PatternD
RETURN
END ' End of program, in case PIC gets "lost"

NOTEA8:
' Find which note to play.
Lookup Cnt,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],PatternA
RETURN
END ' End of program, in case PIC gets "lost"

DURATION8:
' Find out how long to play each note.
Lookup2
Cnt,[563,25,188,2250,563,188,2250,375,375,750,375,375,750,375,375,2250,563,1878,1500,750,750,2250,25,563,25,188,2250],Time ' LOOKUP
takes a given segment from an array.
RETURN
END ' End of program, in case PIC gets "lost"

' ************************************************************* AUTO - LIGHT ON - REV


' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************

SONGLENGTH9:
CntTotal = 107
RETURN

NOTEB9:
' Find which note to play.
Lookup
Cnt,[%00100000,%00000001,%00000000,%00000001,%00100000,%00000000,%00000001,%00000000,%00000001,%00100000,%00000000,%00000001,%00000000,%
00000001,%00100000,%00000001,%00000000,%00000001,%00100000,%00000001,%00000000,%00000001,%00100000,%00000000,%00000001,%00000000,%0000000
1,%00100000,%00000000,%00000001,%00000000,%00000001,%00100000,%00000000,%00100000,%00000001,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000000,%00000001,%00000000,%00000001,%00000000,%00000001,
%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000001,%00000000,%00000
001,%00100000,%00000000,%00100000,%00000001,%00100000,%00000001,%00000000,%00000001,%00100000,%00000000,%00000001,%00000000,%00000001,%0

35
0100000,%00000000,%00000001,%00000000,%00000001,%00100000,%00000001,%00000000,%00000001,%00100000,%00000001,%00000000,%00000001,%00100000
,%00000000,%00000001,%00000000,%00000001,%00100000,%00000000,%00000001,%00000000,%00000001,%00100000,%00000000,%00100000,%00000001],Patt
ernB
RETURN
END ' End of program, in case PIC gets "lost"

NOTEC9:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00010000,%00000000,%00000000,%00010000,%00000000,%00010000,%00000000,%00000000,%00010000,%00000000,%00010000,%
00000000,%00000000,%00000000,%00010000,%00000000,%00000000,%00000000,%00010000,%00000000,%00000000,%00010000,%00000000,%00010000,%0000000
0,%00000000,%00010000,%00000000,%00010000,%00000000,%00000000,%00000000,%00000000,%00000000,%00010000,%00000000,%00010000,%00000000,%000
10000,%00000000,%00010000,%00000000,%00010000,%00000010,%00010000,%00000000,%00010000,%00000000,%00010000,%00000000,%00010000,%00000000,
%00010000,%00000000,%00010000,%00000000,%00010000,%00000000,%00010000,%00000000,%00010000,%00000010,%00010000,%00000000,%00010000,%00000
000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00010000,%00000000,%00000000,%00010000,%00000000,%00010000,%00000000,%0
0000000,%00010000,%00000000,%00010000,%00000000,%00000000,%00000000,%00010000,%00000000,%00000000,%00000000,%00010000,%00000000,%00000000
,%00010000,%00000000,%00010000,%00000000,%00000000,%00010000,%00000000,%00010000,%00000000,%00000000,%00000000,%00000000,%00000000],Patt
ernC
RETURN
END ' End of program, in case PIC gets "lost"

NOTED9:
' Find which note to play.
Lookup
Cnt,[%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%
00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0000000
0,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%000
00000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,
%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000
000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%0
0000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000
,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000,%00000000],Patt
ernD
RETURN
END ' End of program, in case PIC gets "lost"

NOTEA9:
' Find which note to play.
Lookup
Cnt,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],PatternA
RETURN
END ' End of program, in case PIC gets "lost"

DURATION9:
' Find out how long to play each note.
Lookup2
Cnt,[199,199,99,99,199,199,199,99,99,199,199,199,99,99,199,199,398,199,199,199,99,99,199,199,199,99,99,199,199,199,99,99,199,50,199,597
,179,20,179,20,179,20,179,20,179,398,199,199,199,199,199,199,398,199,179,20,179,20,179,20,179,20,179,398,199,199,199,199,199,50,199,597
,199,199,99,99,199,199,199,99,99,199,199,199,99,99,199,199,398,199,199,199,99,99,199,199,199,99,99,199,199,199,99,99,199,50,199,597],Ti
me ' LOOKUP takes a given segment from an array.
RETURN
END ' End of program, in case PIC gets "lost"

' ************************************************************* END OF SONGS


' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************
' *************************************************************

BLINK:
TOGGLE PORTA.1 ' Toggle the note progression LED and return.
RETURN

ENDSONG:
PORTA = %00000000 ' Set all ports to NULL at the end of the song.
PORTB = %00000000
PORTC = %00000000
PORTD = %00000000
PAUSE 1500
PAUSE 500 ' Blink the LEDs to signal that the song has successfully completed.
HIGH PORTA.1
HIGH PORTA.2
PAUSE 250
LOW PORTA.1
LOW PORTA.2
PAUSE 250
HIGH PORTA.1
HIGH PORTA.2

36
PAUSE 250
LOW PORTA.1
LOW PORTA.2
PAUSE 250
HIGH PORTA.1
HIGH PORTA.2
GOTO SONGCHECK

37
'//////////////////////////////////////////////////////////////////////////////
'
' LCD PIC - DISPLAY MODULE FOR AUTICA
' ==============================================================
' Date: November 24, 2008
' Author: Ryan Sullenberger
' Group: 42 (R2D2)
' Colorado State University, Mechanical Engineering
'
' PIC16F88
'
'//////////////////////////////////////////////////////////////////////////////
' LCD should be connected as follows:
' LCD PIC
' DB4 PortA.0
' DB5 PortA.1
' DB6 PortA.2
' DB7 PortA.3
' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.3
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)
' DB0-3 No connect
DEFINE OSC 8 ' Tells PIC which clock we are using
OSCCON.4 = 1 ' Sets the internal oscillator frequency to 8 MHz
OSCCON.5 = 1
OSCCON.6 = 1

ansel = 0 ' Turns off analog to digital conversion. Refer to


' Threaded Design Example A.4 p.296-299 of the textbook
' for an example of how to configure and use A/D conversion

'VARIABLES
Cnt VAR Byte

'INITIAL VALUES
Cnt = 1

Pause 500 ' Wait for LCD to startup


LCDOUT $fe, 1 ' Initially clear LCD

'MAIN LOOP
LCDFUN:
' If Cnt = 1 then we have returned to the main menu. Display the main menu message.
IF Cnt = 1 THEN
Lcdout $FE, 1, "WELCOME TO AUTICA WHERE", $FE, $C0, "MAGIC HAPPENS" ' Clear LCD screen
ENDIF

' Await instruction from the main master PIC. Once instruction is known, execute the instructions.
IF PORTB.1 = 1 THEN
PAUSE 50
IF PORTB.4 = 1 && PORTB.5 = 0 && PORTB.6 = 0 && PORTB.7 = 0 THEN
GOTO NUMBERONE
ENDIF
IF PORTB.4 = 0 && PORTB.5 = 1 && PORTB.6 = 0 && PORTB.7 = 0 THEN
GOTO NUMBERTWO
ENDIF
IF PORTB.4 = 1 && PORTB.5 = 1 && PORTB.6 = 0 && PORTB.7 = 0 THEN
GOTO NUMBERTHREE
ENDIF
IF PORTB.4 = 0 && PORTB.5 = 0 && PORTB.6 = 1 && PORTB.7 = 0 THEN
GOTO NUMBERFOUR
ENDIF
IF PORTB.4 = 1 && PORTB.5 = 0 && PORTB.6 = 1 && PORTB.7 = 0 THEN
GOTO NUMBERFIVE
ENDIF
IF PORTB.4 = 0 && PORTB.5 = 1 && PORTB.6 = 1 && PORTB.7 = 0 THEN
GOTO NUMBERSIX
ENDIF
IF PORTB.4 = 1 && PORTB.5 = 1 && PORTB.6 = 1 && PORTB.7 = 0 THEN
GOTO NUMBERSEVEN
ENDIF
IF PORTB.4 = 0 && PORTB.5 = 0 && PORTB.6 = 0 && PORTB.7 = 1 THEN
GOTO NUMBEREIGHT
ENDIF
IF PORTB.4 = 1 && PORTB.5 = 0 && PORTB.6 = 0 && PORTB.7 = 1 THEN
GOTO NUMBERNINE
ENDIF
IF PORTB.4 = 0 && PORTB.5 = 1 && PORTB.6 = 0 && PORTB.7 = 1 THEN
GOTO NUMBERSTAR
ENDIF
IF PORTB.4 = 1 && PORTB.5 = 1 && PORTB.6 = 0 && PORTB.7 = 1 THEN
GOTO NUMBERZERO
ENDIF
IF PORTB.4 = 0 && PORTB.5 = 0 && PORTB.6 = 1 && PORTB.7 = 1 THEN
GOTO NUMBERPOUND
ENDIF
ENDIF
Cnt = Cnt + 1
IF Cnt > 254 THEN Cnt = 2 ' Set Cnt = 2 to avoid re-writing the same menu message to the LCD more than once

38
GOTO LCDFUN

NUMBERONE:
Lcdout $FE, 1, "#1: TEST PATTERN"
PAUSE 2000
Lcdout $FE, 1, "#1: TEST PATTERN", $FE, $C0, "DURATION: 1:00 - ENJOY"
PAUSE 2000
Lcdout $FE, 1
Cnt = 1
PAUSE 10
GOTO LCDFUN

NUMBERTWO:
Lcdout $FE, 1, "#2: LEGEND OF ZELDA"
PAUSE 2000
Lcdout $FE, 1, "#2: LEGEND OF ZELDA", $FE, $C0, "DURATION: 1:04 - ENJOY"
PAUSE 2000
Lcdout $FE, 1
Cnt = 1
PAUSE 10
GOTO LCDFUN

NUMBERTHREE:
Lcdout $FE, 1, "#3: GREENSLEEVES"
PAUSE 2000
Lcdout $FE, 1, "#3: GREENSLEEVES", $FE, $C0, "DURATION: 0:25 - ENJOY"
PAUSE 2000
Lcdout $FE, 1
Cnt = 1
PAUSE 10
GOTO LCDFUN

NUMBERFOUR:
Lcdout $FE, 1, "#4: CHICKEN DANCE"
PAUSE 2000
Lcdout $FE, 1, "#4: CHICKEN DANCE", $FE, $C0, "DURATION: 0:16 - ENJOY"
PAUSE 2000
Lcdout $FE, 1
Cnt = 1
PAUSE 10
GOTO LCDFUN

NUMBERFIVE:
Lcdout $FE, 1, "#5: SMALL WORLD"
PAUSE 2000
Lcdout $FE, 1, "#5: SMALL WORLD", $FE, $C0, "DURATION: 0:13 - ENJOY"
PAUSE 2000
Lcdout $FE, 1
Cnt = 1
PAUSE 10
GOTO LCDFUN

NUMBERSIX:
Lcdout $FE, 1, "#6: TEQUILA"
PAUSE 2000
Lcdout $FE, 1, "#6: TEQUILA", $FE, $C0, "DURATION: 0:18 - ENJOY"
PAUSE 2000
Lcdout $FE, 1
Cnt = 1
PAUSE 10
GOTO LCDFUN

NUMBERSEVEN:
Lcdout $FE, 1, "#7: HALL OF MNT KING"
PAUSE 2000
Lcdout $FE, 1, "#7: HALL OF MNT KING", $FE, $C0, "DURATION: 0:37 - ENJOY"
PAUSE 2000
Lcdout $FE, 1
Cnt = 1
PAUSE 10
GOTO LCDFUN

NUMBEREIGHT:
Lcdout $FE, 1, "#8: TAPS"
PAUSE 2000
Lcdout $FE, 1, "#8: TAPS", $FE, $C0, "DURATION: 0:15 - ENJOY"
PAUSE 2000
Lcdout $FE, 1
Cnt = 1
PAUSE 10
GOTO LCDFUN

NUMBERNINE:
Lcdout $FE, 1, "#9: REVEILLE"
PAUSE 2000
Lcdout $FE, 1, "#9: REVEILLE", $FE, $C0, "DURATION: 0:18 - ENJOY"
PAUSE 2000
Lcdout $FE, 1
Cnt = 1
PAUSE 10
GOTO LCDFUN

39
'AUTOMATIC MODE
NUMBERSTAR:
Lcdout $FE, 1, "YOU HAVE SELECTED AUTO"
PAUSE 2000
Lcdout $FE, 1, "ENTERING AUTOMATIC MODE"
PAUSE 2000
Lcdout $FE, 1, "TAKING IN READING FROM", $FE, $C0, "LIGHT SENSOR"
Cnt = 1
GOTO AUTOMATIC

NUMBERZERO:
Lcdout $FE, 1, "YOU HAVE SELECTED 0"
PAUSE 2000
Lcdout $FE, 1, "HAVE A NICE DAY,", $FE, $C0, "MECHATRONICS WARRIOR"
PAUSE 2000
Cnt = 1
PAUSE 10
GOTO LCDFUN

NUMBERPOUND:
Lcdout $FE, 1, "YOU HAVE SELECTED #"
PAUSE 2000
Cnt = 1
PAUSE 10
GOTO LCDFUN

AUTOMATIC:
' WAIT UNTIL THE LIGHT READING HAS BEEN MEASURED AND THEN EXIT AUTOMATIC MODE
IF PORTB.4 = 0 && PORTB.5 = 1 && PORTB.6 = 0 && PORTB.7 = 1 THEN
Lcdout $FE, 1, "EXITING AUTOMATIC MODE"
PAUSE 2000
Cnt = 1
GOTO LCDFUN
ENDIF
GOTO AUTOMATIC

40
'//////////////////////////////////////////////////////////////////////////////
'
' LIGHT SENSOR A/D CONVERSION - A/D MODULE FOR AUTICA
' ==============================================================
' Date: November 27, 2008
' Author: Ryan Sullenberger
' Group: 42 (R2D2)
' Colorado State University, Mechanical Engineering
'
' PIC16F88
'
'//////////////////////////////////////////////////////////////////////////////
' PicBasic Pro program to display result of
' 8-bit A/D conversion on LCD
'
' Connect analog input to channel-0 (RA0)

DEFINE OSC 8
OSCCON.4 = 1 'Sets the internal oscillator frequency to 8 MHz
OSCCON.5 = 1
OSCCON.6 = 1

adval var byte ' Create adval to store result

ADCON1 = %00000010 ' Set PORTA analog and LEFT justify result
ADCON0 = %11000001 ' Configure and turn on A/D Module
Pause 50 ' Wait .05 second

adconvert: ADCON0.2 = 1 ' Start Conversion

notdone: Pause 5
If ADCON0.2 = 1 Then GOTO notdone ' Wait for low on bit-2 of ADCON0, conversion finished

adval = ADRESH ' Move high byte of result to adval

IF adval < 15 THEN HIGH PORTB.4 ' If light sensor gives a reading of below 300 mV, turn PORTB.4 HIGH

IF adval > 16 THEN HIGH PORTB.7 ' If light sensor gives a reading of above 301 mV, turn PORTB.7 HIGH

PAUSE 4000 ' Wait 4 seconds to avoid too many flucuations


PORTB = %00000000 ' Return PORTB to 0

GOTO adconvert ' Do it forever


End

41
Excel Music Spreadsheet

42
43
44
45
46
47
48
49
50
51
52
53

Anda mungkin juga menyukai