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

📄 mmc_drv.c

📁 atmel at89c51snd1c mp3芯片方案源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	    gl_media_buffer[i++] = Mmc_rd_byte();
        gl_media_buffer[i++] = Mmc_rd_byte();
	    gl_media_buffer[i++] = Mmc_rd_byte();
        gl_media_buffer[i++] = Mmc_rd_byte();
	    gl_media_buffer[i++] = Mmc_rd_byte();
        gl_media_buffer[i++] = Mmc_rd_byte();
	    gl_media_buffer[i++] = Mmc_rd_byte();
        gl_media_buffer[i++] = Mmc_rd_byte();
	    gl_media_buffer[i++] = Mmc_rd_byte();
        gl_media_buffer[i++] = Mmc_rd_byte();
	    gl_media_buffer[i++] = Mmc_rd_byte();
        gl_media_buffer[i++] = Mmc_rd_byte();
	 }
	 Mmc_disable_flow_ctrl(); 
     return TRUE;
  }
  else
  {
     return FALSE;
  }
}


//////////////////////////////////////////////////////////////////////////////
bit mmc_read_close(void)
{
   Mmc_disable_flow_ctrl();
   bMediaReadOpenFlag = 0;
   return OK;
}


//////////////////////////////////////////////////////////////////////////////
INT8U mmc_read_byte(void)
{  
   INT8U u8Data;

   if(u16MediaBytePointer >= 512)
   {
      u32MediaSector ++;               //sector number add
      mmc_read_close();
      mmc_read_open(u32MediaSector);
   }

   u8Data = gl_media_buffer[u16MediaBytePointer ++];
   return(u8Data);
}


//////////////////////////////////////////////////////////////////////////////
bit mmc_read_one_sector(INT32U u32MmcSector)
{
  Byte i;

  if(mmc_read_open(u32MmcSector) == OK)
  {
     for (i = 0; i < 8; i++)
     {
        Usb_select_ep(EP_IN);
                      /* read 64 bytes from card */
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
        Usb_write_byte(mmc_read_byte());        
        Usb_write_byte(mmc_read_byte());
     
        Usb_set_TXRDY();
        Usb_select_ep(EP_IN);
        while (!Usb_tx_complete());
        Usb_clear_TXCMPL();  
     }	 
     mmc_read_close();
     return OK;
   }
   return KO;
}


//////////////////////////////////////////////////////////////////////////////
bit mmc_write_open(INT32U u32MmcSector)
{  
   u32MediaSector = u32MmcSector;
   u16MediaBytePointer = 0;         //point to the first byte of the sector
   bMediaWriteOpenFlag = 1;
   Mmc_disable_flow_ctrl();
   return TRUE;
}


//////////////////////////////////////////////////////////////////////////////
bit mmc_write_close(void)
{    
  INT32U u32Address;   
  INT16U i;

  u32Address = u32MediaSector;
  u32Address <<= 9;

  Mmc_enable_flow_ctrl();    //enable control
  Mmc_set_write(); 			//set write mode

  Mmc_write_block_cmd(u32Address);    //send write command

  if(OK == mmc_response_Try())
  {  	 
     i = 0;

	 Mmc_wr_byte(gl_media_buffer[i++]); 
	 Mmc_wr_byte(gl_media_buffer[i++]);
	 Mmc_wr_byte(gl_media_buffer[i++]); 
	 Mmc_wr_byte(gl_media_buffer[i++]);
	 Mmc_wr_byte(gl_media_buffer[i++]); 
	 Mmc_wr_byte(gl_media_buffer[i++]);
	 Mmc_wr_byte(gl_media_buffer[i++]); 
	 Mmc_wr_byte(gl_media_buffer[i++]);
	 Mmc_wr_byte(gl_media_buffer[i++]); 
	 Mmc_wr_byte(gl_media_buffer[i++]);
	 Mmc_wr_byte(gl_media_buffer[i++]); 
	 Mmc_wr_byte(gl_media_buffer[i++]);
	 Mmc_wr_byte(gl_media_buffer[i++]); 
	 Mmc_wr_byte(gl_media_buffer[i++]);
	 Mmc_wr_byte(gl_media_buffer[i++]); 
	 Mmc_wr_byte(gl_media_buffer[i++]);
	 
	 Mmc_enable_send();   //enable sent
 //    while(Mmc_write_not_ready());
 //    lcd_print_string(0x40,"ready");
 //    Mmc_enable_send();
   //  while(!Mmc_empty_fifos());    //fifo isn't empty
   //  printch(0x40,"2");

	 for(; i<512; )
	 {      
         //       printch(0x40,"2");
	     //while(!Mmc_empty_fifos());    //fifo isn't empty
         //       printch(0x40,"3");
		 if(Mmc_empty_fifos())
		 {
		 	Mmc_wr_byte(gl_media_buffer[i++]); 
		 	Mmc_wr_byte(gl_media_buffer[i++]);
		 	Mmc_wr_byte(gl_media_buffer[i++]); 
		 	Mmc_wr_byte(gl_media_buffer[i++]);
		 	Mmc_wr_byte(gl_media_buffer[i++]); 
			Mmc_wr_byte(gl_media_buffer[i++]);
			Mmc_wr_byte(gl_media_buffer[i++]); 
			Mmc_wr_byte(gl_media_buffer[i++]); 
		 }
	 }

     bMediaWriteOpenFlag = 0;
     Mmc_disable_flow_ctrl();

     lcd_print_string(0x40,"4");
     return TRUE;
   }
   else
   {
     return FALSE;
   }

}

//////////////////////////////////////////////////////////////////////////////
bit mmc_write_byte(Byte mmc_data)
{   
   gl_media_buffer[u16MediaBytePointer ++] = mmc_data;
   return TRUE;
}


//////////////////////////////////////////////////////////////////////////////
bit mmc_write_one_sector(Uint32 mmc_sector)
{
   INT8U j;
   mmc_write_open(mmc_sector);

   Usb_select_ep(EP_OUT);   

   for (j=0; j<8; j++)
   {
      while(!Usb_rx_complete());          /* wait end of reception */

	  mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());
      mmc_write_byte(Usb_read_byte());

      Usb_clear_RXOUT_PP();	     
   }
  
   mmc_write_close();
   return OK;    
}

⌨️ 快捷键说明

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