Created
September 5, 2018 02:39
-
-
Save alg0trader/a9256a29ffb24cff591be3daa0d8594b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CreatingSound1.C - "God Save The Queen" song. | |
// | |
#include <p18f1320.h> | |
#include <delays.h> | |
#include <stdlib.h> | |
#pragma config OSC=INTIO2, WDT=OFF, LVP=OFF, DEBUG=ON | |
#define PAUSE Delay1KTCYx(50); | |
#define WHOLE 300 | |
#define HALF 150 | |
#define LONG 600 | |
unsigned char hundnotes[] = {30, 28, 27, 25, 25, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12}; | |
unsigned char tensnotes[] = {3, 6, 0, 5, 1, 7, 5, 3, 1, 1, 1, 1, 2, 4, 6, 8}; | |
void playNote(unsigned int note, unsigned int timer) // Sound Driver (Enter the note you would like to play and for how long you wish it to play). | |
{ | |
int times, hdelay, tdelay; | |
hdelay = hundnotes[note]; | |
tdelay = tensnotes[note]; | |
for(times=timer;times>0;times--) // Duration of playing. | |
{ | |
LATA = 0x01; | |
Delay10TCYx(tdelay); | |
Delay100TCYx(hdelay); | |
LATA = 0x00; | |
Delay10TCYx(tdelay); | |
Delay100TCYx(hdelay); | |
} | |
} | |
void main() | |
{ | |
OSCCONbits.IRCF0=1; | |
OSCCONbits.IRCF1=1; | |
OSCCONbits.IRCF2=1; | |
while(!OSCCONbits.IOFS); | |
TRISA = 0xFE; | |
while(1) | |
{ | |
playNote(3, WHOLE); // Section 1 | |
PAUSE; | |
playNote(3, WHOLE); | |
PAUSE; | |
playNote(3, WHOLE); | |
PAUSE; | |
playNote(1, WHOLE); // Section 2 | |
PAUSE; | |
playNote(3, HALF); | |
PAUSE; | |
playNote(5, WHOLE); | |
PAUSE; | |
playNote(7, WHOLE); // Section 3 | |
PAUSE; | |
playNote(7, WHOLE); | |
PAUSE; | |
playNote(8, WHOLE); | |
PAUSE; | |
playNote(5, WHOLE); // Section 4 | |
PAUSE; | |
playNote(7, HALF); | |
PAUSE; | |
playNote(8, WHOLE); | |
PAUSE; | |
playNote(12, WHOLE); // Section 5 | |
PAUSE; | |
playNote(0, WHOLE); | |
PAUSE; | |
playNote(12, WHOLE); | |
PAUSE; | |
playNote(7, WHOLE); // Section 6 | |
PAUSE; | |
playNote(8, HALF); | |
PAUSE; | |
playNote(10, WHOLE); | |
PAUSE; | |
playNote(12, WHOLE); // Section 7 | |
PAUSE; | |
playNote(12, WHOLE); | |
PAUSE; | |
playNote(13, WHOLE); | |
PAUSE; | |
playNote(10, WHOLE); // Section 8 | |
PAUSE; | |
playNote(10, HALF); | |
PAUSE; | |
playNote(12, WHOLE); | |
PAUSE; | |
playNote(5, WHOLE); // Section 9 | |
PAUSE; | |
playNote(1, WHOLE); | |
PAUSE; | |
playNote(3, HALF); | |
PAUSE; | |
playNote(3, LONG); // Section 10 | |
PAUSE; | |
playNote(10, WHOLE); // Section 11 | |
PAUSE; | |
playNote(10, WHOLE); | |
PAUSE; | |
playNote(10, WHOLE); | |
PAUSE; | |
playNote(10, WHOLE); // Section 12 | |
PAUSE; | |
playNote(8, HALF); | |
PAUSE; | |
playNote(7, WHOLE); | |
PAUSE; | |
playNote(8, WHOLE); // Section 13 | |
PAUSE; | |
playNote(8, WHOLE); | |
PAUSE; | |
playNote(8, WHOLE); | |
PAUSE; | |
playNote(8, WHOLE); // Section 14 | |
PAUSE; | |
playNote(7, HALF); | |
PAUSE; | |
playNote(5, WHOLE); | |
PAUSE; | |
playNote(5, WHOLE); // Section 15 | |
PAUSE; | |
playNote(7, WHOLE); | |
PAUSE; | |
playNote(7, HALF); | |
PAUSE; | |
playNote(0, LONG); // Section 16 | |
PAUSE; | |
playNote(15, WHOLE); // Section 17 | |
PAUSE; | |
playNote(15, WHOLE); | |
PAUSE; | |
playNote(15, WHOLE); | |
PAUSE; | |
playNote(15, WHOLE); // Section 18 | |
PAUSE; | |
playNote(13, HALF); | |
PAUSE; | |
playNote(12, WHOLE); | |
PAUSE; | |
playNote(13, WHOLE); // Section 19 | |
PAUSE; | |
playNote(13, WHOLE); | |
PAUSE; | |
playNote(13, WHOLE); | |
PAUSE; | |
playNote(13, WHOLE); // Section 20 | |
PAUSE; | |
playNote(12, HALF); | |
PAUSE; | |
playNote(10, WHOLE); | |
PAUSE; | |
playNote(7, WHOLE); // Section 21 | |
PAUSE; | |
playNote(8, HALF); | |
PAUSE; | |
playNote(7, HALF); | |
PAUSE; | |
playNote(5, HALF); | |
PAUSE; | |
playNote(3, HALF); | |
PAUSE; | |
playNote(7, WHOLE); // Section 22 | |
PAUSE; | |
playNote(8, HALF); | |
PAUSE; | |
playNote(10, WHOLE); | |
PAUSE; | |
playNote(12, WHOLE); // Section 23 | |
PAUSE; | |
playNote(5, WHOLE); | |
PAUSE; | |
playNote(3, HALF); | |
PAUSE; | |
playNote(3, LONG); // Section 24 | |
PAUSE; | |
playNote(12, WHOLE); // Section 25 | |
PAUSE; | |
playNote(13, HALF); | |
PAUSE; | |
playNote(12, HALF); | |
PAUSE; | |
playNote(10, HALF); | |
PAUSE; | |
playNote(8, HALF); | |
PAUSE; | |
playNote(7, WHOLE); // Section 26 | |
PAUSE; | |
playNote(5, HALF); | |
PAUSE; | |
playNote(3, WHOLE); | |
PAUSE; | |
playNote(5, WHOLE); // Section 27 | |
PAUSE; | |
playNote(7, WHOLE); | |
PAUSE; | |
playNote(7, HALF); | |
PAUSE; | |
playNote(0, LONG); // Section 28 | |
PAUSE; | |
Delay100TCYx(255); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment