회원가입 ID/PW 찾기

1) 지식 창고는 본인이 작성한 콘텐츠(팁/노하우/리소스/강좌 등)을 무료 혹은 가상화폐인 납포인트를 통해 공유하는 공간입니다.
2) 본인이 작성한 콘텐츠에 대해서만 지식 창고에 등록할 수 있으며, 저작권에 위배되는 콘텐츠는 사전경고 없이 삭제될 수 있습니다.
3) 콘텐츠 구매 및 첨부파일 다운로드는 회원그룹 '연구원' 이상 가능하오니, 경험치를 쌓아 진급한 후에 이용 부탁드립니다.
4) 무료 콘텐츠의 본문은 구매절차 없이 즉시 이용할 수 있으며, 판매 납포인트가 있는 콘텐츠는 구매 후 이용할 수 있습니다.
5) 콘텐츠 판매에 따른 납포인트 수익은 지정한 비율(50%)에 따라 판매자에게 지급하며, 납포인트 수익을 통해 진급을 빨리할 수 있습니다.
6) 구매 후 평가를 하면 구매 납포인트의 20%를 돌려 드립니다.

콘텐츠 수 33
판매자 아크마스터 판매 납포인트 무료 평점 0점 / 총 0명 참여

 MMC card, CCS-C컴파일러용 소스

For applications where more storage is required I would definately reccomend MultiMediaCards (some times called SanDisk (SD) flash). The built in SPI interface only requires four data lines and they are available in sizes of up to 256MByte (at the moment). There are a few little quirks in making the cards work with a PIC but these are hopefully all sorted out within the code. The code is set to use the hardware SPI pins on the 16F876 and I haven't tried it any other way.


The MMC card has quite a large block size for writing, I think at the moment it is at least 512Bytes although I think I saw something about a new version of the specifcation that is more flexible. But at the moment this means that you need to buffer 512Bytes and write them all in one go, the eeprom code (above) is ideal for this. The write_block function just writes the lowest 512Bytes from the eeprom to the MMC. The same is true when reading the card and in my current application I only need to read the data to a PC so the read_block function just outputs every byte to RS232 although it wouldn't be hard to insert some processing or pass each byte to whatever function you wanted. This is just the functions you need to get some code working and then drop these in.

출처 : http://www.microchipc.com/sourcecode/

mmc_circuit.gif

 // Written by Ed Waugh 2004, www.edwaugh.co.uk
// for the original source, and hundreds more examples of PIC C code, see:
// http://www.microchipc.com/sourcecode/#mmc
int mmc_init();
int mmc_response(unsigned char response);
int mmc_read_block(unsigned long block_number);
int mmc_write_block(unsigned long block_number);
int mmc_get_status();
/************************** MMC Init **************************************/
/* Initialises the MMC into SPI mode and sets block size, returns 0 on success */
int mmc_init()
{
int i;
SETUP_SPI(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_4 | SPI_SS_DISABLED);
*0x94 |= 0x40;                          // set CKE = 1 - clock idle low
*0x14 &= 0xEF;                          // set CKP = 0 - data valid on rising edge
OUTPUT_HIGH(PIN_C2);                    // set SS = 1 (off)
for(i=0;i<10;i++)                       // initialise the MMC card into SPI mode by sending clks on
{
        SPI_WRITE(0xFF);
}
OUTPUT_LOW(PIN_C2);                     // set SS = 0 (on) tells card to go to spi mode when it receives reset
SPI_WRITE(0x40);                        // send reset command
SPI_WRITE(0x00);                        // all the arguments are 0x00 for the reset command
SPI_WRITE(0x00);
SPI_WRITE(0x00);
SPI_WRITE(0x00);
SPI_WRITE(0x95);                        // precalculated checksum as we are still in MMC mode
puts("Sent go to SPI\n\r");
if(mmc_response(0x01)==1) return 1;     // if = 1 then there was a timeout waiting for 0x01 from the mmc
puts("Got response from MMC\n\r");
i = 0;
while((i < 255) && (mmc_response(0x00)==1))     // must keep sending command if response
{
        SPI_WRITE(0x41);                // send mmc command one to bring out of idle state
        SPI_WRITE(0x00);                // all the arguments are 0x00 for command one
        SPI_WRITE(0x00);
        SPI_WRITE(0x00);
        SPI_WRITE(0x00);
        SPI_WRITE(0xFF);                // checksum is no longer required but we always send 0xFF
        i++;
}
if(i >= 254) return 1;                   // if >= 254 then there was a timeout waiting for 0x00 from the mmc
puts("Got out of idle response from MMC\n\r");
OUTPUT_HIGH(PIN_C2);                    // set SS = 1 (off)
SPI_WRITE(0xFF);                        // extra clocks to allow mmc to finish off what it is doing
OUTPUT_LOW(PIN_C2);                     // set SS = 0 (on)
        SPI_WRITE(0x50);                // send mmc command one to bring out of idle state
        SPI_WRITE(0x00);
        SPI_WRITE(0x00);
        SPI_WRITE(0x02);                // high block length bits - 512 bytes
        SPI_WRITE(0x00);                // low block length bits
        SPI_WRITE(0xFF);                // checksum is no longer required but we always send 0xFF
if((mmc_response(0x00))==1) return 1;
OUTPUT_HIGH(PIN_C2);            // set SS = 1 (off)
puts("Got set block length response from MMC\n\r");
return 0;
}
/************************** MMC Get Status **************************************/
/* Get the status register of the MMC, for debugging purposes */
int mmc_get_status()
{
OUTPUT_LOW(PIN_C2);                     // set SS = 0 (on)
        SPI_WRITE(0x58);                // send mmc command one to bring out of idle state
        SPI_WRITE(0x00);
        SPI_WRITE(0x00);
        SPI_WRITE(0x00);                //
        SPI_WRITE(0x00);                // always zero as mulitples of 512
        SPI_WRITE(0xFF);                // checksum is no longer required but we always send 0xFF
OUTPUT_HIGH(PIN_C2);                    // set SS = 1 (off)
return 0;
}
/************************** MMC Write Block **************************************/
int mmc_write_block(unsigned long block_number)
{
unsigned long i;
unsigned long varh,varl;
varl=((block_number&0x003F)<<9);
varh=((block_number&0xFFC0)>>7);
puts("Write block\n\r");                // block size has been set in mmc_init()
OUTPUT_LOW(PIN_C2);                     // set SS = 0 (on)
        SPI_WRITE(0x58);                // send mmc write block
        SPI_WRITE(HIGH(varh));
        SPI_WRITE(LOW(varh));
        SPI_WRITE(HIGH(varl));
        SPI_WRITE(0x00);                // always zero as mulitples of 512
        SPI_WRITE(0xFF);                // checksum is no longer required but we always send 0xFF
if((mmc_response(0x00))==1) return 1;
puts("Got response to write block\n\r");
SPI_WRITE(0xFE);                        // send data token
for(i=0;i<512;i++)
{
SPI_WRITE(i2c_eeprom_read(HIGH(i),LOW(i)));     // send data
}
SPI_WRITE(0xFF);                        // dummy CRC
SPI_WRITE(0xFF);
if((SPI_READ(0xFF)&0x0F)!=0x05) return 1;
puts("Got data response to write block\n\r");
OUTPUT_HIGH(PIN_C2);                    // set SS = 1 (off)
return 0;
}
/************************** MMC Read Block **************************************/
/**** Reads a 512 Byte block from the MMC and outputs each byte to RS232 ****/
int mmc_read_block(unsigned long block_number)
{
unsigned long i;
unsigned long varh,varl;
varl=((block_number&0x003F)<<9);
varh=((block_number&0xFFC0)>>7);
OUTPUT_LOW(PIN_C2);                     // set SS = 0 (on)
        SPI_WRITE(0x51);                // send mmc read single block command
        SPI_WRITE(HIGH(varh));      // arguments are address
        SPI_WRITE(LOW(varh));
        SPI_WRITE(HIGH(varl));
        SPI_WRITE(0x00);
        SPI_WRITE(0xFF);                // checksum is no longer required but we always send 0xFF
if((mmc_response(0x00))==1) return 1;   // if mmc_response returns 1 then we failed to get a 0x00 response (affirmative)
puts("Got response to read block command\n\r");
if((mmc_response(0xFE))==1) return 1;   // wait for data token
puts("Got data token\n\r");
        for(i=0;i<512;i++)
        {
                putc(SPI_READ(0xFF));               // we should now receive 512 bytes
        }
SPI_READ(0xFF);                 // CRC bytes that are not needed
SPI_READ(0xFF);
OUTPUT_HIGH(PIN_C2);            // set SS = 1 (off)
SPI_WRITE(0xFF);                // give mmc the clocks it needs to finish off
puts("\n\rEnd of read block\n\r");
return 0;
}
/************************** MMC get response **************************************/
/**** Repeatedly reads the MMC until we get the response we want or timeout ****/
int mmc_response(unsigned char response)
{
        unsigned long count = 0xFFFF;           // 16bit repeat, it may be possible to shrink this to 8 bit but there is not much point
        while(SPI_READ(0xFF) != response && --count > 0);
        if(count==0) return 1;                  // loop was exited due to timeout
        else return 0;                          // loop was exited before timeout
}



profile
올드뉴 2012.05.29 14:40
감사합니다.
profile
hideman 2012.09.12 14:12
좋은 자료 감사합니다.
profile
시나브로69 2016.07.16 16:05

좋은 자료 감사합니다.

search
List of Articles
번호 분류 제목 평점 포인트 판매자 등록일 구매수 조회 수
공지 공공의 목적으로 공유하고자 하는 소프트웨어는 '소프트웨어 자료실'에 업로드를 요청드립니다.
공지 구매후 평점 댓글을 남겨주시면 구매포인트의 20%를 돌려드립니다.
33 Software & IDEs fortran에서 수치해석 라이브러리 IMSL사용하기 [3] 무료 도시인 2014-03-04 0 215
32 Software & IDEs C# - GPS 예제 [4] 무료 달리는거북이 2010-12-03 0 3642
31 Software & IDEs 저는 학원에서 패스했습니다 ㅋ 무료 뒤집기달인y 2010-10-22 0 1993
30 Software & IDEs VS6 MFC기반에서 Rchedit 컨트롤 추가시 에러 무료 아크마 2010-10-04 0 2100
29 Software & IDEs MFC 테트리스프로그램 입니다^^ [8] 무료 초짜초짜초짜 2010-09-27 0 3103
28 Software & IDEs [Win32api/게임 ] 갤러그 [4] 무료 밍구리 2010-07-02 0 3576
27 Software & IDEs VB 에서 VC++ 처럼 메시지 이벤트 사용 [2] 무료 전자과조교 2010-05-04 0 1893
26 Software & IDEs Serial로 데이터 받아 처리하는 신체검사프로그램 [7] 무료 맑은소리 2010-04-26 0 1852
25 Software & IDEs 그리기 예제입니다 ^^ [5] 무료 전설의사나이 2010-04-10 0 1855
24 Software & IDEs MFC를 이용한 타자게임 입니다 ^^ [4] 무료 전설의사나이 2010-04-10 0 3196
23 Software & IDEs Winsock API 한글 도움말 입니다 . [6] 무료 쑤잉아 2010-04-08 0 2032
22 Software & IDEs unix network 프로그래밍 관련 자료 입니다. [2] 무료 블루미르7 2010-01-05 0 1782
21 Software & IDEs 강아지 키트를 이용하여 만들었습니다~~~ [17] 무료 kimd 2009-11-20 0 2118
20 Software & IDEs [MFC] 날짜 계산기입니다 [8] 무료 shindy 2009-10-28 0 3538
19 Software & IDEs 제어용DSP 추천합니다 [1] 무료 날아가는잡쉐 2008-09-25 0 1282
18 Software & IDEs API 시리얼통신 함수 사용방법 입니다. 참고하세요 [10] 무료 뺘쑝 2008-04-30 0 3911
17 Software & IDEs [MFC] 윈도우 크기 고정하기 [6] 무료 아크마 2008-04-28 0 3956
16 Software & IDEs 섭씨 화씨 변환 프로그램 [8] 무료 아크마 2008-04-23 0 2536
15 Software & IDEs 저.. 지금 딱 두번 글을 올려 봤는데.. 움.. 먼가 좀 바꿔야 될듯 해서..;; ㅋㅋ [1] 무료 행복하면 2007-12-03 0 1313
14 Software & IDEs c언어와 c++ 할 줄은 아는데.. 개념이 조금 부족하신분.. [14] 무료 행복하면 2007-11-29 0 1965
  • 지식에 투자하는 것이 가장 이윤이 높다.
    - 벤자민 프랭클린
  • * 납포인트 정보 *
  • 글 작성 : 3
  • 댓글 작성 : 1
저작권법에 위배되는 콘텐츠는 등록 불가하며, 저작물에 대한 권리는 저작자에게 있습니다.
Copyright 2006-2021 © hardwareis.com, All rights reserved.