/* Compiler: BC++ 3.1, Turbo C++ 1.01 (3.01) MSVC 1.52 Compile mode: large Project: SD_QA.c ..\..\lib\8000a.lib ..\lib\sd_vnnn.lib Hardware: uPAC-5000 [Jan 05, 2012] by Liam */ #include #include "..\..\Lib\8000a.h" #include "..\..\Lib\microSD.h" void main(void) { int fd,iRet,line,bytes,total_bytes; unsigned char buffer[80]; InitLib(); if(pc_init()) Print("Init microSD ok\n\r"); else { Print("Init microSD failed\n\r"); iRet=pc_get_errno(); switch(iRet) { case PCERR_BAD_FORMAT: //1 Print("Error 01: format is not FAT(FAT16)\n\r"); break; case PCERR_NO_CARD: //2 Print("Error 02: no microSD card\n\r"); break; default: Print("Error %02d: check the error code list in microSD.h\n\r"); } Delay(10); //wait 10 ms to let the message can be printed compeletely. exit(0); } fd=pc_open("test.txt",(word)(PO_RDONLY),(word)(PS_IWRITE|PS_IREAD)); if(fd>=0) { line=0; total_bytes=0; while(!pc_eof(fd)) { bytes=pc_read(fd,buffer,10); //write 10 bytes total_bytes+=bytes; line++; buffer[10]=0; //add zero end to the end of the string. Print("[Line%02d] %s\n\r",line,buffer); } pc_close(fd); Print("read %d bytes from test.txt, done.\n\r",total_bytes); } else { iRet=pc_get_errno(); Print("Error %02d: check the error code list in microSD.h\n\r",iRet); } }