代码写的不咋的 传上来供大家乐乐。140319.zip
http://elm-chan.org/fsw/ff/00index_p.html 整个传送门。嘿嘿。![]()
#include <stc12c5a60s2.h>
#include <intrins.h>
#include "delay.h"
#include "uart.h"
#include "spi_msd.h"
#include "spi.h"
#include "pff.h"
FATFS fatfs; ///定义一个文件系统对象
void main(void)
{
// unsigned char flag = 0;
unsigned int read_size = 0;
unsigned char buf[512] = {0};
unsigned char times = 0;
FRESULT res;
char s[] = " ";
unsigned int i;
WORD br,rc,bw;
P0 =0xff;
Delay999ms();
P0 =0xF0;
Delay999ms();
P0 =0xFf;
UartInit();
SPI_LowSpeed();
SendString("STC12C5A60S2\r\nUart Test !\r\n");
SendString("THAT THE TRUTH YOU LEAVE !\r\n");
SD_Init();
if(SD_ReadSingleBlock(0x100,buf)== 0)
{
for(read_size = 1; read_size < 512 ;read_size++)
{
SendData(buf[read_size]);
Delay999us();
}
//SendString(&buf);
}
res = pf_mount(&fatfs);
if(res == FR_OK)
SendString("挂载成功!\n"); //如果返回1,则挂载失败,否则成功
else
SendString("挂载失败\n");
res = pf_open("test.txt");
SendString("*********************\r\n");
SendData(res + 0X30);
SendString("\r\n*********************\r\n");
if(res == FR_OK)
SendString("打开文件成功\n"); //如果返回1,则打开失败,否则成功
else
SendString("打开文件失败\n");
for (;;) //读SD卡baichi.txt里的内容
{
rc = pf_read(s, sizeof(s), &br); /* Read a chunk of file */
if (rc || !br) break; /* Error or end of file */
for (i = 0; i < br; i++) /* Type the data */
SendData(s[i]);
}
/*
flag = SD_Init();
if(flag)
{
SendString("ERROR!\r\n");
}
else
{
SendString("SUCCESSFUL!\r\n");
}
*/
/*for(times = 0 ;times<200;times++)
{
buf[times] = times;
} */
/* SendString("READING ......!\r\n");
if(SD_ReadSingleBlock(0,buf)== 0)
{
SendString("SECTOR 0 DATA:\n");
for(read_size = 1; read_size < 512 ;read_size++)
{
SendData(buf[read_size]);
Delay999us();
}
//SendString(&buf);
Delay999ms();
SendString("\nDATA ENDED\n");
}
else
{
SendString("READING ERROR!\r\n");
}
*/
/* SendString("WRITING ......!\r\n");
if(SD_WriteSingleBlock(129,buf) == 0)
{
for(times = 0;times<200;times++)
{
buf[times] = 0;
}
if(SD_ReadSingleBlock(129,buf)== 0)
for(read_size = 1; read_size < 512 ;read_size++)
{
SendData(buf[read_size]);
Delay999us();
}
}
else
{
SendString("WRITING ERROR!\r\n");
}
*/
while(1)
{
}
}
我要赚赏金
