|
|||||||||||
| 技術交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術 | 電源技術 | 測控之家 | EMC技術 | ARM技術 | EDA技術 | PCB技術 | 嵌入式系統(tǒng) 驅動編程 | 集成電路 | 器件替換 | 模擬技術 | 新手園地 | 單 片 機 | DSP技術 | MCU技術 | IC 設計 | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe |
請問各位大俠 這用的是哪中編譯器 |
| 作者:dudongdao 欄目:單片機 |
/*! \file mmc.c \brief MultiMedia and SD FLASH Card Interface. */ //***************************************************************************** // // File NAME : 'mmc.c' // Title : MultiMedia and SD FLASH Card Interface // Author : Pascal Stang - COPYRIGHT (C) 2004 // Created : 2004.09.22 // Revised : 2004.09.22 // Version : 0.1 // Target MCU : ATMEL AVR Series // Editor Tabs : 4 // // NOTE: This code is currently below version 1.0, and therefore is considered // to be lacking in some functionality or documentation, or may not be fully // tested. Nonetheless, you can expect most functions to work. // // This code is distributed under the GNU Public License // which can be found at http://www.gnu.org/licenses/gpl.txt // //***************************************************************************** //----- Include Files --------------------------------------------------------- #include <avr/io.h> // include I/O definitions (PORT names, pin names, etc) #include <avr/signal.h> // include "signal" names (interrupt names) #include <avr/interrupt.h> // include interrupt supPORT #include "GLOBAL.h" // include our GLOBAL settings #include "spi.h" // include spi bus supPORT #include "rprintf.h" #include "mmc.h" // include project-specific HARDWARE configuration #include "mmcconf.h" // GLOBAL variables // Functions void mmcInit(void) { // initialize SPI interface spiInit(); // release chip SELECT sbi(MMC_CS_DDR, MMC_CS_PIN); sbi(MMC_CS_PORT,MMC_CS_PIN); } u08 mmcReset(void) { u08 retry; u08 r1=0; retry = 0; do { // send DUMMY bytes with CS high before accessing spiTransferByte(0xFF); spiTransferByte(0xFF); spiTransferByte(0xFF); spiTransferByte(0xFF); // resetting card, go to SPI mode r1 = mmcSendCommand(MMC_GO_IDLE_STATE, 0); rprintf("MMC_GO_IDLE_STATE: R1=0x%x\r\n", r1); // do retry counter retry++; if(retry>10) return -1; } while(r1 != 0x01); // TODO: check card parameters for voltage compliance // before issuing initialize command retry = 0; do { // initializing card for operation r1 = mmcSendCommand(MMC_SEND_OP_COND, 0); rprintf("MMC_SEND_OP_COND: R1=0x%x\r\n", r1); // do retry counter retry++; if(retry>100) return -1; } while(r1); // turn off CRC checking to simplify communication r1 = mmcSendCommand(MMC_CRC_ON_OFF, 0); rprintf("MMC_CRC_ON_OFF: R1=0x%x\r\n", r1); // set block length to 512 bytes r1 = mmcSendCommand(MMC_SET_BLOCKLEN, 512); rprintf("MMC_SET_BLOCKLEN: R1=0x%x\r\n", r1); // return success return 0; } u08 mmcSendCommand(u08 cmd, u32 arg) { u08 r1; // assert chip SELECT cbi(MMC_CS_PORT,MMC_CS_PIN); // issue the command r1 = mmcCommand(cmd, arg); // release chip SELECT sbi(MMC_CS_PORT,MMC_CS_PIN); return r1; } u08 mmcRead(u32 sector, u08* buffer) { u08 r1; u16 i; // assert chip SELECT cbi(MMC_CS_PORT,MMC_CS_PIN); // issue command r1 = mmcCommand(MMC_READ_SINGLE_BLOCK, sector<<9); rprintf("MMC Read Block R1=0x%x\r\n", r1); // check for valid response if(r1 != 0x00) return r1; // wait for block start while(spiTransferByte(0xFF) != MMC_STARTBLOCK_READ); // read in data for(i=0; i<0x200; i++) { *buffer++ = spiTransferByte(0xFF); } // read 16-bit CRC spiTransferByte(0xFF); spiTransferByte(0xFF); // release chip SELECT sbi(MMC_CS_PORT,MMC_CS_PIN); // return success return 0; } u08 mmcWrite(u32 sector, u08* buffer) { u08 r1; u16 i; // assert chip SELECT cbi(MMC_CS_PORT,MMC_CS_PIN); // issue command r1 = mmcCommand(MMC_WRITE_BLOCK, sector<<9); rprintf("MMC Write Block R1=0x%x\r\n", r1); // check for valid response if(r1 != 0x00) return r1; // send DUMMY spiTransferByte(0xFF); // send data start token spiTransferByte(MMC_STARTBLOCK_WRITE); // write data for(i=0; i<0x200; i++) { spiTransferByte(*buffer++); } // write 16-bit CRC (DUMMY values) spiTransferByte(0xFF); spiTransferByte(0xFF); // read data response token r1 |
| 2樓: | >>參與討論 |
| 作者: hanyafeng 于 2006/3/9 11:23:00 發(fā)布:
不象ICCAVR |
|
| 3樓: | >>參與討論 |
| 作者: zsmbj 于 2006/3/10 9:01:00 發(fā)布:
一看就是winavr啦! |
|
| 4樓: | >>參與討論 |
| 作者: mxh0506 于 2006/3/10 12:30:00 發(fā)布:
從包含的頭文件上看是GCC |
|
| 5樓: | >>參與討論 |
| 作者: dudongdao 于 2006/3/10 16:35:00 發(fā)布:
請問這一句是什么意思呢 rprintf("MMC_GO_IDLE_STATE: R1=0x%x\r\n", r1); |
|
| 6樓: | >>參與討論 |
| 作者: computer00 于 2006/3/10 16:52:00 發(fā)布:
rprintf,一看就知道是個輸出語句。例如發(fā)送到串口什么的 |
|
|
|
| 免費注冊為維庫電子開發(fā)網(wǎng)會員,參與電子工程師社區(qū)討論,點此進入 |
Copyright © 1998-2006 www.hbjingang.com 浙ICP證030469號 |