日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀] /************************************************************//*SDCodeforM32L*//*Bypasyong*//*2006-4*//*BaseICC6.31A*//************************************************************/#includ

/************************************************************/
/*SDCodeforM32L*/

/*Bypasyong*/
/*2006-4*/
/*BaseICC6.31A*/
/************************************************************/
#include
#include
#include"1011.h"
#defineucharunsignedchar
#defineuintunsignedint
#defineMMC_CS_PINBIT(4)//PORTB.4
#defineMMC_PORTPORTB

ucharreading=0,a=0,pointer=0;
voidsd_port_init()
{
MMC_PORT|=MMC_CS_PIN;
}
ucharBUFFER[512];//扇區(qū)緩沖區(qū)
uinti=0;
voiddelay_nus(uintn)
{
unsignedcharb;
for(b=1;b;
}
//****************************************************************************
//SendaCommandtoMMC/SD-Card
//Return:thesecondbyteofresponseregisterofMMC/SD-Card
//****************************************************************************
ucharSD_Write_Command(ucharcmd,unsignedlongarg)
{
uchartmp;
ucharretry=0;

//MMC_PORT|=MMC_CS_PIN;//SD卡關(guān)閉
//send8CLOCkImpulse
Write_Byte_SPI(0xFF);

//setMMC_Chip_Selecttolow(MMC/SD-Cardactive)
MMC_PORT&=~MMC_CS_PIN;//SD卡使能

Write_Byte_SPI(cmd|0x40);//送頭命令
Write_Byte_SPI(arg>>24);
Write_Byte_SPI(arg>>16);//send6ByteCommandtoMMC/SD-Card
Write_Byte_SPI(arg>>8);
Write_Byte_SPI(arg&0xff);
Write_Byte_SPI(0x95);//僅僅對RESET有效的CRC效驗(yàn)碼

//get8bitresponse
//Read_Byte_MMC();//readthefirstbyte,ignoreit.
do
{//Onlylast8bitisusedhere.Readitout.
tmp=Read_Byte_SPI();
retry++;
}
while((tmp==0xff)&&(retry<100));//當(dāng)沒有收到有效的命令的時(shí)候

if(reading==0)
MMC_PORT|=MMC_CS_PIN;//MMC_CS_PIN=1;
elseMMC_PORT&=~MMC_CS_PIN;//MMC_CS_PIN=0;
return(tmp);
}
//****************************************************************************
//SD卡初始化(SPI-MODE)
//****************************************************************************
ucharSD_Init(void)
{
ucharretry,temp;
uchari;
MMC_PORT&=~MMC_CS_PIN;//SD卡使能

delay_nus(250);//WaitMMC/SDready...
for(i=0;i<0x0f;i++)
{
Write_Byte_SPI(0xff);//send74clockatleast!!!
}
//SendCommandCMD0toMMC/SDCard
retry=0;

do
{//retry200timestosendCMD0command
temp=SD_Write_Command(0,0);
retry++;
if(retry==100)
{
;//CMD0Error!
}
}
while(temp!=1);

//SendCommandCMD1toMMC/SD-Card
retry=0;
do
{//retry100timestosendCMD1command
temp=SD_Write_Command(1,0);
retry++;
if(retry==100)
{
;
}
}
while(temp!=0);
retry=0;
SD_Write_Command(16,512);//設(shè)置一次讀寫B(tài)LOCK的長度為512個(gè)字節(jié)

MMC_PORT|=MMC_CS_PIN;//MMC_CS_PIN=1;//setMMC_Chip_Selecttohigh
return(0);//Allcommandshavebeentaken.
}
//****************************************************************************
//從SD卡讀一個(gè)扇區(qū)Return0ifnoError.
//****************************************************************************
ucharSD_Read_Block(unsignedlongaddress)
{
uchartemp=0;uinti=0;
reading=1;
temp=SD_Write_Command(17,address);//讀出RESPONSE
while(Read_Byte_SPI()!=0xfe)
{;}//直到讀取到了數(shù)據(jù)的開始頭0XFE,才繼續(xù)
for(i=0;i<512;i++)
{
BUFFER[i]=Read_Byte_SPI();
}
Read_Byte_SPI();//CRC-Byte
Read_Byte_SPI();//CRC-Byte
reading=0;
MMC_PORT|=MMC_CS_PIN;//關(guān)閉SD卡
return(temp);
}


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