PIC18F4550 MP3 Player (Kind Of)

Thread Starter

GOkussj5okazu

Joined Jul 9, 2009
3
Hello! I'm hoping someone could take a look at my code here for a project I'm working on. I'm confident in my hardware setup, pictured below, but the code needs review.



Here's my circuit. PIC18F4550 connected to a VS1011 and an SD card via SPI. Pretty simple, hardware wire.

I'm using CCS C compiler. My program needs to play an MP3 file, and flash a set of LEDS whenever a switch is closed. I have attached a zip of my code, and I have posted my main file.

Rich (BB code):
#include "M6GDeluxe.h"
#include "mmc_driver.h"
#include "vs1011_driver.h"
#include "fat_driver.h"

unsigned int32 current_sector;
unsigned int32 current_file;
unsigned char play_sound;
unsigned char ammo_count;
unsigned char lzr_on;
unsigned char FIRED;


//General Functions

void player_init()
{
   
   ADCON1 = 0b00001111;     // Port A Digital I/O
      
   TRIS_A = 0b00100000;        // PortA.5 Input
   TRIS_B = 0b11110001;        // PortB Inputs

   volume = 0x7F;            // Volume = 127
   current_sector = 0x00;
   current_file = 0;
   play_sound = 0;
   ammo_count = 8;
   lzr_on = 0;
   MUZZLE = 0;
   FIRED = 0;
    
} 

void main()
{

    while (TRIGGER)
    {
    FIRED = 0;
    }

    if (!TRIGGER)
    {
    delay_ms(20);
        if( !TRIGGER)
        {
            if (FIRED == 0)
            {
                if (ammo_count > 0)
                {
                    current_file = 0;
                    MUZZLE = 1;
                    play_sound = 1;
                    ammo_count --;
                    FIRED = 1;
                    delay_ms(75);
                    MUZZLE = 0;
                    delay_ms(155);
                }
                else
                {
                    current_file = 1;
                    play_sound = 1;
                    delay_ms(230);
                }
            }
        }
    }

    if (!RELOAD)
    {
    ammo_count = 8;
    }

    if (!LZRSW)
    {
    delay_ms(20);
        if (!LZRSW)
        {
            if (lzr_on == 0)
            {
            LZR = 1;
            }
            else
            {
            LZR = 0;
            }
        }
    }


   int mmc_result;
   char cmd;

   player_init();
   delay_ms(10);  

   mmc_result = mmc_init();
   LED = mmc_result;

    if (mmc_result != 0) 
    {
        while (1);
    }

   delay_ms(100);
   
   resetvs1011_hard();

   blink_led(3);
   
   find_first_fat32_partition();
   read_volumeid();
   
   while (play_sound == 1)
   {
      //mmc_read_block_to_vs1011(current_sector);
      //current_sector++;

      cmd = play_file(current_file);
   }
}

This is just the main section. Please refer to my zip file for the rest. I just need to know if all of this will work as intended. Thanks in advance!
 

Attachments

Top