📄 mp3v.c
字号:
/*
* Copyright (c) 2002, Jan Szymanski.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Jan Szymanski.
* 4. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*********************************************************/
/* */
/* Module : MP3.C */
/* Language used : msp430-gcc */
/* Microprocessor : MSP430F149 */
/* */
/* Function : Does whatever it is supposed */
/* to do and a bit more */
/* ------------------------------------------------------*/
/* Revision History : */
/* Author Date Reason */
/* Jan Szymanski 6 December 2001 Initial Design */
/* Jan Szymanski 29 July 2002 Ported to GNU C */
/* */
/*********************************************************/
/*********************************************************/
/* Includes */
/*********************************************************/
#include "Includes.h"
/*********************************************************/
/* Global Variables */
/*********************************************************/
/* uart globals */
unsigned char *prd_uart0; /* read pointer */
unsigned char *pwr_uart0; /* write pointer */
unsigned char buffer_rxuart0[sizeb0]; /* uart0 receive buffer */
/* timer variables */
unsigned char free10ms;
unsigned char freep1s;
unsigned char freesec;
/* for delays */
unsigned char t10ms_1;
unsigned char t1s_1;
/* for keys */
unsigned char inP2t5;
unsigned char inP2t4;
unsigned char inP2t3;
unsigned char inP2t2;
unsigned char inP2t1;
unsigned char inP2t0;
unsigned char inP2deb;
unsigned char keystate;
unsigned char oldkeystate;
unsigned char validkey;
unsigned char key;
/* SmartMedia variables */
unsigned int SM_info[12];
unsigned char SM_page_data[528];
unsigned char SM_write_data[2];//was528
/* Disk Application variables */
unsigned int SM_log_to_phyADD[256]; /* should be 1000 */
//unsigned char SM_FAT_data[528];
unsigned char SM_flag1;
unsigned char SM_total_files;
unsigned char SM_current_file;
/* for LCD */
unsigned char LCD_buffer[256]; // was [512];
unsigned char ID3_title[31];
unsigned char ID3_artist[31];
unsigned char ID3_album[31];
unsigned int start_block[20];
unsigned long flength[20];
unsigned char bardots;
unsigned int baraddr;
unsigned char contrast;
/* for LED */
//unsigned int LED_state;
unsigned int Red_LED_state;
unsigned int Green_LED_state;
//unsigned char play_stop;
/* for audio volume control */
unsigned char vol;
unsigned char firstblock;
#include "tables.c"
/*********************************************************/
/* Function Prototypes */
/*********************************************************/
void init_vars(void);
void init_hardware(void);
void play_test(void);
/* serial.h */
void putchar_uart0(unsigned char c);
unsigned char getchar_uart0(void);
unsigned char ischar_uart0(void);
void putstring_uart0(unsigned char *str);
void hexout_uart0(unsigned char c);
void hexout_uart0_int(unsigned int i);
void hexout_uart0_long(unsigned long i);
void putchar_uart1(unsigned char c);
/* SMedia.h */
void SM_reset(void);
void SM_read_info(void);
unsigned char SM_page_read(unsigned char *page_data,unsigned long page_num);
unsigned char SM_page_write(unsigned char *write_data,unsigned int page_num);
unsigned char SM_block_erase(unsigned int block_number);
unsigned char SM_all_read(unsigned char *page_data,unsigned int page_num);
unsigned char SM_extra_read(unsigned char *page_data,unsigned long page_num);
/* for onboard flash programming */
void Flash_wb( char *Data_ptr, char byte );
void Flash_ww( int *Data_ptr, int word );
void Flash_clr( int *Data_ptr );
void Flash_test(void);
unsigned char Flash_seg_write (unsigned char *source, unsigned char *dest);
/* DiskAppl.h */
void SM_disk_init(void);
unsigned char SM_log_to_phy(void);
unsigned char SM_read_FAT(void);
unsigned char SM_play_block(unsigned int block);
unsigned char SM_play_file(unsigned char *fileextension);
unsigned char SM_dir(unsigned char *buffer, unsigned int maxlength);
unsigned int SM_find_next_inFAT(unsigned int cluster);
void SM_read_ID3tag(unsigned char SM_file);
//void LEDOff(void);
//void LEDRed(void);
//void LEDGreen(void);
void delay(void); // Software delay
/* st.h */
//void st_init(void);
//void st_read(void);
//void st_volume(unsigned char step);
/* vs1001k.h */
void v_init(void);
void v_reset(unsigned char vol);
unsigned int SCI_wread(unsigned char regaddress);
void SCI_wwrite(unsigned char regaddress, unsigned int param);
void v_volume(unsigned char vol);
void vWaitDReq(unsigned char level);
/* lcd.h */
unsigned int LCD_fileblocks(unsigned char fileno);
void LCD_init(void);
void LCD_reset(void);
void LCD_set_contrast(unsigned int contrast);
void LCD_show_BMP(const unsigned char *ptr);
//void LCD_putcharxy(unsigned char c, unsigned char x, unsigned char y);
void LCD_putchar(unsigned char c);
//void LCD_putstringxy(unsigned char *ptr, unsigned char x, unsigned char y);
void LCD_putstring(unsigned char *ptr,unsigned char page,unsigned char column);
void LCD_on(void);
void LCD_off(void);
void LCD_bar_start(unsigned int startaddr);
void LCD_bar_update(void);
/* mischard.h */
void SM_On(unsigned char command);
void ST_On(unsigned char command);
void m_sleep(void);
void m_awake(void);
/*********************************************************/
/* Name : main */
/* Parameters : none */
/* Returns : never returns */
/* Scope : */
/* Function : the main program loop */
/*-------------------------------------------------------*/
/* Memory map */
/* 0x00 - 0x0f Special Function Registers */
/* 0x10 - 0xff 8-bit Peripheral Modules */
/* 0x100 - 0x1ff 16-bit Perpheral Modules */
/* 0x200 - 0x9ff 2kB RAM Data Memory */
/* 0xc00 - 0xfff 1kB Boot ROM */
/* 0x1000 - 0x10ff 256 bytes flash */
/* 0x1100 - 0xffff 60kB flash */
/* 0xffe0 - 0xffff Interrupt Vectors */
void main(void)
{
unsigned char c;
unsigned int i;
unsigned long j;
// _SP = 0x09f0; /* was 0x0a00 stack pointer initialization */
WDTCTL =0x5a80; /* disable watchdog */
/* clock selection here */
/* 32.768kHz watch crystal connected to LFXT1 */
/* 8MHz crystal connected to XT2 */
IFG1=0; /* clear Interrupt Flags */
IFG2=0; /* clear Interrupt Flags */
BCSCTL1=0x04; /* 00000100 */
/* ||||||______ Rsel.2 Rsel.1 Rsel.0 */
/* |||||_______ XT5V always 0 */
/* ||||________ DIVA.1 DIVA.0 = 0 ACLK divided by 1 */
/* ||__________ XTS=0, low frequency for LFXT1 */
/* |___________ XT2Off=0, XT2 is on */
BCSCTL2=0x88; /* 10001000 */
/* ||||||||____ DCOR=0 */
/* |||||||_____ DIVS.1 DIVS.0 =0 SMCLK divided by 1 */
/* |||||_______ SELS use XT2CLK for SMCLK */
/* ||||________ DIVM.1 DIVM.0 MCLK divided by 1 */
/* ||__________ SELM.1 SELM.0 =2 use XT2CLK */
/* wait in loop until crystal is stable */
do
{
IFG1 &= 0xfd; //IFG1&=~OFIFG;
}while(IFG1 & 0x02); //(IFG1&OFIFG);
/* temporary for test output on P1.4/SMCLK and P2.0/ACLK and P54/MCLK */
//P1OUT=0;
//P1DIR|=0x10;
//P1SEL|=0x10;
//P2DIR|=0x01;
//P2SEL|=0x01;
//P5DIR|=0x10;
//P5SEL|=0x10;
/* end of temporary for test */
/* wait for a while and reset osc. fault flag again */
delay();
IFG1 &= 0xfd; //~OFIFG;
/* set XT1 as MCLK */
// BCSCTL2=0xc0; /* 11000000 */
/* ||||||||____ DCOR=0 */
/* |||||||_____ DIVS.1 DIVS.0 =0 SMCLK divided by 1 */
/* |||||_______ SELS use DCOCLK for SMCLK */
/* ||||________ DIVM.1 DIVM.0 MCLK divided by 1 */
/* ||__________ SELM.1 SELM.0 =3 use LXT1CLK */
init_hardware(); /* initialize hardware */
init_vars(); /* initialize variables */
putchar_uart0(0x0d);
putchar_uart0(0x0a);
putchar_uart0(0x0d);
putchar_uart0(0x0a);
putstring_uart0("MP3 Player");
_EINT(); /* start interrupts */
// LCD_reset();
LCD_init();
LCD_show_BMP(BMP_data);
putchar_uart0(0x0d);
putchar_uart0(0x0a);
putstring_uart0("Reading SmartMedia Information");
putchar_uart0(0x0d);
putchar_uart0(0x0a);
SM_On(0x01); // power on to SmartMedia
SM_reset();
SM_read_info();
hexout_uart0(SM_info[0]); // device maker
putchar_uart0(',');
hexout_uart0(SM_info[1]);// device type
putstring_uart0(" - ");
switch(SM_info[1])
{
case 0x73:
putstring_uart0("16M detected");
break;
case 0x75:
putstring_uart0("32M detected");
break;
case 0x76:
putstring_uart0("64M detected");
break;
default:
putstring_uart0("no card or unsupported detected");
while(1) // stay here until valid SmartMedia
{
putstring_uart0("insert SmartMedia");
}
break;
}
putchar_uart0(0x0d);
putchar_uart0(0x0a);
// temporary only
//for (j=0;j<65535;j+=32)
// {
// hexout_uart0_long(j);
// putchar_uart0(':');
// SM_extra_read(SM_page_data,j);
// }
// end of temporary
c=SM_log_to_phy();
hexout_uart0(c);
SM_read_FAT(); /* first sector of FAT */
/* (logical sector 26 for 8MB or 42 for 16MB ) is */
/* moved to RAM, so we can follow cluster chain */
SM_flag1 = 1; /* set the flag, that table exists */
/* to save time */
// read file directory
SM_total_files=SM_dir(LCD_buffer,512);
hexout_uart0(SM_total_files);
putstring_uart0(LCD_buffer);
// m_sleep();
/* we stay here in sleep, waiting for keypress */
/* we are awaken, lets check the key */
// m_awake();
// _DINT(); /* disable interrupts */
// LED_state=0x0101;
// _EINT(); /* start interrupts */
validkey=1;
key='1';
/* for test of V1001k */
//ST_On(0x01);// turn power on to MP3 decoder and audio
//v_init();
//putchar_uart0(0x0a);
//putchar_uart0(0x0d);
//putstring_uart0("vMODE=");
//hexout_uart0_int(SCI_wread(0x00));
//putchar_uart0(0x0a);
//putchar_uart0(0x0d);
//putstring_uart0("vSTATUS=");
//hexout_uart0_int(SCI_wread(0x01));
//putchar_uart0(0x0a);
//putchar_uart0(0x0d);
//putstring_uart0("vCLOCKF=");
//hexout_uart0_int(SCI_wread(0x03));
//putchar_uart0(0x0a);
//putchar_uart0(0x0d);
//putstring_uart0("vVOLUME=");
//hexout_uart0_int(SCI_wread(0x0b));
// putchar_uart1(0x53);
// putchar_uart1(0xef);
// putchar_uart1(0x6e);
// putchar_uart1(0x30);
// putchar_uart1(0);
// putchar_uart1(0);
// putchar_uart1(0);
// putchar_uart1(0);
/* end of test */
while(1)
{
if(validkey==1)
{
switch(key)
{
case '1'://play/stop
LCD_off();
m_sleep();
m_awake();
LCD_on();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -