/* Compiler: BC++ 3.1, Turbo C++ 1.01 (3.01) MSVC 1.52 Compile mode: large Project: SD_QA.c ..\..\lib\upac5000.lib ..\lib\sd_vnnn.lib Hardware: uPAC-5000 [Jul 31, 2013] by Liam */ #include #include "..\..\Lib\uPAC5000.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"); else { Print("Init microSD failed\n"); iRet=pc_get_errno(); switch(iRet) { case PCERR_BAD_FORMAT: //1 Print("Error 01: format is not FAT(FAT32)\n"); break; case PCERR_NO_CARD: //2 Print("Error 02: no microSD card\n"); break; default: Print("Error %02d: check the error code list in microSD.h\n"); } 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", line, buffer); } pc_close(fd); Print("read %d bytes from test.txt, done.\n", total_bytes); } else { iRet=pc_get_errno(); Print("Error %02d: check the error code list in microSD.h\n", iRet); } }