在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            SD卡讀寫程序

            作者: 時(shí)間:2010-06-23 來源:網(wǎng)絡(luò) 收藏

            unsigned char sd_reset()
            {
            unsigned char i,tmp;
            unsigned char retry; //重復(fù)次數(shù)
            unsigned char r1=0;
            retry=0;
            delay();
            delay();
            do
            {
            for(i=0;i100;i++) SPI_WriteByte(0xff);

            r1 = _SendCommand(0,0);//發(fā)idle命令
            retry++;
            if(retry>20) return 1; //超時(shí)退出
            } while(r1 != 0x01); //等待IDLE命令返回

            本文引用地址:http://www.biyoush.com/article/151774.htm

            retry = 0;
            cs=0;
            do
            {
            for(i=0;i100;i++) SPI_WriteByte(0xff);

            r1 = _SendCommand(1, 0); //發(fā)Active命令
            retry++;
            if(retry>254) return 1; //超時(shí)退出
            } while(r1);

            for(i=0;i100;i++) SPI_WriteByte(0xff);

            r1 = _SendCommand(59, 0); //關(guān)crc
            if (r1) return 1; //返回不正確,退出初始化

            for(i=0;i100;i++) SPI_WriteByte(0xff);

            r1 = SD_SendCommand(16, 512); //設(shè)扇區(qū)大小512
            if(r1!=0) return 1; //返回不正確,退出初始化
            return 0; //正常返回
            }

            //********************寫一個(gè)扇區(qū)**************************
            unsigned char SD_WriteSingleBlock(unsigned long sector)
            {
            unsigned char r1;
            unsigned int i;
            unsigned char retry=0;
            do
            {
            for(i=0;i100;i++) SPI_WriteByte(0xff);

            r1 = SD_SendCommand(24, sector9);//寫命令
            retry++;
            if(retry>10) return 1; //超時(shí)退出
            } while(r1 != 0x00);

            cs=0;

            SPI_WriteByte(0xff);
            SPI_WriteByte(0xff);
            SPI_WriteByte(0xff);
            SPI_WriteByte(0xff);
            SPI_WriteByte(0xff);
            SPI_WriteByte(0xff);

            SPI_WriteByte(0xfe); //發(fā)開始符

            for(i=0; i512; i++) //送512字節(jié)數(shù)據(jù)
            {
            if(i255) SPI_WriteByte(i); //發(fā)送0--255
            else SPI_WriteByte(512-i); //發(fā)送255--0

            }

            SPI_WriteByte(0x95);
            SPI_WriteByte(0x95); //16-bits CRC

            r1 = SPI_WriteByte(0xff); //讀響應(yīng)位
            if(retry++ >10) return 1; //超時(shí)退出
            while(!((r10x0f)==5)); //等待數(shù)據(jù)成功接受返回信息
            while(!(SPI_WriteByte(0xff))); //等待SD卡內(nèi)部編程完成

            return 0;
            }

            //******************讀SD卡一個(gè)扇區(qū)************************
            unsigned char SD_ReadSingleBlock(unsigned long sector)
            {
            unsigned char r1,temp;
            unsigned int i,j;
            unsigned char retry=0;

            do
            {
            r1 = SD_SendCommand(17, sector9);//讀命令
            retry++;
            if(retry>10) return 1; //超時(shí)退出
            } while(r1 != 0x00);
            cs=0;
            while(SPI_WriteByte(0xff)!= 0xfe) //等待接收到開始字節(jié)
            {
            if(retry++ >100) return 1; //超時(shí)退出
            }
            for(i=0; i512; i++) //讀512個(gè)數(shù)據(jù)
            {
            temp = SPI_WriteByte(0xff); //讀取接收到的數(shù)據(jù)
            lcd[0]=(temp/100)+48;
            lcd[1]=((temp%100)/10)+48;
            lcd[2]=((temp%100)%10)+48;
            lcd_display(); //讀取數(shù)據(jù)送顯示
            for(j=0;j500;j++) {delay();}
            }

            SPI_WriteByte(0xff); //偽16-bits crc
            SPI_WriteByte(0xff);

            cs=1;

            return 0;
            }

            //***********************延時(shí)*************************
            void delay() //延時(shí)
            {
            int i; //定義整形變量
            for(i=0x100;i--;); //延時(shí)
            }

            //************************主函數(shù)**************************
            int main(void)
            {
            unsigned char loop,res;
            delay();
            delay();
            delay();
            loop=1;

            cs=1;
            while(loop)
            {
            spi_init(); //調(diào)用系統(tǒng)初始化函數(shù)
            res= sd_reset(); //調(diào)用SD卡初始化函數(shù)
            if(res) break; //SD卡初始化是否正常,不正常,退出循環(huán),不執(zhí)行下面的操作
            SD_WriteSingleBlock(1); //調(diào)用寫SD卡單BLOCK函數(shù),其中扇區(qū)號(hào)為1
            if(res) break;
            SD_ReadSingleBlock(1); //調(diào)用讀SD卡單BLOCK函數(shù),其中扇區(qū)號(hào)為1
            if(res) break;
            loop=0;
            while(1);
            }
            while(1);
            }


            上一頁 1 2 下一頁

            關(guān)鍵詞: 程序 讀寫 SD

            評(píng)論


            相關(guān)推薦

            技術(shù)專區(qū)

            關(guān)閉