My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
FountAudioCode  
Updated Dec 1, 2013 by rijadsul...@gmail.com

Code

/******************************************************************************/
/* Files to Include                                                           */
/******************************************************************************/

#if defined(__XC)
    #include <xc.h>        /* XC8 General Include File */
#elif defined(HI_TECH_C)
    #include <htc.h>       /* HiTech General Include File */
#elif defined(__18CXX)
    #include <p18cxxx.h>   /* C18 General Include File */
#endif

#if defined(__XC) || defined(HI_TECH_C)

#include <stdint.h>        /* For uint8_t definition */
#include <stdbool.h>       /* For true/false definition */

#endif

#include "system.h"        /* System funct/params, like osc/peripheral config */
#include "user.h"          /* User funct/params, such as InitApp */
#include <delays.h>

/******************************************************************************/
/* User Global Variable Declaration                                           */
/******************************************************************************/

/* i.e. uint8_t <variable_name>; */


//Used to Write pins on pic
#define TRACK1 LATCbits.LATC1
#define TRACK2 LATCbits.LATC2
#define TRACK3 LATCbits.LATC3

//#define TRACK1 PORTCbits.RC1
//#define TRACK2 PORTCbits.RC2
//#define TRACK3 PORTCbits.RC3

int i;

void playAudio( int track );

/******************************************************************************/
/* Main Program                                                               */
/******************************************************************************/

// One clock cycle is 130 ns

void main(void)
{
    // Set TRI state bits to outputs
    TRISCbits.TRISC1 = 0;
    TRISCbits.TRISC2 = 0;
    TRISCbits.TRISC3 = 0;

    PORTC = 1;      // All portc high
    PORTC = 0;      // All portc low


    //Set all pins to High
    TRACK1 = 1;
    TRACK2 = 1;
    TRACK3 = 1;

    //playAudio(3);
    //playAudio(2);
    //playAudio(1);

    while(1)
    {
        //Example of how you call the function
        //playAudio(1);
        //playAudio(2);
        //playAudio(3);

    }

}



void playAudio( int track )
{
    if (track == 1)
    {
        //Set pin to Low to play the track
        TRACK1 = 0;
        //Delay to make sure the pin is grounded
        Delay1KTCYx(100);
        //Set pin back to high so it can be played again later
        TRACK1 = 1;


        //Previously used for debugging
        //for(i = 0; i < 5; i++)
            //Delay10KTCYx(255);
    }

    if (track == 2)
    {

        //Set pin to low to play the track
        TRACK2 = 0;
        //Delay to make sure the pin is grounded
        Delay1KTCYx(100);
        //Set pin back to high so it can be played again later
        TRACK2 = 1;


        //Previously used for debugging
        //for(i = 0; i < 5; i++)
            //Delay10KTCYx(255);
    }

    if (track == 3)
    {

        //Set pin to low to play the track
        TRACK3 = 0;
        //Delay to make sure the pin is grounded
        Delay1KTCYx(100);
        //Set pin back to high so it can be played again later
        TRACK3 = 1;

        //Previously used for debugging
        //for(i = 0; i < 5; i++)
            //Delay10KTCYx(255);
    }

}
Powered by Google Project Hosting