⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp3v.c

📁 使用MSP430做MP3播放器的专题源码
💻 C
📖 第 1 页 / 共 2 页
字号:
          break;
        case '2'://pause
          break;
        case '3'://previous
          if(SM_current_file>0)SM_current_file--;
            else SM_current_file=(SM_total_files-1);
          //v_init();
          v_reset(vol);
          break;
        case '4'://next
          if(SM_current_file<(SM_total_files-1))SM_current_file++;
            else SM_current_file=0;
          //v_init();
          v_reset(vol);
          break; 
        case '5'://F1
          putchar_uart0(0x0a);
          putchar_uart0(0x0d);
          putstring_uart0("F1 pressed");
          //v_reset(vol);
          //LCD_putstring("ABCDEFGHIJKLMNOP",0,42);
          //LCD_putstring("01234567890abcdefghijklmnopqrstuwxz",0,60);
          LCD_set_contrast(contrast);
          contrast+=4;
          if(contrast>=63) contrast=0x00; 
          //LCD_init();
          //LCD_show_BMP(BMP_data); 
          break;
        default:
          break;
        }
      validkey=0;
      }//end of if validkey
  LCD_on();
  LCD_init();
  LCD_show_BMP(BMP_data);
  putchar_uart0(0x0a);
  putchar_uart0(0x0d);
  putstring_uart0("Now playing: ");
  hexout_uart0(SM_current_file);
  //LCD_init(); 
  putstring_uart0(" size: "); 
  hexout_uart0_long(flength[SM_current_file]);

  SM_read_ID3tag(SM_current_file);


  c=SM_play_file("MP3");
    if(c!=SM_KEY_BREAK)
      {
      if(SM_current_file<(SM_total_files-1))SM_current_file++;
        else SM_current_file=0;
      //WAS v_init();
      v_reset(vol);
      }   

  }


//-------------------------------------
 for(i=0;i<SM_total_files;i++)
  {
  putchar_uart0(0x0a);
  putchar_uart0(0x0d);
  SM_current_file=i;
  putstring_uart0("Now playing: ");
  hexout_uart0(SM_current_file);
  c=SM_play_file("MP3");
  }

  while(1)          // Repeat forever
  {
  //play_test();  


    if(ischar_uart0())
      { 
      c=getchar_uart0();
      putchar_uart0(c);
      switch(c)
        {
        case '1':
          //Flash_test();
          putchar_uart1(0x89);
          break;

        case '2':
          st_init();
          play_test();
          break;

        case '3':
          st_read();
          break;

        case '4':
            //st_init();
            putchar_uart0('P');
            c=SM_play_file("MP3");
            hexout_uart0(c);
          break;
        
        default:
          break;
        }//end of switch
      }
  }//end of while
}//end of main
/*-------------------------------------------------------*/
/*              End of Function: main                    */
/*********************************************************/


// Delay very approximately 1 second.

void delay(void)
{
// Note: i is an unsigned integer. If not declared unsigned, 65000 in 16 bits
// becomes a negative number, and the loop is executed only once!

  unsigned int i;
  
  for (i = 65000; i > 0; i--);
} 

/*********************************************************/
/*  Name        : init_vars                              */
/*  Parameters  : none                                   */
/*  Returns     : none                                   */
/*  Scope       :                                        */
/*  Function    : initialize variables after power on    */
/*-------------------------------------------------------*/
void init_vars(void)
{
/* init serial buffer */
prd_uart0 = pwr_uart0 = buffer_rxuart0;
/* for timer */
free10ms=0;
freep1s=0;
freesec=0;
SM_flag1=0;
//LED_state=0x1111;
Red_LED_state=0x1111;
Green_LED_state=0x0000;
SM_total_files=0;
SM_current_file=0;
keystate=0x00;
oldkeystate=0x00;
validkey=0;
key='0';
vol=60;
contrast=0x18;
}
/*-------------------------------------------------------*/
/* End of Function: init_vars                            */
/*********************************************************/

/*********************************************************/
/*  Name        : init_hardware                          */
/*  Parameters  : none                                   */
/*  Returns     : none                                   */
/*  Scope       :                                        */
/*  Function    : initialize hardware after reset        */
/*-------------------------------------------------------*/
void init_hardware(void)
{
//WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
WDTCTL =0x5a80;  /* disable watchdog             */
//P3DIR = BIT0;     // P3.0 output

/* initialisation of i/o ports */
/* PORT1 is used as control for SmartMedia */
/* P10 SMCS out */
/* P11 SMRD out */
/* P12 SMWR out */
/* P13 CLE out */
/* P14 ALE out */
/* P15 R/B in */                      
/* P16 SM_On out */
/* P17 ST_On out */
P1DIR=0xdf; // 1101 1111
P1OUT=0x07; // 0000 0111

/* PORT2 is used as key inputs */
/* P20 PLAY/STOP in */
/* P21 PAUSE in */
/* P22 PREVIOUS in */
/* P23 NEXT in */
/* P24 F1 in */
/* P25 UP in */                      
/* P26 DOWN in */
/* P27 NU out */
P2DIR=0x80;  // 1000 0000
P2OUT=0x00;  // 0000 0000
P2IES=0x00; /* low to high transition */
P2IFG=0x00; /* reset all flags */
P2IE=0x00;  /* disabled for now */

/* PORT3 is used as misc. i/o */
/* P30 LED1 out */
/* P31 SO for VS1001K in */
/* P32 RESET out */
/* P33 LED2 out */
/* P34 PTx out */
/* P35 PRx in */                      
/* P36 SCL out */
/* P37 SDA out */
P3DIR=0xdd; // 1101 1101
P3OUT=0x3b; // 0011 1011

/* PORT4 is used as bidirectional data bus for SmartMedia and LCD */
/* P40 D0 i/o */
/* P41 D1 i/o */
/* P42 D2 i/o */
/* P43 D3 i/o */
/* P44 D4 i/o */
/* P45 D5 i/o */                      
/* P46 D6 i/o */
/* P47 D7 i/o */
P4DIR=0xff;   /* initially all outputs */
P4OUT=0x00;

/* PORT5 is used as misc. i/o */
/* P50 DATA_R in */
/* P51 SDI out */
/* P52 DCS (chip select for lcd) out */
/* P53 SCKR out */
/* P54 BIT_EN out */
/* P55 E out */                      
/* P56 R/W out */
/* P57 RS out */
P5DIR=0xfe; // 1111 1110
P5OUT=0x00; // 0000 0000

/* PORT6 is used as misc. i/o */
/* P60 DRESET out */
/* P61 xCS (chip select for VS1001K) out */
/* P62 NU out */
/* P63 NU out */
/* P64 NU out */
/* P65 NU out */                      
/* P66 NU out */
/* P67 NU out */
P6DIR=0xff; // 1111 1111 
P6OUT=0x00; // 0000 0000

/* USART0 used for debugging 19200,8,n,1 */
/* 8MHz/19200=416.666...=0x1a0 */
U0MCTL=0;
U0BR0=0xa0;
U0BR1=0x01;
/* select UTXD0 for P34/UTXD0 */
P3SEL|=0x10;
/* select URXD0 for P35/URXD0 */
P3SEL|=0x20;

/* enable USART modules */
ME1=0xc0; /* 11000000 - UTXE0=1, URXE0=1 */
/* USART Control Register */
U0CTL=0x10;   /* 00010000 */
              /* ||||||||_____ SWRST=0 */
              /* |||||||______ MM=0 */
              /* ||||||_______ SYNC=0, UART mode */
              /* |||||________ Listen=0 */
              /* ||||_________ CHAR=1, 8bit */
              /* |||__________ SP=0, 1 stop bit */
              /* ||___________ PEV=1 parity even */
              /* |____________ PEN=0 no parity */
/* Transmit Control Register */
U0TCTL=0x60;  /* 00110000 */  
              /* ||||||||_____ TXEPT=0 */
              /* |||||||______ unused */
              /* ||||||_______ TXWake=0 */
              /* |||||________ URXSE=0 */
              /* ||||_________ SSEL1 SSEL0 =11 clock for baud is SMCLK */
              /* ||___________ CKPL=0 */
              /* |____________ unused */
/* Receive Control Register */
U0RCTL=0x00;  /* 00000000 */
              /* ||||||||_____ RXERR=0 */
              /* |||||||______ RXWake=0 */
              /* ||||||_______ URXWIE=0 */
              /* |||||________ URXEIE=0 */
              /* ||||_________ BRK=0 */
              /* |||__________ OE=0 */
              /* ||___________ PE=0 */
              /* |____________ FE=0 */
/* enable receive interrupt */
IE1|=0x40;    /* 01000000 */
              /* ||||||||_____ WDTIE=0 */
              /* |||||||______ OFIE=0 */
              /* ||||||_______ NU */
              /* |||||________ NU */
              /* ||||_________ NMIIE=0 */
              /* |||__________ ACCVIE=0 */
              /* ||___________ URXIE0=1 */
              /* |____________ UTXIE0=0 */

/* USART1 used as master SPI */
/* max. speed accepted by STA013 = 320kbit/s */
/* 8MHz/320000=25=0x19 */

U1MCTL=0;
U1BR0=0x19;//was 0x19
U1BR1=0x00;
/* select SIMO1 for P51/SIMO1 */
/*        SOMI1 for P52/SOMI1 not used */
/*        UCLK1 for P53/UCLK1 */
P5SEL|=0x0e;

/* enable USART modules */
ME2=0x10; /* 00010000 - USPIE1=1 */
/* USART Control Register */
U1CTL=0x16;   /* 00010110 */
              /* ||||||||_____ SWRST=0 */
              /* |||||||______ MM=1 Master mode */
              /* ||||||_______ SYNC=1, SPI mode */
              /* |||||________ Listen=0 */
              /* ||||_________ CHAR=1, 8bit */
              /* |||__________ unused */
              /* ||___________ unused */
              /* |____________ unused */
/* Transmit Control Register */
//WASU1TCTL=0xf2;  /* 11110010 */  
U1TCTL=0xb2;  /* 10110010 */  
              /* ||||||||_____ TXEPT=0 */
              /* |||||||______ STC=1 3-pin SPI */
              /* ||||||_______ unused */
              /* |||||________ unused */
              /* ||||_________ SSEL1 SSEL0 =11 clock for baud is SMCLK */
              /* ||___________ CKPL=1 inactive clock level high, data out on falling adge */
              /* |____________ unused */
/* Receive Control Register */
U1RCTL=0x00;  /* 00000000 */
              /* ||||||||_____ RXERR=0 */
              /* |||||||______ RXWake=0 */
              /* ||||||_______ URXWIE=0 */
              /* |||||________ URXEIE=0 */
              /* ||||_________ BRK=0 */
              /* |||__________ OE=0 */
              /* ||___________ PE=0 */
              /* |____________ FE=0 */
/* interrupt not used */
IE2=0x00;     /* 00000000 */
              /* ||||||||_____ NU */
              /* |||||||______ NU */
              /* ||||||_______ NU */
              /* |||||________ NU */
              /* ||||_________ URXIE1=0 */
              /* |||__________ UTXIE1=0 */
              /* ||___________ NU */
              /* |____________ NU */

/* timerA used to generate intervals */
/* Timer_A Control Register */
TACTL=0x0232; /* 0000 0010 0011 0010 */
              /* |||| |||| |||| ||||_ TAIFG=0 */
              /* |||| |||| |||| |||__ TAIE=1 enable INT */
              /* |||| |||| |||| ||___ CLR=0 */
              /* |||| |||| |||| |____ not used */
              /* |||| |||| ||||______ MC1,MC0=11 mode up/down */
              /* |||| |||| ||________ ID1,ID0=00 input divider=1 */
              /* |||| ||||___________ SSEL1,SSEL0=10 SMCLK used */
              /* |||| ||_____________ unused */

CCR0=0x9c40;  /* 40000x2=80000 with 8MHz SMCLK gives 10ms period */
//TACTL |= 0x0030;  /* start up/down timer */ 
//TACTL |= 0x0020;
}
/*-------------------------------------------------------*/
/* End of Function: init_hardware                        */
/*********************************************************/
void play_test(void)
{
//unsigned char DR;
unsigned char error;
unsigned int i;
unsigned int page_num;
unsigned char *ptr;
unsigned int j;

//DR=0;
putchar_uart0('P');
//SM_all_read(SM_page_data,0);
for (page_num=4224; page_num<32768; page_num++)
  {
  error=SM_page_read(SM_page_data,page_num);
  //hexout_uart0_int(page_num); 
  ptr=SM_page_data;
  for(i=0; i<512; i++)
    // if necessary wait for DATA_R to be high
    //if((P5IN&0x01)==1) DR=1;
    //if (DR==1) while((P5IN&0x01)==0){}
    putchar_uart1(*ptr++);
  j=0;
  while(((P5IN&0x01)==0)&(j<20000)) j++;
  }
putchar_uart0('F');
}

#include "serial.c"
#include "smedia.c"
//#include "ST.c"
#include "VS1001K.c"
#include "lcd.c"
#include "diskappl.c"
#include "mischard.c"
#include "ints.c"
//#include "tables.c"

/*********************************************************/
/* END OF FILE MP3.C                                     */
/*********************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -