PIC18F4550 MP3 Player (Kind Of)

Discussion in 'Programmer's Corner' started by GOkussj5okazu, Aug 11, 2013.

  1. GOkussj5okazu

    Thread Starter New Member

    Jul 9, 2009
    3
    0
    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.

    [​IMG]

    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.

    Code ( (Unknown Language)):
    1.  
    2.  
    3. #include "M6GDeluxe.h"
    4. #include "mmc_driver.h"
    5. #include "vs1011_driver.h"
    6. #include "fat_driver.h"
    7.  
    8. unsigned int32 current_sector;
    9. unsigned int32 current_file;
    10. unsigned char play_sound;
    11. unsigned char ammo_count;
    12. unsigned char lzr_on;
    13. unsigned char FIRED;
    14.  
    15.  
    16. //General Functions
    17.  
    18. void player_init()
    19. {
    20.    
    21.    ADCON1 = 0b00001111;     // Port A Digital I/O
    22.      
    23.    TRIS_A = 0b00100000;        // PortA.5 Input
    24.    TRIS_B = 0b11110001;        // PortB Inputs
    25.  
    26.    volume = 0x7F;            // Volume = 127
    27.    current_sector = 0x00;
    28.    current_file = 0;
    29.    play_sound = 0;
    30.    ammo_count = 8;
    31.    lzr_on = 0;
    32.    MUZZLE = 0;
    33.    FIRED = 0;
    34.    
    35. }
    36.  
    37. void main()
    38. {
    39.  
    40.     while (TRIGGER)
    41.     {
    42.     FIRED = 0;
    43.     }
    44.  
    45.     if (!TRIGGER)
    46.     {
    47.     delay_ms(20);
    48.         if( !TRIGGER)
    49.         {
    50.             if (FIRED == 0)
    51.             {
    52.                 if (ammo_count > 0)
    53.                 {
    54.                     current_file = 0;
    55.                     MUZZLE = 1;
    56.                     play_sound = 1;
    57.                     ammo_count --;
    58.                     FIRED = 1;
    59.                     delay_ms(75);
    60.                     MUZZLE = 0;
    61.                     delay_ms(155);
    62.                 }
    63.                 else
    64.                 {
    65.                     current_file = 1;
    66.                     play_sound = 1;
    67.                     delay_ms(230);
    68.                 }
    69.             }
    70.         }
    71.     }
    72.  
    73.     if (!RELOAD)
    74.     {
    75.     ammo_count = 8;
    76.     }
    77.  
    78.     if (!LZRSW)
    79.     {
    80.     delay_ms(20);
    81.         if (!LZRSW)
    82.         {
    83.             if (lzr_on == 0)
    84.             {
    85.             LZR = 1;
    86.             }
    87.             else
    88.             {
    89.             LZR = 0;
    90.             }
    91.         }
    92.     }
    93.  
    94.  
    95.    int mmc_result;
    96.    char cmd;
    97.  
    98.    player_init();
    99.    delay_ms(10);  
    100.  
    101.    mmc_result = mmc_init();
    102.    LED = mmc_result;
    103.  
    104.     if (mmc_result != 0)
    105.     {
    106.         while (1);
    107.     }
    108.  
    109.    delay_ms(100);
    110.    
    111.    resetvs1011_hard();
    112.  
    113.    blink_led(3);
    114.    
    115.    find_first_fat32_partition();
    116.    read_volumeid();
    117.    
    118.    while (play_sound == 1)
    119.    {
    120.       //mmc_read_block_to_vs1011(current_sector);
    121.       //current_sector++;
    122.  
    123.       cmd = play_file(current_file);
    124.    }
    125. }

    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!
     
  2. GOkussj5okazu

    Thread Starter New Member

    Jul 9, 2009
    3
    0
    No one wants to take a look? :)
     
Loading...