Maria Loida Canada
Published © GPL3+

Stepper Motor Music

A novel use of a stepper motors in creating music.

IntermediateProtipOver 1 day748
Stepper Motor Music

Things used in this project

Hardware components

Microchip dsPICDEM MCSM
×1
Microchip MCSM Plug-In Module
×1
Microchip PIC18FxxK42
×1

Software apps and online services

MPLAB Code Configurator
Microchip MPLAB Code Configurator
Microchip MPLABX IDE
Microchip XC8 Compiler

Story

Read more

Custom parts and enclosures

PIC16F177x PIM Reference

BOM

MCSM PIM PCB

3D PCB File

Schematics

Schematic Diagram

Code

twinkle.c

C/C++
/**
  Company:
    Microchip Technology Inc.

  File Name:
    twinkle.c

  Summary:
    It contains the code for playing Twinkle Twinkle Little Star.
  
  Author: A20692
  Last Modified Date: 10/19/2018
  
*/

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
*/

#include "../mcc_generated_files/tmr1.h"
#include "../Control/control.h"
#include "notes_duration.h"
#include "stepperMusic.h"

const uint16_t twinkle_music_Sheet [85] = {
    null, C5, null, C5, null, G5, null, G5, null, A5, null, A5, null, G5,
    null, F5, null, F5, null, E5, null, E5, null, D5, null, D5, null, C5,
    null, G5, null, G5, null, F5, null, F5, null, E5, null, E5, null, D5,
    null, G5, null, G5, null, F5, null, F5, null, E5, null, E5, null, D5,
    null, C5, null, C5, null, G5, null, G5, null, A5, null, A5, null, G5,
    null, F5, null, F5, null, E5, null, E5, null, D5, null, D5, null, C5,
    null
};
const uint16_t twinkle_pause_Sheet [85] = {
    ms_100, ms_400, ms_100, ms_400, ms_200, ms_400, ms_100, ms_400, ms_50, ms_500, ms_100, ms_500, ms_50, ms_400,
    ms_500, ms_400, ms_100, ms_400, ms_100, ms_400, ms_100, ms_400, ms_100, ms_400, ms_100, ms_400, ms_100, ms_300,
    ms_500, ms_600, ms_100, ms_400, ms_50, ms_400, ms_200, ms_400, ms_100, ms_400, ms_100, ms_400, ms_50, ms_500,
    ms_500, ms_500, ms_50, ms_200, ms_100, ms_400, ms_50, ms_300, ms_100, ms_400, ms_100, ms_400, ms_100, ms_400,
    ms_500, ms_400, ms_100, ms_400, ms_200, ms_400, ms_100, ms_400, ms_100, ms_500, ms_100, ms_500, ms_50, ms_400,
    ms_500, ms_400, ms_100, ms_400, ms_100, ms_400, ms_100, ms_400, ms_100, ms_400, ms_100, ms_400, ms_100, ms_400,
    ms_500
};

const uint16_t *twinkle_noteCounter = twinkle_music_Sheet;
const uint16_t *twinkle_durationCounter = twinkle_pause_Sheet;
uint8_t twinkle_checkLastElement = 0; 


void twinkle() {
    speed_control(*++twinkle_noteCounter);
    duration_control(*++twinkle_durationCounter);
    twinkle_checkLastElement++;
    
    if (twinkle_checkLastElement > (sizeof (twinkle_music_Sheet)/sizeof(twinkle_music_Sheet[0]))) {
        twinkle_checkLastElement = 0; 
        twinkle_noteCounter = twinkle_music_Sheet;
        twinkle_durationCounter = twinkle_pause_Sheet;
    }
}

void play_twinkle(){
    TMR1_SetInterruptHandler(twinkle);
}

stepperMusic.h

C Header File
/* Microchip Technology Inc. and its subsidiaries.  You may use this software 
 * and any derivatives exclusively with Microchip products. 
 * 
 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".  NO WARRANTIES, WHETHER 
 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED 
 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A 
 * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION 
 * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. 
 *
 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS 
 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE 
 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS 
 * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF 
 * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
 *
 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE 
 * TERMS. 
 */

/* 
 * File:   
 * Author: A20687
 * Comments:
 * Revision history:
 */

// This is a guard condition so that contents of this file are not included
// more than once.  
#ifndef  STEPPER_MUSIC_H
#define	 STEPPER_MUSIC_H

#include <xc.h> // include processor files - each processor file is guarded.  

//Function prototypes
void play_canonRockIntro();
void play_happyBday();
void play_joyToTheWorld();
void play_superMario();
void play_twinkle();

#endif	/* STEPPER_MUSIC_H */

wavestep.c

C/C++
/*
 * File:   wavestep.c
 * Author: A15693
 *
 * Created on May 20, 2018, 6:51 PM
 */

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
*/

#include <xc.h>
#include "../mcc_generated_files/cwg1.h"
#include "../mcc_generated_files/cwg2.h"
#include "../mcc_generated_files/tmr0.h"
#include "control.h"
 
uint8_t waveStep_DriveTableCWG1 [4] = {0, 0, 1, 0};
uint8_t waveStep_DriveTableCWG2 [4] = {0, 0, 0, 1};
uint8_t waveStepCWG1_EnDriveTable [4] = {1, 0, 1, 0};
uint8_t waveStepCWG2_EnDriveTable [4] = {0, 1, 0, 1};

uint8_t stepCounter;

void motor_wavedrive (void);

void wavestep_drive () 
{
    TMR0_SetInterruptHandler(motor_wavedrive);
    stepCounter = 0;

}

void motor_wavedrive()
{        
    stepCounter++;
    if (stepCounter == 4)
    {
        stepCounter = 0;
    }

    CWG1CON0bits.EN = waveStepCWG1_EnDriveTable[stepCounter];
    CWG2CON0bits.EN = waveStepCWG2_EnDriveTable[stepCounter];
    CWG1CON0bits.MODE0 = waveStep_DriveTableCWG1[stepCounter];
    CWG2CON0bits.MODE0 = waveStep_DriveTableCWG2[stepCounter];

    TMR0_WriteTimer(changeSpeed);
}

speedcontrol.c

C/C++
/*
 * File:   speedcontrol.c
 * Author: A15693
 *
 * Created on May 20, 2018, 7:25 PM
 */

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
*/

