实现功能:创建12-29.txt,写入EEWORD GOOD!,然后在读出来
主代码:
int main(void)
{
//系统时钟
SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC| SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ);
//自定义串口初始化;波特率为9600
USART_Configuration(9600);
//SPI时钟使能
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//系统滴答
SysTickPeriodSet(SysCtlClockGet() / 100);
SysTickEnable();
SysTickIntEnable();
IntMasterEnable();
printf("\r\n mmc/sd卡演示\r\n");
res = f_mount(0, &fs);
if(res == FR_OK)
printf("\n 开辟空间成功! \r\n");
else
printf("\n 开辟空间失败! \r\n");
res=f_open(&fsrc,"12-29.txt",FA_CREATE_ALWAYS | FA_WRITE);
if (res == FR_OK)
printf("\n 创建12-29.txt文件成功! \r\n");
else
printf("\n 创建12-29.txt文件失败! \r\n");
res = f_write(&fsrc, &w_buffer, countof(w_buffer), &bw);
if (res == FR_OK)
printf("\n 写入文件成功! \r\n");
else
printf("\n 写入文件失败! \r\n");
res=f_close(&fsrc);
if (res == FR_OK)
printf("\n 关闭文件成功! \r\n");
else
printf("\n 关闭文件失败! \r\n");
res=f_open(&fsrc,"12-29.TXT",FA_READ);
if (res == FR_OK)
printf("\n 读取12-29.txt文件成功! \r\n");
else
printf("\n 读取12-29.txt文件失败! \r\n");
res = f_read(&fsrc, &buffer, 1024, &br);
if (res == FR_OK)
{
printf("\n 读取文件成功! \r\n");
printf("\n 文件内容为:\r\n%s\r\n",buffer);
printf("读取 %d 字节!\r\n",br);
}
else
printf("\n 读取文件错误代码为:%d\r\n",res);
////////////////////////
res=f_close(&fsrc);
if (res == FR_OK)
printf("\n 关闭文件成功! \r\n");
else
printf("\n 关闭文件失败! \r\n");
////////////////////////
res=f_mount(0, NULL);
if (res == FR_OK)
{
printf("\n 注销区域成功! \r\n");
}
while(1)
{
}
}
实现效果:
代码下载:[hide][/hide]
MMC/SD资料: