亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? mmc.c

?? CS5532的驅動程序
?? C
字號:
/**************************************************************************************
//------------------ MMC/SD-Card Reading and Writing implementation -------------------
//FileName     : mmc.c
//Function     : Connect AVR to MMC/SD 
//Created by   : ZhengYanbo
//Created date : 15/08/2005
//Version      : V1.2
//Last Modified: 19/08/2005
//Filesystem   : Read or Write MMC without any filesystem

//CopyRight (c) 2005 ZhengYanbo
//Email: Datazyb_007@163.com
****************************************************************************************/



#include <iom8v.h>
#include <macros.h>

#include "DEFINE.H"
#include "DELAY.H"
#include "mmc.h"

typedef struct MMC_VOLUME_INFO
{ //MMC/SD Card info
	uint16   size_MB;
	uint08   sector_multiply;
	uint16   sector_count;
	uint08   name[6];
} VOLUME_INFO_TYPE; 

/*
typedef struct STORE 
{ 
  uint08   data[256]; 
} BUFFER_TYPE; //256 bytes, 128 words
*/
//BUFFER_TYPE sectorBuffer; //512 bytes for sector buffer

//--------------------------------------------------------------
uint16	readPos=0;
uint08	sectorPos=0;
uint08    LBA_Opened=0; //Set to 1 when a sector is opened.
uint08    Init_Flag;    //Set it to 1 when Init is processing.


#if USE_MMC
//****************************************************************************
// Port Init
void MMC_Port_Init(void)
//****************************************************************************
{
 	CLR_BIT(PORTB,PB4);
	SET_BIT(DDRB,PB3);
	SET_BIT(DDRB,PB5);
	CLR_BIT(DDRB,PB4);
	SET_BIT(DDRB,PB1);
	SET_BIT(PORTB,PB1);
}

//****************************************************************************
//Routine for Init MMC/SD card(SPI-MODE)
unsigned char MMC_Init(void)
//****************************************************************************
{  
   unsigned char retry,temp;
   unsigned char i;
   unsigned char CMD[] = {0x40,0x00,0x00,0x00,0x00,0x95};
   
   MMC_Port_Init(); 	//Init SPI port  

   for(i=0;i<200;i++) //Wait MMC/SD ready...
   {
      NOP();
   }
   
   Init_Flag=1; //Set the init flag

   for (i=0;i<0x0f;i++) 
   {
      Write_Byte_MMC(0xff); //send 74 clock at least!!!
   }
	
   //Send Command CMD0 to MMC/SD Card
   retry=0;
   do
   { //retry 200 times to send CMD0 command 
     temp=Write_Command_MMC(CMD);
     retry++;
     if(retry==200) 
     { //time out
       return(INIT_CMD0_ERROR);//CMD0 Error!
     }
   } 
   while(temp!=1);
   
   //Send Command CMD1 to MMC/SD-Card
   CMD[0] = 0x41; //Command 1
   CMD[5] = 0xFF;
   retry=0;
   do
   { //retry 100 times to send CMD1 command 
     temp=Write_Command_MMC(CMD);
     retry++;
     if(retry==100) 
     { //time out
       return(INIT_CMD1_ERROR);//CMD1 Error!
     }
   } 
   while(temp!=0);
   
   Init_Flag=0; //Init is completed,clear the flag 
   
   MMC_Disable();  //set MMC_Chip_Select to high 
   return(0); //All commands have been taken.
} 

//****************************************************************************
//returns the :
// 	size of the card in MB ( ret * 1024^2) == bytes
// 	sector count and multiplier MB are in u08 == C_SIZE / (2^(9-C_SIZE_MULT))
// 	name of the media 
/*void MMC_get_volume_info(void)
//****************************************************************************
{   unsigned char i;
    VOLUME_INFO_TYPE MMC_volume_Info,*vinf;
    
    vinf=&MMC_volume_Info; //Init the pointoer;
	// read the CSD register
    Read_CSD_MMC(sectorBuffer.data);
	// get the C_SIZE value. bits [73:62] of data
	// [73:72] == sectorBuffer.data[6] && 0x03
	// [71:64] == sectorBuffer.data[7]
	// [63:62] == sectorBuffer.data[8] && 0xc0
	vinf->sector_count = sectorBuffer.data[6] & 0x03;
	vinf->sector_count <<= 8;
	vinf->sector_count += sectorBuffer.data[7];
	vinf->sector_count <<= 2;
	vinf->sector_count += (sectorBuffer.data[8] & 0xc0) >> 6;
		
	// get the val for C_SIZE_MULT. bits [49:47] of sectorBuffer.data
	// [49:48] == sectorBuffer.data[5] && 0x03
	// [47]    == sectorBuffer.data[4] && 0x80
	vinf->sector_multiply = sectorBuffer.data[9] & 0x03;
	vinf->sector_multiply <<= 1;
	vinf->sector_multiply += (sectorBuffer.data[10] & 0x80) >> 7;

	// work out the MBs
	// mega bytes in u08 == C_SIZE / (2^(9-C_SIZE_MULT))
	vinf->size_MB = vinf->sector_count >> (9-vinf->sector_multiply);
	// get the name of the card
	Read_CID_MMC(sectorBuffer.data);
	vinf->name[0] = sectorBuffer.data[3];
	vinf->name[1] = sectorBuffer.data[4];
	vinf->name[2] = sectorBuffer.data[5];
	vinf->name[3] = sectorBuffer.data[6];
	vinf->name[4] = sectorBuffer.data[7];
	vinf->name[5] = 0x00; //end flag
	//----------------------------------------------------------
    LCDclrscr();
    //Print Product name on lcd
    i=0;
    writestring("Product:");
    while((vinf->name[i]!=0x00)&&(i<16)) writechar(vinf->name[i++]);
    //Print Card Size(eg:128MB)
    gotoxy(1,0);
    writestring("Tot:"); 
    writeNumber(vinf->size_MB); writestring("MB ");
    //gotoxy(2,0);
    //writestring("sector_mult:"); writeNumber(vinf->sector_multiply);
    //gotoxy(3,0);
    //writestring("sect_cnt:"); writeNumber(vinf->sector_count);
	
}
*/
//****************************************************************************
//Send a Command to MMC/SD-Card
//Return: the second byte of response register of MMC/SD-Card
unsigned char Write_Command_MMC(unsigned char *CMD)
//****************************************************************************
{
   unsigned char tmp;
   unsigned char retry=0;
   unsigned char i;

   //set MMC_Chip_Select to high (MMC/SD-Card disable) 
   MMC_Disable();
   //send 8 Clock Impulse
   Write_Byte_MMC(0xFF);
   //set MMC_Chip_Select to low (MMC/SD-Card active)
   MMC_Enable();

   //send 6 Byte Command to MMC/SD-Card
   for (i=0;i<0x06;i++) 
   { 
      Write_Byte_MMC(*CMD++);
   }
   
   //get 16 bit response
   Read_Byte_MMC(); //read the first byte,ignore it. 
   do 
   {  //Only last 8 bit is used here.Read it out. 
      tmp = Read_Byte_MMC();
      retry++;
   }
   while((tmp==0xff)&&(retry<100)); 
   return(tmp);
}

//****************************************************************************
//Routine for reading a byte from MMC/SD-Card
unsigned char Read_Byte_MMC(void)
//****************************************************************************
{ 
   uint08 ret_val=0;
	uint08 i;
	
	for(i=0;i<8;i++)
	{
		CLR_SCK();
		if(Init_Flag)
		us_delay(20);
		NOP();
		ret_val<<=1;
		if(PIN_MISO)ret_val|=0x01;
		SET_SCK();
		if(Init_Flag)
		us_delay(20);
		NOP();
	}
	return(ret_val);
}

//****************************************************************************
//Routine for sending a byte to MMC/SD-Card
void Write_Byte_MMC(unsigned char value)
//****************************************************************************
{ 
  	uint08 i;
	for(i=0;i<8;i++)
	{
		if(value&0x80)
		SET_MOSI();
		else
		CLR_MOSI();
		value<<=1;
		CLR_SCK();
		if(Init_Flag)
		us_delay(20);
		NOP();
		SET_SCK();
		if(Init_Flag)
		us_delay(20);
		NOP();
	}
	SET_MOSI();
}

//****************************************************************************
//Routine for writing a Block(512Byte) to MMC/SD-Card
//Return 0 if sector writing is completed.
unsigned char MMC_write_sector(unsigned long addr,unsigned char *Buffer)
//****************************************************************************
{  
   unsigned char tmp,retry;
   unsigned int i;
   //Command 24 is a writing blocks command for MMC/SD-Card.
   unsigned char CMD[] = {0x58,0x00,0x00,0x00,0x00,0xFF}; 
   
   CLI(); //clear all interrupt.
   addr = addr << 9; //addr = addr * 512
	
   CMD[1] = ((addr & 0xFF000000) >>24 );
   CMD[2] = ((addr & 0x00FF0000) >>16 );
   CMD[3] = ((addr & 0x0000FF00) >>8 );

   //Send Command CMD24 to MMC/SD-Card (Write 1 Block/512 Bytes)
   retry=0;
   do
   {  //Retry 100 times to send command.
      tmp=Write_Command_MMC(CMD);
      retry++;
      if(retry==100) 
      { 
        return(tmp); //send commamd Error!
      }
   }
   while(tmp!=0); 
   
   //Before writing,send 100 clock to MMC/SD-Card
   for (i=0;i<100;i++)
   {
      Read_Byte_MMC();
   }
	
   //Send Start Byte to MMC/SD-Card
   Write_Byte_MMC(0xFE);	
	
   //Now send real data Bolck (512Bytes) to MMC/SD-Card
   for (i=0;i<512;i++)
   {
      Write_Byte_MMC(*Buffer++); //send 512 bytes to Card
   }

   //CRC-Byte 
   Write_Byte_MMC(0xFF); //Dummy CRC
   Write_Byte_MMC(0xFF); //CRC Code
   
    
   tmp=Read_Byte_MMC();   // read response
   if((tmp & 0x1F)!=0x05) // data block accepted ?
   {
     MMC_Disable();
     return(WRITE_BLOCK_ERROR); //Error!
   }
   //Wait till MMC/SD-Card is not busy
   while (Read_Byte_MMC()!=0xff){};
	
   //set MMC_Chip_Select to high (MMC/SD-Card Invalid)
   MMC_Disable();
   return(0);
} 

//****************************************************************************
//Routine for reading data Registers of MMC/SD-Card
//Return 0 if no Error.
unsigned char MMC_Read_Block(unsigned char *CMD,unsigned char *Buffer,unsigned int Bytes)
//****************************************************************************
{  
   unsigned int i; unsigned retry,temp;
    
   //Send Command CMD to MMC/SD-Card
   retry=0;
   do
   {  //Retry 100 times to send command.
      temp=Write_Command_MMC(CMD);
      retry++;
      if(retry==100) 
      {
        return(READ_BLOCK_ERROR); //block write Error!
      }
   }
   while(temp!=0); 
   			
   //Read Start Byte form MMC/SD-Card (FEh/Start Byte)
   while (Read_Byte_MMC() != 0xfe){};
	
   //Write blocks(normal 512Bytes) to MMC/SD-Card
   for (i=0;i<Bytes;i++)
   {
      *Buffer++ = Read_Byte_MMC();
   }
   
   //CRC-Byte
   Read_Byte_MMC();//CRC - Byte 
   Read_Byte_MMC();//CRC - Byte
	
   //set MMC_Chip_Select to high (MMC/SD-Card invalid)
   MMC_Disable();
   return(0);
}

/*
//****************************************************************************
//Routine for reading Blocks(512Byte) from MMC/SD-Card
//Return 0 if no Error.
unsigned char MMC_read_sector(unsigned long addr,unsigned char *Buffer)
//****************************************************************************
{	
   //Command 16 is reading Blocks from MMC/SD-Card
   unsigned char CMD[] = {0x51,0x00,0x00,0x00,0x00,0xFF}; 
   unsigned char temp;
   
   #asm("cli"); //clear all interrupt.
   //Address conversation(logic block address-->byte address)  
   addr = addr << 9; //addr = addr * 512

   CMD[1] = ((addr & 0xFF000000) >>24 );
   CMD[2] = ((addr & 0x00FF0000) >>16 );
   CMD[3] = ((addr & 0x0000FF00) >>8 );

   temp=MMC_Read_Block(CMD,Buffer,512);
   
   return(temp);
} */

//***************************************************************************
//Routine for reading CID Registers from MMC/SD-Card (16Bytes) 
//Return 0 if no Error.
unsigned char Read_CID_MMC(unsigned char *Buffer)
//***************************************************************************
{
   //Command for reading CID Registers
   unsigned char CMD[] = {0x4A,0x00,0x00,0x00,0x00,0xFF}; 
   unsigned char temp;
   temp=MMC_Read_Block(CMD,Buffer,16); //read 16 bytes

   return(temp);
}

//***************************************************************************
//Routine for reading CSD Registers from MMC/SD-Card (16Bytes)
//Return 0 if no Error.
unsigned char Read_CSD_MMC(unsigned char *Buffer)
//***************************************************************************
{	
   //Command for reading CSD Registers
   unsigned char CMD[] = {0x49,0x00,0x00,0x00,0x00,0xFF};
   unsigned char temp;
   temp=MMC_Read_Block(CMD,Buffer,16); //read 16 bytes

   return(temp);
}

//***************************************************************************
//Return: [0]-success or something error!
unsigned char MMC_Start_Read_Sector(unsigned long sector)
//***************************************************************************
{  
   unsigned char retry;
   //Command 16 is reading Blocks from MMC/SD-Card
   unsigned char CMD[] = {0x51,0x00,0x00,0x00,0x00,0xFF}; 
   unsigned char temp;
   
   CLI(); //clear all interrupt.
   //Address conversation(logic block address-->byte address)  
   sector = sector << 9; //sector = sector * 512

   CMD[1] = ((sector & 0xFF000000) >>24 );
   CMD[2] = ((sector & 0x00FF0000) >>16 );
   CMD[3] = ((sector & 0x0000FF00) >>8 );
   //Send Command CMD to MMC/SD-Card
   retry=0;
   do
   {  //Retry 100 times to send command.
      temp=Write_Command_MMC(CMD);
      retry++;
      if(retry==100) 
      {
        return(READ_BLOCK_ERROR); //block write Error!
      }
   }
   while(temp!=0); 
   			
   //Read Start Byte form MMC/SD-Card (FEh/Start Byte)
   //Now data is ready,you can read it out.
   while (Read_Byte_MMC() != 0xfe){};
   return 0; //Open a sector successfully!
}

//***************************************************************************
void MMC_get_data(unsigned int Bytes,unsigned char *buffer) 
//***************************************************************************
{
   unsigned int j;
   
  CLI(); //clear all interrupt.
   for (j=0;((j<Bytes) && (readPos<512));j++)
   {	
      *buffer++ = Read_Byte_MMC();
      readPos++; //read a byte,increase read position
   }
   if (readPos==512)  
   {  //CRC-Bytes
      Read_Byte_MMC();//CRC - Byte 
      Read_Byte_MMC();//CRC - Byte
      readPos=0;      //reset sector read offset 
      sectorPos++;    //Need to read next sector
      LBA_Opened=0;   //Set to 1 when a sector is opened.
      //set MMC_Chip_Select to high (MMC/SD-Card invalid)
      MMC_Disable();  //MMC disable
   }
}

//***************************************************************************
void MMC_get_data_LBA(unsigned long lba, unsigned int Bytes,unsigned char *buffer)
//***************************************************************************
{ //get data from lba address of MMC/SD-Card
  //If a new sector has to be read then move head
  if (readPos==0) MMC_Start_Read_Sector(lba); 
  MMC_get_data(Bytes,buffer);
  SEI();	
}

//***************************************************************************
void MMC_GotoSectorOffset(unsigned long LBA,unsigned int offset)
//***************************************************************************
{  
   //Find the offset in the sector
   unsigned char temp[1];
   MMC_LBA_Close(); //close MMC when read a new sector(readPos=0)
   while (readPos<offset) MMC_get_data_LBA(LBA,1,temp); //go to offset  
}

//***************************************************************************
void MMC_LBA_Close()
//***************************************************************************
{  
   unsigned char temp[1];
   while((readPos!=0x00)|(LBA_Opened==1))
   { //read MMC till readPos==0x00
     MMC_get_data(1, temp); //dummy read,temp is a valid data.
   }  
}

//---------------------------------------------------------------------------- 
#endif //USE_MMC

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99v久久综合狠狠综合久久| 久久久久久久久久久久电影 | 日韩三级视频在线观看| 日韩精品一区二区三区蜜臀| 亚洲一区在线视频| 欧洲视频一区二区| 怡红院av一区二区三区| 91美女视频网站| 亚洲男女毛片无遮挡| 久草中文综合在线| 欧美一级一区二区| 九九九久久久精品| 久久―日本道色综合久久| 久久99精品国产.久久久久久| 欧美一区二区在线视频| 久久不见久久见中文字幕免费| 日韩亚洲欧美一区二区三区| 青草av.久久免费一区| 精品av久久707| 高清久久久久久| 亚洲免费在线观看视频| 欧美日韩情趣电影| 蜜桃av一区二区| 国产喷白浆一区二区三区| 成人av午夜电影| 亚洲精品久久嫩草网站秘色| 欧美久久久久久蜜桃| 久久国产精品99精品国产| 久久久久久久久岛国免费| 91啪在线观看| 日韩高清在线电影| 国产色产综合色产在线视频| a美女胸又www黄视频久久| 亚洲精品一二三区| 91精品国产色综合久久久蜜香臀| 丝袜亚洲另类欧美| 久久久高清一区二区三区| 91网站在线播放| 日本亚洲三级在线| 国产精品视频九色porn| 欧美自拍偷拍一区| 9191精品国产综合久久久久久| 国产午夜精品一区二区三区视频| 亚洲成人一区二区| 国产尤物一区二区在线| 色综合久久精品| 久久久久国产精品麻豆ai换脸| 亚洲美女区一区| 成人一区二区三区在线观看| 欧美一区二区三区四区在线观看| 夜色激情一区二区| 成人性生交大片免费看在线播放| 精品国产sm最大网站免费看| 欧美中文字幕亚洲一区二区va在线| 日本美女一区二区| 亚洲视频一区在线观看| 日韩免费观看高清完整版| 美女在线视频一区| 亚洲人精品一区| 久久综合给合久久狠狠狠97色69| 91蜜桃传媒精品久久久一区二区| 久久er精品视频| 一区二区在线观看视频| 中文字幕+乱码+中文字幕一区| 69堂成人精品免费视频| 色94色欧美sute亚洲线路二| 国产在线不卡一卡二卡三卡四卡| 一区二区三区在线免费| 中文字幕欧美激情| av一本久道久久综合久久鬼色| 免费成人小视频| 亚洲一区二区三区精品在线| 国产精品女主播av| 欧美草草影院在线视频| 欧美美女直播网站| 色噜噜狠狠成人网p站| 国产91高潮流白浆在线麻豆| 精品一区二区三区在线视频| 五月天精品一区二区三区| 麻豆久久一区二区| 日韩精彩视频在线观看| 亚洲一区二区三区爽爽爽爽爽| 亚洲日本在线看| 国产精品三级av| 国产亚洲一区二区在线观看| 精品国产免费一区二区三区四区| 欧美一区三区四区| 欧美一区二区三区视频免费播放| 欧美亚洲丝袜传媒另类| 色哟哟国产精品| 国产a区久久久| 丰满亚洲少妇av| 国产成人小视频| 国产成人精品亚洲日本在线桃色| 精品午夜久久福利影院| 精品在线一区二区| 国产乱妇无码大片在线观看| 国产激情91久久精品导航| 国产一区二区在线看| 国产专区综合网| 粉嫩av一区二区三区粉嫩 | 99久久综合99久久综合网站| 不卡av在线免费观看| 福利一区福利二区| 99久久99久久精品免费观看 | 亚洲国产精品久久人人爱| 亚洲综合色网站| 亚洲夂夂婷婷色拍ww47| 亚洲欧美另类综合偷拍| 一区二区日韩电影| 石原莉奈在线亚洲三区| 人人狠狠综合久久亚洲| 国产一区二区三区香蕉| 国产一区二区在线影院| 成人av在线播放网站| 日本道色综合久久| 日韩视频永久免费| 国产日韩欧美一区二区三区乱码| 国产精品久久久久久久蜜臀 | 国产一区二区在线免费观看| 白白色 亚洲乱淫| 欧美色图免费看| 精品粉嫩超白一线天av| 国产精品福利一区| 亚洲午夜在线观看视频在线| 久久av中文字幕片| av毛片久久久久**hd| 欧美视频在线观看一区| 欧美精品一区二区在线播放| 国产三区在线成人av| 一区二区三区丝袜| 极品少妇一区二区三区精品视频| 成人精品一区二区三区四区| 欧美日韩二区三区| 国产亚洲精久久久久久| 亚洲国产成人av网| 国产自产视频一区二区三区| 91久久精品国产91性色tv| xf在线a精品一区二区视频网站| 久久久国产综合精品女国产盗摄| 国产午夜精品在线观看| 午夜精品久久久久久久99水蜜桃 | 久草热8精品视频在线观看| 国产成人av电影在线| 欧美二区三区91| 久久久久久9999| 亚洲人成网站色在线观看 | 亚洲欧美一区二区三区极速播放| 日韩制服丝袜av| 91原创在线视频| 国产婷婷色一区二区三区| 亚洲大片一区二区三区| 成人黄色免费短视频| 日韩欧美在线观看一区二区三区| 亚洲美女淫视频| 国模少妇一区二区三区| 欧美三级蜜桃2在线观看| 1024国产精品| 91在线精品一区二区三区| 中文字幕av一区二区三区免费看 | 91麻豆精品国产自产在线| 亚洲综合色区另类av| 欧洲av在线精品| 一二三区精品视频| 日本韩国精品一区二区在线观看| 亚洲另类在线一区| 91国偷自产一区二区开放时间| 中文字幕日韩一区| av电影在线不卡| 亚洲视频免费在线观看| 色婷婷久久久亚洲一区二区三区| 亚洲欧美另类久久久精品| 91福利视频久久久久| 午夜欧美一区二区三区在线播放| 欧美三级日韩三级| 免费人成在线不卡| 精品电影一区二区三区| 国产成人综合网站| 亚洲欧洲日韩女同| 欧美综合一区二区| 全部av―极品视觉盛宴亚洲| 欧美成人一区二区三区片免费| 国内精品伊人久久久久av影院| 久久免费国产精品| 99精品欧美一区二区三区小说| 亚洲在线观看免费视频| 欧美丰满高潮xxxx喷水动漫| 国产一区二区电影| 国产精品不卡一区二区三区| 在线观看亚洲精品视频| 美美哒免费高清在线观看视频一区二区| 日韩精品一区二区三区视频在线观看| 国产精品99久久久久久宅男| 亚洲视频免费观看| 欧美一区二区日韩| 国产成人av电影在线播放| 亚洲午夜激情网站| 久久综合中文字幕| 色呦呦国产精品| 国产真实乱子伦精品视频|