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

📄 diskappl.c

📁 用msp430设计的MP3方案,解码芯片用VS1001K
💻 C
📖 第 1 页 / 共 3 页
字号:

SM_chip_enable
//reset();  //TRY
SM_cmd_latch_en
SM_write(SM_READ1_C);	/*Main area data read command(00h)*/
SM_cmd_latch_dis
SM_add_latch_en

SM_write(0x00);
SM_write(temp);
SM_write(temp1);
if(SM_info[11]>=64)
  {
//  putchar_uart0('E');
//  hexout_uart0(temp2);
  SM_write(temp2);//another address cycle
  }
SM_add_latch_dis


for(n=startsector;n<sector+SM_info[7];n++)	
{
// waiting for R/B
for(i=0; i<50000; i++)//was 10000
	{ 
	//if(P4.PORT.BIT.B5==0) putchar_PC('0');
	//	else putchar_PC('1');
	if((P1IN &0x20)==0x20) break; /* P15 is R/B input */
	}	// waiting for ready 



for (j=0;j<512;j++)
	{
	c = SM_read();


  // if necessary wait for DATA_R to be high
  for(l=0;l<65000;l++)
    {
    if((P5IN &0x01)==0x01) break; /* P51 is DR input */

    for(i=0; i<65000; i++)
	    { 
	    if((P5IN &0x01)==0x01) break; /* P51 is DR input */
	    }	// waiting for ready 

    }

//P5OUT |= 0x10;  // 0001 0000 P54=BIT_EN (BSYNC)  
  putchar_uart1(c);

//P5OUT &= 0xef;
//for(i=0;i<2;i++){}
//P5OUT |= 0x10;  // 0001 0000 P54=BIT_EN (BSYNC)  
	//hexout_uart0(c);
  //putchar_uart0(' ');
 	}

//putchar_uart1(0x00);
//putchar_uart1(0x00);
//putchar_uart1(0x00);
//putchar_uart1(0x00);

for(j=0;j<16;j++)
  c=SM_read();// information area

//putstring_uart0("press...");
//putchar_uart0(0x0d);
//putchar_uart0(0x0a);
//while (ischar_uart0()==0){}
// getchar_uart0();
}

SM_chip_disable
return PASS;

}
/* End of SM_play_block ***********************************/ 
/***********************************************************
Function:       SM_dir
Purpose: 				to read file directory from SmartMedia card
Author:  				Jan Szymanski
Original Date:  25-01-2002
Date last Mod:
Comments:				returns number of dir entries and string at
                buffer location										
***********************************************************/
unsigned char SM_dir(unsigned char *buffer, unsigned int maxlength)
{
unsigned char entry_num;
unsigned char *dptr;
unsigned char errorcode;
unsigned int phsector;  // physical sector of root directory
unsigned int i,j,k;
//unsigned int entry,sector;
unsigned char *bptr,*temp;
unsigned char d,e; 
unsigned int SCN;	/* start cluster number */
/* temp holds physical sector number */
/* there are 256 directory entries, each entry 32 bytes */
/* 256*32=8192 bytes = 16 sectors */
/* we need to search for filename.ext, first file with extention ext */
/* will be taken */
temp=buffer;
*temp++='N';
*temp++='O';
*temp++='T';
*temp++='H';
*temp++='I';
*temp++='N';
*temp++='G';
*temp++=0x00;


/* first create/or update address conversion table */
/* but only if doesn't exists as it is time consuming */
//if(SM_flag1 == 0)
//	{
//	errorcode=SM_log_to_phy();
//	if(errorcode!=SM_OK) return errorcode;	/* error return */
//  } 

/* 8MB - root directory in logical block 2 - sectors 32-47 */
if(SM_info[1]==0xE6) phsector=SM_log_to_phyADD1[2]<<4;	/* physical address of logical sector 32 */
/* 16MB - root directory in logical block 1 - sectors 48-63 */
if(SM_info[1]==0x73) phsector=(SM_log_to_phyADD1[1]<<5) + 0x10;	/* physical address of logical sector 48 */
/* 32MB - root directory in logical block 1 - sectors 48-63 */
if(SM_info[1]==0x75) phsector=(SM_log_to_phyADD1[1]<<5) + 0x10;	/* physical address of logical sector 48 */
/* 64MB - root directory in logical block 2 - sectors 80-95 */
if(SM_info[1]==0x76) phsector=(SM_log_to_phyADD1[2]<<5) + 0x10;	/* physical address of logical sector 80 */

entry_num=0;
dptr=buffer;
//sector=0;
for(i=phsector;i<phsector+16;i++)
	{
	SM_page_read(SM_page_data,i);
// for debug only
//  bptr=SM_page_data;
//  for(k=0;k<512;k++)
//    {
//    hexout_uart0(*bptr++);
//    putchar_uart0(','); 
//    }
//  while(ischar_uart0()==0){}
//    getchar_uart0();
//  putchar_uart0(0x0a);
//  putchar_uart0(0x0d);
// end of for debug

	//entry=0xff;
	bptr=SM_page_data; 
	
	for(j=0;j<16;j++)
			{
      temp=bptr;
			d=*temp;
			if (d!=0xe5)	/* not deleted directory */
				{
        temp+=11;
				e=*temp;
        //hexout_uart0(e);
				if(e==0x20) // valid entry???
					{ 
					
          temp+=16;//+27
					SCN=*temp--;//+26
					SCN<<=8;
					SCN+=*temp;
          temp=bptr;
					for(k=0;k<11;k++)
					  *dptr++=*temp++;// copy of filename.ext 8.3
					//dptr+=32;
          *dptr=0x00;// dptr>12
          start_block[entry_num]=SCN;
// for filelength
          temp=bptr;
          temp+=31;
          flength[entry_num]=0;
          flength[entry_num]+=*temp--;
          flength[entry_num]<<=8;
          flength[entry_num]+=*temp--;
          flength[entry_num]<<=8;
          flength[entry_num]+=*temp--;
          flength[entry_num]<<=8;
          flength[entry_num]+=*temp--;         
// end for filename
          entry_num++;
					}
				}
				bptr+=32;
			}
	}
return entry_num;
}
/* End of SM_dir ******************************************/

/***********************************************************
Function:       SM_read_ID3tag
Purpose: 				to read ID3 tag from *.mp3 file on SmartMedia
                card
Author:  				Jan Szymanski
Original Date:  25-01-2002
Date last Mod:
Comments:												
***********************************************************/
void SM_read_ID3tag(unsigned char SM_file)
{
/* we need to read last 128 bytes */
unsigned int cluster,oldcluster,temp1;
unsigned int logicalblock,physicalblock;
unsigned int block;
unsigned long sector,i;
unsigned char *ptr;
unsigned int j;
unsigned char c;
unsigned int lbsize;
unsigned char lsector;
unsigned char a,b,d;

//cluster=start_block[SM_current_file];
cluster=start_block[SM_file]; /* Start Cluster Number */
while(temp1!=0x0fff)	/* cluster 0x0fff indicates end */
	{
  oldcluster=cluster; 
/* find next cluster in a cluster chain */
	temp1=SM_find_next_inFAT(cluster);
	cluster = temp1; 
  }

//hexout_uart0_int(oldcluster);
if(SM_info[1]==0x76) oldcluster+=1;// 64MB card

logicalblock = oldcluster;
// adjustment here for gaps 1000-1024,2000-2024,3000-3024
if(logicalblock>=3000)logicalblock+=72;
  else
    {
    if(logicalblock>=2000)logicalblock+=48;
      else if(logicalblock>=1000)logicalblock+=24;
    }
physicalblock = SM_log_to_phyADD1[logicalblock];
block=physicalblock;
sector=block<<5;

/* see what is the size of last block */
lbsize=flength[SM_file] & 0x3fff; /* mod 0x4000 */
lsector=lbsize/0x200;

/* for debugging */
//hexout_uart0_int(lbsize);
//hexout_uart0(lsector);
//putchar_uart0(' ');
//putstring_uart0("press");
//while(ischar_uart0()==0){}
//getchar_uart0();

//for(i=sector;i<sector+SM_info[7];i++)
//	{
//	SM_page_read(SM_page_data,i);
//  hexout_uart0_int(i); 
//  ptr=SM_page_data;
//  for(j=0; j<512; j++)
//    {
//    c=*ptr++;
//    if((c>0x20)&&(c<0x7a)) putchar_uart0(c); 
//      else putchar_uart0('.');
//    }  
//  hexout_uart0(*ptr++);
  
//  putstring_uart0("press");
//  while(ischar_uart0()==0){}
//  getchar_uart0();
//  }
/* end of for debugging */

/* N/A not available by default */

ID3_title[0]='N';
ID3_artist[0]='N';
ID3_album[0]='N';
ID3_title[1]='/';
ID3_artist[1]='/';
ID3_album[1]='/';
ID3_title[2]='A';
ID3_artist[2]='A';
ID3_album[2]='A';
for(j=3; j<31; j++)
  {
  ID3_title[j]=0x00;
  ID3_artist[j]=0x00;
  ID3_album[j]=0x00;
  }

putstring_uart0(ID3_artist);
putstring_uart0(ID3_title);
putstring_uart0(ID3_album);
putchar_uart0('_');

sector += lsector;
SM_page_read(SM_page_data,sector);
ptr=SM_page_data;

//for(j=0; j<512; j++)
//  {
//  c=*ptr++;
//  if((c>0x20)&&(c<0x7a)) putchar_uart0(c); 
//  else putchar_uart0('.');
//  }  

ptr=SM_page_data;
for(j=0; j<512; j++)
  {
  a=*ptr++;
  b=*ptr++;
  d=*ptr++;

  if((a=='T')&&(b=='A')&&(d=='G'))
    {        
    putstring_uart0(" TAG found  ");
    break;
    }
  ptr-=2;
  }

//hexout_uart0_int(SM_page_data);
//putchar_uart0(',');
//hexout_uart0_int(ptr);

if(ptr!=SM_page_data+512)
  {
   for(j=0;j<30;j++)
    ID3_title[j]=*ptr++;
   for(j=0;j<30;j++)
    ID3_artist[j]=*ptr++;
   for(j=0;j<30;j++)
    ID3_album[j]=*ptr++;
  }

putchar_uart0(0x0a);
putchar_uart0(0x0d);
ID3_artist[20]=0x00; /* for lcd - one line only for artist */
putstring_uart0(ID3_artist);
putchar_uart0(0x0a);
putchar_uart0(0x0d);
ID3_title[30]=0x00;
putstring_uart0(ID3_title);
putchar_uart0(0x0a);
putchar_uart0(0x0d);
ID3_album[30]=0x00;
putstring_uart0(ID3_album);
putchar_uart0(0x0a);
putchar_uart0(0x0d);

LCD_putstring("artist",0,0);
LCD_putstring(ID3_artist,1,0);

LCD_putstring("title",2,0);
LCD_putstring(ID3_title,3,0);

LCD_putstring("album ",5,0);
LCD_putstring(ID3_album,5,36);

}
/* End of SM_read_ID3tag *********************************/
/*********************************************************/
/* END OF FILE DiskAppl.c                                */
/*********************************************************/

⌨️ 快捷键说明

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