#include <xc.h>
#include "../mcc_generated_files/tmr0.h"
#include "control.h"

void speed_control(uint16_t speedValue) 
{
    TMR0_WriteTimer(speedValue);
    
    changeSpeed = speedValue;
}

microstep.c

C/C++
/*
 * File:   microstep.c
 * Author: A15693
 *
 * Created on May 20, 2018, 6:51 PM
 */

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
 */

#include <xc.h>
#include "../mcc_generated_files/cwg1.h"
#include "../mcc_generated_files/cwg2.h"
#include "../mcc_generated_files/pwm1.h"
#include"../mcc_generated_files/pwm2.h"
#include "../mcc_generated_files/tmr0.h"
#include "control.h"

uint8_t microCT_DriveTableCOG1 [16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1};
uint8_t microCT_DriveTableCOG2 [16] = {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0};
uint8_t microCTCOG1_EnDriveTable [16] = {1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0};
uint8_t microCTCOG2_EnDriveTable [16] = {1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1};
uint8_t microCT_PWM3DC [16] = {389, 726, 941, 1023, 941, 726, 389, 1023, 389, 726, 941, 1023, 941, 726, 389, 1023};
uint8_t microCT_PWM4DC [16] = {941, 726, 389, 1023, 389, 726, 941, 1023, 941, 726, 389, 1023, 389, 726, 941, 1023};


uint8_t stepCounter;

void constorq_drive(void);

void microstepconstorq_drive() {

    TMR0_SetInterruptHandler(constorq_drive);
    stepCounter = 0;
}

void constorq_drive() {
    stepCounter++;

    if (stepCounter == 16) {
        stepCounter = 0;
    }

    PWM1_LoadDutyValue(microCT_PWM3DC[stepCounter]);
    PWM2_LoadDutyValue(microCT_PWM4DC[stepCounter]);

    CWG1CON0bits.EN = microCTCOG1_EnDriveTable[stepCounter];
    CWG2CON0bits.EN = microCTCOG2_EnDriveTable[stepCounter];
    CWG1CON0bits.MODE0 = microCT_DriveTableCOG1[stepCounter];
    CWG2CON0bits.MODE0 = microCT_DriveTableCOG2[stepCounter];

    TMR0_WriteTimer(changeSpeed);
}

halfstep.c

C/C++
/*
 * File:   halfstep.c
 * Author: A15693
 *
 * Created on May 20, 2018, 6:51 PM
 */

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
*/

#include <xc.h>
#include "../mcc_generated_files/cwg1.h"
#include "../mcc_generated_files/cwg2.h"
#include "../mcc_generated_files/tmr0.h"
#include "control.h"

uint8_t halfStep_DriveTableCWG1 [8] = {0, 0, 0, 1, 1, 1, 0, 0};
uint8_t halfStep_DriveTableCWG2 [8] = {0, 0, 0, 0, 0, 1, 1, 1};
uint8_t halfStepCWG1_EnDriveTable [8] = {1, 1, 0, 1, 1, 1, 0, 1};
uint8_t halfStepCWG2_EnDriveTable [8] = {0, 1, 1, 1, 0, 1, 1, 1};

uint8_t stepCounter;

void motor_drive(void);

void halfstep_drive ()
{
    TMR0_SetInterruptHandler(motor_drive);
    stepCounter = 0;
}

void motor_drive()
{ 
    stepCounter++;
    
    if (stepCounter == 8)
    {
        stepCounter = 0;
    }

    CWG1CON0bits.EN = halfStepCWG1_EnDriveTable[stepCounter];
    CWG2CON0bits.EN = halfStepCWG2_EnDriveTable[stepCounter];
    CWG1CON0bits.MODE0 = halfStep_DriveTableCWG1[stepCounter];
    CWG2CON0bits.MODE0 = halfStep_DriveTableCWG2[stepCounter]; 
    
    TMR0_WriteTimer(changeSpeed);   
}

fullstep.c

C/C++
/*
 * File:   fullstep.c
 * Author: A15693
 *
 * Created on May 20, 2018, 6:51 PM
 */

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
*/

#include <xc.h>
#include "../mcc_generated_files/cwg1.h"
#include "../mcc_generated_files/cwg2.h"
#include "../mcc_generated_files/tmr0.h"
#include "control.h"

uint16_t fullStep_DriveTableCWG1 [4] = {1, 0, 0, 1};
uint16_t fullStep_DriveTableCWG2 [4] = {1, 1, 0, 0};

uint8_t stepCounter;

void motor_fulldrive (void);

void fullstep_drive () 
{
    TMR0_SetInterruptHandler(motor_fulldrive);
    stepCounter = 0;
}


void motor_fulldrive()
{
    stepCounter++;
    if (stepCounter == 4)
    {
        stepCounter = 0;
    }

    CWG1CON0bits.MODE0 = fullStep_DriveTableCWG1[stepCounter];
    CWG2CON0bits.MODE0 = fullStep_DriveTableCWG2[stepCounter]; 

    TMR0_WriteTimer(changeSpeed);
}

durationcontrol.c

C/C++
/*
 * File:   durationcontrol.c
 * Author: A20687
 *
 * Created October 19, 2018, 2:04 PM
 */

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
*/

#include <xc.h>
#include "../mcc_generated_files/tmr1.h"
#include "control.h"



void duration_control(uint16_t durationValue) 
{
    TMR1_WriteTimer(durationValue);
}

control.h

C Header File
/* Microchip Technology Inc. and its subsidiaries.  You may use this software 
 * and any derivatives exclusively with Microchip products. 
 * 
 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".  NO WARRANTIES, WHETHER 
 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED 
 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A 
 * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION 
 * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. 
 *
 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS 
 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE 
 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS 
 * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF 
 * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
 *
 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE 
 * TERMS. 
 */

/* 
 * File:   
 * Author: A15693
 * Comments:
 * Revision history: 
 */

// This is a guard condition so that contents of this file are not included
// more than once.  
#ifndef CONTROL_H
#define	CONTROL_H

#include <xc.h> 
#include <stdint.h>

#define CCW  1
#define CW 0



void fullstep_drive (void);
void wavestep_drive (void);
void halfstep_drive (void);
void microstepconstorq_drive (void);
void microstephightorq_drive (void);
void duration_control(uint16_t durationValue);
void speed_control (uint16_t speedValue);


// Stepper Commutation Related Register
uint16_t StepCounter;
uint16_t changeSpeed;
uint16_t DesiredStep = 0;

bit direction;
#endif	/* CONTROL_H */

main.c

C/C++
/**
  Generated Main Source File

  Company:
    Microchip Technology Inc.

  File Name:
    main.c

  Summary:
    This is the main file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs

  Description:
    This header file provides implementations for driver APIs for all modules selected in the GUI.
    Generation Information :
        Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.65.2
        Device            :  PIC18LF24K42
        Driver Version    :  2.00
*/

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
*/

#include "mcc_generated_files/mcc.h"
#include "Control/control.h"
#include "Music/notes_duration.h"
#include "Music/stepperMusic.h"

/*
                         Main application
 */

void main(void) {
    SYSTEM_Initialize();
    
    INTERRUPT_GlobalInterruptEnable();

//Select your desired Music by Commenting Out each choice below, comment out one at a time
    
    play_canonRockIntro();
//    play_happyBday();
//    play_joyToTheWorld();
//    play_superMario();
//    play_twinkle();
        
/*
  Before selecting the type of drive you want to use, follow the instruction below.
  This stepper music is originally created using microstepping and tested using a 24V supply.
  If you want to try other drive modes, for safety and to avoid overheating set the PWM to:
   - 20% modulation when using wavestep drive or full-step drive
   - 30% modulation when using half-step drive
   - 100% modulation for microstepping
*/
//       microstepconstorq_drive(); 
//     wavestep_drive();  
//     fullstep_drive();   
     halfstep_drive();     
     
    while (1) {
        // Add your application code
    }
}
/**
 End of File
*/

canonRockIntro.c

C/C++
/**
  Company:
    Microchip Technology Inc.

  File Name:
    canonRockIntro.c

  Summary:
    It contains the code for playing canon intro.
  
  Author: A20692
  Last Modified Date: 10/19/2018
  
*/

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
*/

#include "../mcc_generated_files/tmr1.h"
#include "../Control/control.h"
#include "notes_duration.h"
#include "stepperMusic.h"

void canonRockIntro();

const uint16_t canon_music_Sheet [1409] = {
    null, D5, null, A4, null, B4, null, Gb4, null, G4, null, D4, null, G4, null, A4, null, Gb5, null, E5, null, D5, null, Db5, null, B4, null, A4, null, B4, null,
    Db5, null, D5, null, E5, null, Gb5, null, Gb5, null, E5, null, Gb5, null, G5, null, Gb5, null, E5, null, D5, null, E5, null, D5, null, Db5, null, Gb5, null,
    A5, null, B5, null, B5, null, A5, null, B5, null, Db6, null, Gb5, null, B4, null, Db5, null, D5, null, E5, null, A5, null, D5, null, E5, null, Gb5, null,
    G5, null, D5, null, D4, null, D4, null, G5, null, Gb5, null, D4, null, D4, null, A4, null, A3, null, A3, null, E5, null, Gb5, null, A3, null, A3, null,
    B4, null, B3, null, B3, null, E5, null, B3, null, Gb5, null, B3, null, Gb4, null, A3, null, A3, null, E4, null, A3, null, Gb4, null, A3, null, G4, null,
    G3, null, G3, null, G3, null, B4, null, Db5, null, D5, null, D4, null, D4, null, B5, null, A5, null, G5, null, Gb5, null, G4, null, G3, null, G3, null,
    B4, null, Db5, null, D5, null, Db5, null, A4, null, A3, null, A3, null, E5, null, Gb5, null, G5, null, Gb5, null, D5, null, D4, null, D4, null, G5, null,
    Gb5, null, D4, null, D4, null, A4, null, A3, null, A3, null, E5, null, Gb5, null, A3, null, A3, null, B4, null, B3, null, B3, null, E5, null, B3, null,
    Gb5, null, B3, null, Gb4, null, A3, null, A3, null, E4, null, A3, null, Gb4, null, A3, null, G4, null, G3, null, G3, null, G3, null, B4, null, Db5, null,
    D5, null, D4, null, D4, null, B5, null, A5, null, G5, null, Gb5, null, G4, null, G3, null, G3, null, B4, null, Db5, null, D5, null, Db5, null, A4, null,
    E5, null, Gb5, null, E5, null, Gb5, null, Gb5, null, E5, null, A4, null, D5, null, D5, null, E5, null, D5, null, Db5, null, A4, null, D4, null, B4, null,
    B4, null, A4, null, G4, null, A4, null, D5, null, Gb4, null, B4, null, B4, null, A4, null, G4, null, Db5, null, D5, null, E5, null, Gb5, null, Gb5, null,
    G5, null, Gb5, null, E5, null, A4, null, D5, null, D5, null, E5, null, D5, null, Db5, null, Gb5, null, A5, null, B5, null, A5, null, G5, null, B5, null,
    A5, null, G5, null, Gb5, null, A5, null, B5, null, A5, null, G5, null, B5, null, Db6, null, D5, null, Db5, null, D5, null, Gb4, null, A4, null, B4, null,
    Db5, null, D5, null, Db5, null, D5, null, Gb5, null, A5, null, G5, null, Gb5, null, E5, null, G5, null, Gb5, null, E5, null, D5, null, B4, null, A4, null,
    B4, null, A4, null, G4, null, D5, null, Db5, null, A4, null, E4, null, D4, null, Db4, null, A3, null, D5, null, Db5, null, D5, null, Gb4, null, A4, null,
    B4, null, Db5, null, D5, null, Gb5, null, B5, null, Gb5, null, B5, A5, null, B5, null, null, A5, null, G5, null, Gb5, null, G5, null, Gb5, null, E5, null,
    G5, null, Gb5, null, E5, null, D5, null, Db5, null, G5, null, Gb5, null, E5, null, D5, null, Db5, null, B4, null, A4, null, G4, null, Db5, null, B4, null,
    A4, null, G4, null, Gb4, null, E4, null, A3, null, A3, null, A3, null, E4, null, E4, null, A3, null, A3, null, E4, null, E4, null, A4, null, A4, null,
    Db5, null, Db5, null, A4, null, A4, null, E4, null, E4, null, A5, null, Gb5, null, G5, null, A5, null, Gb5, null, G5, null, A5, null, A4, null, B4, null,
    Db5, null, D5, null, E5, null, Gb5, null, G5, null, Gb5, null, D5, null, E5, null, Gb5, null, Gb4, null, G4, null, A4, null, B4, null, A4, null, G4, null,
    A4, null, D5, null, Db5, null, D5, null, G4, null, B4, null, A4, null, G4, null, Gb4, null, E4, null, Gb4, null, E4, null, D4, null, E4, null, Gb4, null,
    G4, null, A4, null, B4, null, G4, null, B4, null, A4, null, B4, null, Db5, null, D5, null, A4, null, B4, null, Db5, null, D5, null, E5, null, Gb5, null,
    G5, null, A5, null, Gb5, null, D5, null, E5, null, Gb5, null, E5, null, D5, null, E5, null, Db5, null, D5, null, E5, null, Gb5, null, E5, null, D5, null,
    Db5, null, D5, null, B4, null, Db5, null, D5, null, D4, null, E4, null, Gb4, null, G4, null, Gb4, null, E4, null, Gb4, null, D5, null, Db5, null, D5, null,
    B4, null, D5, null, Db5, null, B4, null, A4, null, G4, null, A4, null, G4, null, Gb4, null, G4, null, A4, null, B4, null, Db5, null, D5, null, B4, null,
    D5, null, Db5, null, D5, null, Db5, null, B4, null, Db5, null, D5, null, E5, null, D5, null, Db5, null, D5, null, B4, null, Db5, null, D5, null, G5, null,
    Gb5, null, A4, null, E5, null, Gb5, null, B4, null, E5, null, Gb5, null, Gb4, null, E4, null, Gb4, null, G4, null, G4, null, B4, null, Db5, null, D5, null,
    B5, null, A5, null, G5, null, Gb5, null, G4, null, B4, null, Db5, null, D5, null, Db5, null, E5, null, A5, null, Db6, null, E5, null, Gb5, null, E5, null,
    A4, null, D5, null, D5, null, E5, null, D5, null, Db5, null, A4, null, D4, null, B4, null, B4, null, A4, null, G4, null, A4, null, D5, null, Gb4, null,
    G4, null, B4, null, Db5, null, D5, null, Db5, null, D5, null, E5, null, G5, null, Gb5, null, A5, null, E5, null, D5, null, Db5, null, D5, null, D5, null,
    E5, null, D5, null, Db5, null, Gb5, null, A5, null, B5, null, A5, null, G5, null, B5, null, A5, null, Db6, null, D6, null, B4, null, G4, null, D4, null,
    G4, null, B4, null, G4, null, D4, null, G4, null, Db5, null, A4, null, E4, null, A4, null, Db5, null, A4, null, E4, null, A3, null, D5, null, Db5, null,
    D4, null, Gb4, null, G4, null, A4, null, B4, null, A4, null, G4, null, A4, null, B4, null, Db5, null, A4, null, D5, null, B4, null, Db5, null, B4, null,
    D5, null, B4, null, Gb5, null, B4, null, A5, null, Db5, null, D5, null, E5, null, Gb5, null, A5, null, B5, null, A5, null, G5, null, B5, null, A5, null,
    Gb5, null, A5, null, D6, null, D5, null, B4, null, G4, null, B4, null, D5, null, B4, null, G4, null, D5, null, E5, null, Db5, null, A4, null, Db5, null,
    E5, null, Db5, null, A4, null, E4, null, D5, null, Db5, null, D4, null, Gb4, null, G4, null, A4, null, B4, null, A4, null, G4, null, A4, null, B4, null,
    Db5, null, A4, null, D5, null, B4, null, Db5, null, B4, null, D5, null, B4, null, Gb5, null, B4, null, A5, null, B5, null, B5, null, A5, null, A5, null,
    G5, null, G5, null, B5, null, B5, null, A5, null, Gb5, null, A5, null, D6, null, G5, null, D5, null, B4, null, D5, null, G5, null, D5, null, B4, null,
    D5, null, A5, null, E5, null, Db5, null, E5, null, Db6, null, A5, null, Gb5, null, G5, null, A5, null, Gb5, null, G5, null, A5, null, A4, null, B4, null,
    Db5, null, D5, null, E5, null, Gb5, null, G5, null, Gb5, null, D5, null, E5, null, Gb5, null, Gb4, null, G4, null, A4, null, B4, null, A4, null, G4, null,
    A4, null, D5, null, Db5, null, D5, null, G4, null, B4, null, A4, null, G4, null, Gb4, null, E4, null, Gb4, null, E4, null, D4, null, E4, null, Gb4, null,
    G4, null, A4, null, B4, null, G4, null, B4, null, A4, null, B4, null, Db5, null, D5, null, A4, null, B4, null, Db5, null, D5, null, E5, null, Gb5, null,
    G5, null, A5, null, Gb5, null, D5, null, E5, null, Gb5, null, E5, null, D5, null, E5, null, Db5, null, D5, null, E5, null, Gb5, null, E5, null, D5, null,
    Db5, null, D5, null, B4, null, Db5, null, D5, null, D4, null, E4, null, Gb4, null, G4, null, Gb4, null, E4, null, Gb4, null, D5, null, Db5, null, D5, null,
    B4, null, D5, null, Db5, null, B4, null, A4, null, G4, null, A4, null, G4, null, Gb4, null, G4, null, A4, null, B4, null, Db5, null, D5, null, B4, null,
    D5, null, Db5, null, D5, null, Db5, null, B4, null, Db5, null, D5, null, E5, null, D5, null, Db5, null, D5, null, B4, null, Db5, null, D5, null
};

const uint16_t canon_pause_Sheet [1409] = {
    null, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25,
    ms_500, ms_25, ms_250, ms_25, ms_250, ms_25, ms_500, ms_25, ms_500, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_250, ms_25, ms_750, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_250, ms_25,
    ms_250, ms_25, ms_250, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_1000, ms_25, ms_500, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_500, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25,
    ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_500, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_1000, ms_25, ms_750, ms_25, ms_250, ms_25, ms_500, ms_25, ms_200, ms_25, ms_200, ms_25, ms_120, ms_25, ms_500, ms_25, ms_250, ms_25, ms_250, ms_25, ms_500, ms_25,
    ms_200, ms_25, ms_200, ms_25, ms_120, ms_25, ms_240, ms_25, ms_250, ms_25, ms_500, ms_25, ms_500, ms_25, ms_200, ms_25, ms_200, ms_25, ms_120, ms_25, ms_750, ms_25, ms_120, ms_25, ms_120, ms_25, ms_500, ms_25, ms_200, ms_25,
    ms_200, ms_25, ms_120, ms_25, ms_750, ms_25, ms_250, ms_25, ms_500, ms_25, ms_200, ms_25, ms_200, ms_25, ms_120, ms_25, ms_250, ms_25, ms_250, ms_25, ms_500, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25,
    ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_1000, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_500, ms_25, ms_250, ms_25,
    ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_1000, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_500, ms_25,
    ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_240, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_500, ms_25,
    ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_400, ms_60, ms_25, ms_60, ms_25, ms_25, ms_500, ms_25, ms_250, ms_25, ms_100, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25,
    ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_500, ms_25, ms_120, ms_25,
    ms_400, ms_25, ms_500, ms_25, ms_120, ms_25, ms_400, ms_25, ms_500, ms_25, ms_250, ms_25, ms_250, ms_25, ms_500, ms_25, ms_250, ms_25, ms_250, ms_25, ms_500, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_500, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_500, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_250, ms_25, ms_400, ms_25, ms_120, ms_25, ms_1000, ms_25, ms_750, ms_25,
    ms_250, ms_25, ms_500, ms_25, ms_200, ms_25, ms_200, ms_25, ms_120, ms_25, ms_500, ms_25, ms_250, ms_25, ms_250, ms_25, ms_500, ms_25, ms_200, ms_25, ms_200, ms_25, ms_120, ms_25, ms_250, ms_25, ms_250, ms_25, ms_500, ms_25,
    ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_750, ms_25, ms_250, ms_25, ms_750, ms_25, ms_120, ms_25, ms_120, ms_25, ms_500, ms_25, ms_200, ms_25,
    ms_200, ms_25, ms_120, ms_25, ms_250, ms_25, ms_250, ms_25, ms_500, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_500, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_250, ms_25,
    ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_400, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_500, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_250, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_1000, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_500, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_500, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25,
    ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_240, ms_25,
    ms_120, ms_25, ms_120, ms_25, ms_250, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_120, ms_25, ms_2000, ms_25
};

const uint16_t *canon_noteCounter = canon_music_Sheet;
const uint16_t *canon_durationCounter = canon_pause_Sheet;
uint16_t canon_checkLastElement = 0; 

void canonRockIntro() {
    speed_control(*++canon_noteCounter);
    duration_control(*++canon_durationCounter);
    canon_checkLastElement++;
    
    if (canon_checkLastElement > (sizeof (canon_music_Sheet)/sizeof(canon_music_Sheet[0]))) {
        canon_checkLastElement = 0; 
        canon_noteCounter = canon_music_Sheet;
        canon_durationCounter = canon_pause_Sheet;
    }
}

void play_canonRockIntro(){
    TMR1_SetInterruptHandler(canonRockIntro);
}

happyBirthday.c

C/C++
/**
  Company:
    Microchip Technology Inc.

  File Name:
    happyBirthday.c

  Summary:
    It contains the code for playing Happy Birthday song.
  
  Author: A20687
  Last Modified Date: 10/16/2018
  
 */

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
 */


#include "../mcc_generated_files/mcc.h"
#include "../Control/control.h"
#include "notes_duration.h"
#include "stepperMusic.h"

void happyBday();

const uint16_t happyBday_music_Sheet [105] = {
    null, G4, null, G4, null, Ab4, null, G4, null, C5, null, Bb4, null, G4, null, G4, null, Ab4, null,
    G4, null, D5, null, C5, null, G4, null, G4, null, Ab5, null, E5, null, C5, null, C5, null,
    Bb4, null, Ab4, null, F5, null, F5, null, E5, null, C5, null, D5, null, C5, null, G4, null, 
    G4, null, Ab4, null, G4, null, C5, null, Bb4, null, G4, null, G4, null, Ab4, null,
    G4, null, D5, null, C5, null, G4, null, G4, null, Ab5, null, E5, null, C5, null, C5, null,
    Bb4, null, Ab4, null, F5, null, F5, null, E5, null, C5, null, D5, null, C5, null
};

const uint16_t happyBday_pause_Sheet [105] = {
    ms_923, ms_230, ms_150, ms_230, ms_150, ms_500, ms_150, ms_500, ms_150, ms_500, ms_150, ms_923, ms_150, ms_230, ms_150,
    ms_230, ms_150, ms_500, ms_150, ms_500, ms_150, ms_500, ms_150, ms_923, ms_150, ms_230, ms_150, ms_230, ms_150, ms_500,
    ms_150, ms_500, ms_150, ms_230, ms_150, ms_230, ms_150, ms_500, ms_150, ms_500, ms_150, ms_230, ms_150, ms_230, ms_150,
    ms_500, ms_150, ms_500, ms_150, ms_500, ms_150, ms_923, ms_230,ms_230, ms_150, ms_230, ms_150, ms_500, ms_150, ms_500, 
    ms_150, ms_500, ms_150, ms_923, ms_150, ms_230, ms_150, ms_230, ms_150, ms_500, ms_150, ms_500, ms_150, ms_500, ms_150, 
    ms_923, ms_150, ms_230, ms_150, ms_230, ms_150, ms_500, ms_150, ms_500, ms_150, ms_230, ms_150, ms_230, ms_150, ms_500, 
    ms_150, ms_500, ms_150, ms_230, ms_150, ms_230, ms_150, ms_500, ms_150, ms_500, ms_150, ms_500, ms_150, ms_923, ms_5000
};

const uint16_t *HBD_noteCounter = happyBday_music_Sheet;
const uint16_t *HBD_durationCounter = happyBday_pause_Sheet;
uint16_t HBD_checkLastElement = 0;

void happy_Bday() {
    speed_control(*++HBD_noteCounter);
    duration_control(*++HBD_durationCounter);
    HBD_checkLastElement++;

    if(HBD_checkLastElement > (sizeof (happyBday_music_Sheet)/sizeof(happyBday_music_Sheet[0]))){
        HBD_checkLastElement = 0;
        HBD_noteCounter = happyBday_music_Sheet;
        HBD_durationCounter = happyBday_pause_Sheet;
    }
}

void play_happyBday(){
    TMR1_SetInterruptHandler(happy_Bday);
}

joyToTheWorld.c

C/C++
/**
  Company:
    Microchip Technology Inc.

  File Name:
    joyToTheWorld.c

  Summary:
    It contains the code for playing Joy to the World music.
  
  Author: A20692
  Last Modified Date: 10/19/2018
  
*/

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
*/

#include "../mcc_generated_files/tmr1.h"
#include "../Control/Control.h"
#include "notes_duration.h"
#include "stepperMusic.h"

void joyToTheWorld();

const uint16_t joyToTheWorld_music_Sheet [237] = {
    null, A4, null, Ab4, null, F4, null, E4, null, D4, null, C4, null, B3, null, A3, null, E4, null, F4, null, F4, null, Ab4, null, Ab4, null, A4, null, A4, null,
    A4, null, Ab4, null, F4, null, E4, null, E4, null, D4, null, C4, null, A4, null, A4, null, Ab4, null, F4, null, E4, null, E4, null, D4, null, C4, null,
    C4, null, C4, null, C4, null, C4, null, C4, null, C4, null, D4, null, E4, null, D4, null, C4, null, B3, null, B3, null, B3, null, B3, null, B3, null,
    C4, null, D4, null, C4, null, B3, null, A3, null, A4, null, Ab4, null, F4, null, E4, null, D4, null, E4, null, C4, null, B3, null, A3, null, A4, null,
    Ab4, null, F4, null, E4, null, D4, null, C4, null, B3, null, A3, null, E4, null, F4, null, F4, null, Ab4, null, Ab4, null, A4, null, A4, null, A4, null, 
    Ab4, null, F4, null, E4, null, E4, null, D4, null, C4, null, A4, null, A4, null, Ab4, null, F4, null, E4, null, E4, null, D4, null, C4, null, C4, null, 
    C4, null, C4, null, C4, null, C4, null, C4, null, D4, null, E4, null, D4, null, C4, null, B3, null, B3, null, B3, null, B3, null, B3, null, C4, null, 
    D4, null, C4, null, B3, null, A3, null, A4, null, Ab4, null, F4, null, E4, null, D4, null, E4, null, C4, null, B3, null, A3, null

};

const uint16_t joyToTheWorld_pause_Sheet [237] = {
    null, ms_500, ms_25, ms_350, ms_20, ms_100, ms_10, ms_700, ms_40, ms_240, ms_10, ms_500, ms_25, ms_500, ms_25, ms_700,
    ms_50, ms_250, ms_10, ms_700, ms_50, ms_250, ms_10, ms_700, ms_50, ms_250, ms_10, ms_1500, ms_200, ms_250, ms_10,
    ms_250, ms_10, ms_250, ms_10, ms_250, ms_10, ms_250, ms_10, ms_350, ms_25, ms_100, ms_10, ms_250, ms_10, ms_250,
    ms_10, ms_250, ms_10, ms_250, ms_10, ms_250, ms_10, ms_250, ms_10, ms_250, ms_25, ms_100, ms_10, ms_250, ms_10, 
    ms_250, ms_10, ms_100, ms_10, ms_100, ms_10, ms_250, ms_10, ms_250, ms_10, ms_100, ms_10, ms_100, ms_10, ms_700, 
    ms_50, ms_100, ms_10, ms_100, ms_10, ms_100, ms_10, ms_100, ms_10, ms_250, ms_10, ms_250, ms_10, ms_100, ms_10, 
    ms_100, ms_10, ms_700, ms_50, ms_100, ms_10, ms_100, ms_10, ms_250, ms_10, ms_500, ms_25, ms_250, ms_10, ms_350, 
    ms_20, ms_100, ms_10, ms_250, ms_10, ms_250, ms_10, ms_500, ms_25, ms_500, ms_25, ms_1000, ms_50, ms_500, ms_25, 
    ms_350, ms_20, ms_100, ms_10, ms_700, ms_40, ms_240, ms_10, ms_500, ms_25, ms_500, ms_25, ms_700, ms_50, ms_250, 
    ms_10, ms_700, ms_50, ms_250, ms_10, ms_700, ms_50, ms_250, ms_10, ms_1500, ms_200, ms_250, ms_10, ms_250, ms_10, 
    ms_250, ms_10, ms_250, ms_10, ms_250, ms_10, ms_350, ms_25, ms_100, ms_10, ms_250, ms_10, ms_250, ms_10, ms_250, ms_10, 
    ms_250, ms_10, ms_250, ms_10, ms_250, ms_10, ms_250, ms_25, ms_100, ms_10, ms_250, ms_10, ms_250, ms_10, ms_100, ms_10, 
    ms_100, ms_10, ms_250, ms_10, ms_250, ms_10, ms_100, ms_10, ms_100, ms_10, ms_700, ms_50, ms_100, ms_10, ms_100, ms_10, 
    ms_100, ms_10, ms_100, ms_10, ms_250, ms_10, ms_250, ms_10, ms_100, ms_10, ms_100, ms_10, ms_700, ms_50, ms_100, ms_10, 
    ms_100, ms_10, ms_250, ms_10, ms_500, ms_25, ms_250, ms_10, ms_350, ms_20, ms_100, ms_10, ms_250, ms_10, ms_250, ms_10, 
    ms_500, ms_25, ms_500, ms_25, ms_1000, ms_50
};
const uint16_t *Joy_noteCounter = joyToTheWorld_music_Sheet;
const uint16_t *Joy_durationCounter = joyToTheWorld_pause_Sheet;
uint8_t Joy_checkLastElement = 0; 

void joyToTheWorld() {
    speed_control(*++Joy_noteCounter);
    duration_control(*++Joy_durationCounter);
    Joy_checkLastElement++;
    
    if (Joy_checkLastElement > (sizeof (joyToTheWorld_music_Sheet)/sizeof(joyToTheWorld_music_Sheet[0]))) {
        Joy_checkLastElement = 0; 
        Joy_noteCounter = joyToTheWorld_music_Sheet;
        Joy_durationCounter = joyToTheWorld_pause_Sheet;
    }
}

void play_joyToTheWorld(){
    TMR1_SetInterruptHandler(joyToTheWorld);
}

superMario.c

C/C++
/**
  Company:
    Microchip Technology Inc.

  File Name:
    superMario.c

  Summary:
    It contains the code for playing Super Mario.
  
  Author: A20687
  Last Modified Date: 10/19/2018
  
*/

/*
    (c) 2018 Microchip Technology Inc. and its subsidiaries. 
    
    Subject to your compliance with these terms, you may use Microchip software and any 
    derivatives exclusively with Microchip products. It is your responsibility to comply with third party 
    license terms applicable to your use of third party software (including open source software) that 
    may accompany Microchip software.
    
    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER 
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY 
    IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS 
    FOR A PARTICULAR PURPOSE.
    
    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP 
    HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO 
    THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL 
    CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT 
    OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS 
    SOFTWARE.
*/

#include "../mcc_generated_files/mcc.h"
#include "../Control/control.h"
#include "notes_duration.h"
#include "stepperMusic.h"

void superMario();

const uint16_t superMario_music_Sheet [348] = {
    F5, null, F5, null, F5, null, C5, null, F5, null, Ab5,null, G4, null, C5, null, G4, null, E4, null,
    A4, null, B4, null, Bb4,null, A4, null, G4, null, F5, null, Ab5,null, A5, null, Gb5,null, Ab5,null,
    F5, null, C5, null, D5, null, B4, null, C5, null, G4, null, E4, null, A4, null, B4, null, Bb4,null,
    A4, null, G4, null, F5, null, Ab5,null, A5, null, Gb5,null, Ab5,null, F5, null, C5, null, D5, null,
    B4, null, Ab5,null, G5, null, Gb5,null, Eb5,null, F5, null, Ab4,null, A4, null, C5, null, A4, null,
    C5, null, D5, null, Ab5,null, G5, null, Gb5,null, Eb5,null, F5, null, C6, null, C6, null, C6, null,
    Ab5,null, G5, null, Gb5,null, Eb5,null, F5, null, Ab4,null, A4, null, C5, null, A4, null, C5, null,
    D5, null, E5, null, D5, null, C5, null, C5, null, C5, null, C5, null, C5, null, D5, null, F5, null,
    C5, null, A4, null, G4, null, C5, null, C5, null, C5, null, C5, null, D5, null, F5, null, C5, null,
    C5, null, C5, null, C5, null, D5, null, F5, null, C5, null, A4, null, G4, null, F5, null, F5, null,
    F5, null, C5, null, F5, null, Ab5,null, G4, null, F5, null, C5, null, G4, null, Ab4,null, A4, null,
    Gb5,null, Gb5,null, A4, null, B4, null, Bb5,null, Bb5,null, Bb5,null, Ab5,null, Gb5,null,
    F5, null, C5, null, A4, null, G4, null, F5, null, C5, null, G4, null, Ab4,null, A4, null, Gb5,null,
    Gb5,null, A4, null, B4, null, Gb5,null, Gb5,null, Gb5,null, F5, null, D5, null, C5, null, F5, null,
    C5, null, G4, null, Ab4,null, A4, null, Gb5,null, Gb5,null, A4, null, B4, null, Bb5,null, Bb5,null,
    Bb5,null, Ab5,null, Gb5,null, F5, null, C5, null, A4, null, G4, null, F5, null, C5, null, G4, null,
    Ab4,null, A4, null, Gb5, null,Gb5,null, A4, null, B4, null, Gb5,null, Gb5,null, Gb5,null, F5, null,
    D5, null, C5, null, G4, null, F4, null, C4, null
};

const uint16_t superMario_pause_Sheet [348] = {
    ms_150, ms_50,  ms_150, ms_200, ms_150, ms_200, ms_150, ms_50,  ms_150, ms_200, ms_150, ms_550, ms_150, ms_600, 
    ms_150, ms_400, ms_150, ms_400, ms_150, ms_400, ms_150, ms_200, ms_150, ms_200, ms_150, ms_20,  ms_150, ms_200,
    ms_150, ms_50,  ms_150, ms_200, ms_150, ms_50,  ms_150, ms_200, ms_150, ms_50,  ms_150, ms_200,  ms_150, ms_200,
    ms_150, ms_50,  ms_150, ms_20,  ms_150, ms_400, ms_150, ms_400, ms_150, ms_400, ms_150, ms_400, ms_150, ms_200,
    ms_150, ms_200, ms_150, ms_20,  ms_150, ms_200, ms_150, ms_50,  ms_150, ms_200, ms_150, ms_50,  ms_150, ms_200,
    ms_150, ms_50,  ms_150, ms_200,  ms_150, ms_200, ms_150, ms_50,  ms_150, ms_20,  ms_150, ms_800, ms_150, ms_30,
    ms_150, ms_30,  ms_150, ms_25,  ms_150, ms_200, ms_150, ms_200, ms_150, ms_50,  ms_150, ms_50,  ms_150, ms_200,
    ms_150, ms_30,  ms_150, ms_30,  ms_150, ms_400, ms_150, ms_30,  ms_150, ms_30,  ms_150, ms_25,  ms_150, ms_200,
    ms_150, ms_200, ms_150, ms_200, ms_150, ms_30,  ms_150, ms_1000,ms_150, ms_30,  ms_150, ms_30,  ms_150, ms_25,
    ms_150, ms_200, ms_150, ms_200, ms_150, ms_50,  ms_150, ms_50,  ms_150, ms_200, ms_150, ms_30,  ms_150, ms_30,
    ms_150, ms_400, ms_150, ms_400, ms_150, ms_400, ms_150, ms_1300,ms_150, ms_30,  ms_150, ms_200, ms_150, ms_200,
    ms_150, ms_30,  ms_150, ms_200, ms_150, ms_30,  ms_150, ms_200, ms_150, ms_30,  ms_150, ms_600, ms_150, ms_30,
    ms_150, ms_200, ms_150, ms_200, ms_150, ms_30,  ms_150, ms_200, ms_150, ms_1400,ms_150, ms_30,  ms_150, ms_200,
    ms_150, ms_200, ms_150, ms_30,  ms_150, ms_200, ms_150, ms_30,  ms_150, ms_200, ms_150, ms_30,  ms_150, ms_600,
    ms_150, ms_50,  ms_150, ms_200, ms_150, ms_200, ms_150, ms_50,  ms_150, ms_200, ms_150, ms_550, ms_150, ms_600,
    ms_150, ms_50,  ms_150, ms_200, ms_150, ms_400, ms_150, ms_200, ms_150, ms_50,  ms_150, ms_200, ms_150, ms_30,
    ms_150, ms_600, ms_150, ms_100, ms_150, ms_100, ms_150, ms_100, ms_150, ms_100, ms_150, ms_100, ms_150, ms_50,
    ms_150, ms_30,  ms_150, ms_200, ms_150, ms_30,  ms_150, ms_600, ms_150, ms_50,  ms_150, ms_200, ms_150, ms_400,
    ms_150, ms_200, ms_150, ms_50,  ms_150, ms_200, ms_150, ms_30,  ms_150, ms_600, ms_150, ms_100, ms_150, ms_100,
    ms_150, ms_100, ms_150, ms_100, ms_150, ms_100, ms_150, ms_100, ms_150, ms_1200,ms_150, ms_50,  ms_150, ms_200,
    ms_150, ms_400, ms_150, ms_200, ms_150, ms_50,  ms_150, ms_200, ms_150, ms_30,  ms_150, ms_600, ms_150, ms_100,
    ms_150, ms_100, ms_150, ms_100, ms_150, ms_100, ms_150, ms_100, ms_150, ms_50,  ms_150, ms_30,  ms_150, ms_200,
    ms_150, ms_30,  ms_150, ms_600, ms_150, ms_50,  ms_150, ms_200, ms_150, ms_400, ms_150, ms_200, ms_150, ms_50,
    ms_150, ms_200, ms_150, ms_30,  ms_150, ms_600, ms_150, ms_100, ms_150, ms_100, ms_150, ms_100, ms_150, ms_100,
    ms_150, ms_100, ms_150, ms_100, ms_150, ms_100, ms_150, ms_100, ms_150, ms_100, ms_150, ms_5000
};

const uint16_t *superMario_noteCounter = superMario_music_Sheet;
const uint16_t *superMario_durationCounter = superMario_pause_Sheet;
uint16_t superMario_checkLastElement = 0; 


void superMario() {
    speed_control(*++superMario_noteCounter);
    duration_control(*++superMario_durationCounter);
    superMario_checkLastElement++;
    
    if (superMario_checkLastElement > (sizeof (superMario_music_Sheet)/sizeof(superMario_music_Sheet[0]))) {
        superMario_checkLastElement = 0;
        superMario_noteCounter = superMario_music_Sheet;
        superMario_durationCounter = superMario_pause_Sheet;
    }
}

void play_superMario(){
    TMR1_SetInterruptHandler(superMario);
}

notes_duration.h

C Header File
/* Microchip Technology Inc. and its subsidiaries.  You may use this software 
 * and any derivatives exclusively with Microchip products. 
 * 
 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".  NO WARRANTIES, WHETHER 
 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED 
 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A 
 * PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION 
 * WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION. 
 *
 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, 
 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND 
 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS 
 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.  TO THE 
 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS 
 * IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF 
 * ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
 *
 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE 
 * TERMS. 
 */

/* 
 * File:   
 * Author: A20687 & A20692
 * Comments:
 * Revision history: 
 */

// This is a guard condition so that contents of this file are not included
// more than once.  
#ifndef NOTES_DURATION_H
#define	NOTES_DURATION_H

#include <xc.h> // include processor files - each processor file is guarded.  

//Music Notes
#define G3    0xFFB0       //196 Hz
#define Ab3   0xFFB4       //207.65 Hz
#define A3    0xFFB8       //220 Hz
#define Bb3   0xFFBC       //233.082Hz
#define B3    0xFFC0       //246.94 Hz

#define C4    0xFFC3       //261.6 Hz
#define Db4   0xFFC7       //277.183 Hz
#define D4    0xFFCA       //293.665 Hz
#define Eb4   0xFFCD       //311.127 Hz
#define E4    0xFFCF       //329.63 Hz
#define F4    0xFFD1       //349.23 Hz
#define Gb4   0xFFD5       //369.994 Hz
#define G4    0XFFD7       //392 Hz
#define Ab4   0xFFD9       //415.3 Hz
#define A4    0xFFDB       //440 Hz
#define Bb4   0xFFDD       //466.16 Hz
#define B4    0xFFDF       //493.88 Hz

#define C5    0XFFE1       //523.25 Hz
#define Db5   0xFFE3       //554.365 Hz
#define D5    0xFFE4       //587.33 Hz
#define Eb5   0xFFE6       //622.25 Hz
#define E5    0xFFE7       //659.26 Hz
#define F5    0XFFE8       //698.46 Hz
#define Gb5   0xFFE9       //739.99 Hz
#define G5    0xFFEB       //783.99 Hz
#define Ab5   0XFFEC       //830.61 Hz
#define A5    0xFFED       //880 Hz
#define Bb5   0xFFEE       //932.33 Hz
#define B5    0xFFF0       //987.767 Hz

#define C6    0xFFF1       //1046.5 Hz
#define Db6   0xFFF1       //1108.73 Hz
#define D6    0xFFF2       //1174.66 Hz
#define Eb6   0xFFF3       //1244.51 Hz
#define E6    0xFFF4       //1318.51 Hz
#define Gb6   0xFFF5       //1479.98 Hz

#define null  0x0000

// Music Duration
#define ms_10   0xFFD9
#define ms_20   0XFFB2
#define ms_25   0xFF9E
#define ms_30   0xFF8B
#define ms_40   0xFF65
#define ms_50   0XFF3D 
#define ms_60   0xFF16
#define ms_100  0xFE79
#define ms_120  0xFE2B
#define ms_150  0XFDBB
#define ms_200  0XFCF9
#define ms_230  0xFC7E
#define ms_240  0xFC56
#define ms_250  0xFC2F
#define ms_300  0xFB6C
#define ms_350  0xFAB4
#define ms_400  0XF9E5
#define ms_500  0xF85F
#define ms_550  0xF7AD
#define ms_600  0xF6EB
#define ms_700  0xF567
#define ms_750  0xF48E
#define ms_800  0xF3CB
#define ms_923  0xF1EB
#define ms_1000 0xF0BE
#define ms_1200 0xEDB0
#define ms_1300 0xEC2A
#define ms_1400 0xEAA3
#define ms_1500 0xE91D
#define ms_2000 0xE17B
#define ms_3000 0xD239
#define ms_5000 0xB3B5

#endif	/* NOTES_DURATION_H */

Credits

Maria Loida Canada

Maria Loida Canada

1 project • 0 followers
Thanks to Aldrin Abacan and Mike Gomez.

Comments