高中生
最后登录1970-1-1
在线时间 小时
注册时间2013-11-21
|
楼主 |
发表于 2014-3-25 11:42:53
|
显示全部楼层
#include "stm32f10x.h"
#include "delays.h"
#include "ledcfg.h"
#include "USERusart.h"
#include "nviccfg.h"
#include "sdiocfg.h"
#include "ff.h"
/* Private typedef -----------------------------------------------------------*/
typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
/* Private define ------------------------------------------------------------*/
#define BLOCK_SIZE 512 /* Block Size in Bytes */
#define NUMBER_OF_BLOCKS 32 /* For Multi Blocks operation (Read/Write) */
#define MULTI_BUFFER_SIZE (BLOCK_SIZE * NUMBER_OF_BLOCKS)
#define SD_OPERATION_ERASE 0
#define SD_OPERATION_BLOCK 1
#define SD_OPERATION_MULTI_BLOCK 2
#define SD_OPERATION_END 3
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
SD_Error Status = SD_OK;
uint8_t wrbuffer[]="stm32";
int res;
int a;
FIL fsrc,fdst;
FATFS fs;
UINT br, bw; // File R/W count
BYTE buffer[512]; // file copy buffer
BYTE textFileBuffer[] = "感谢您选用 野火STM32开发板 !^_^ \r\n";
int main(void)
{
Usart1_Init(115200);
NVIC_config();
USART_ClearFlag(USART1,USART_FLAG_TC);
USART1_printf(USART1, "SDIOProject\r\n");
USART1_printf(USART1, "SDIOProject\r\n");
f_mount(&fs,0,1);
res = f_open(&fdst,"0:/Demo.TXT",FA_CREATE_NEW | FA_WRITE);
if ( res == FR_OK )
{
/* 将缓冲区的数据写到文件中 */
res = f_write(&fdst, textFileBuffer, sizeof(textFileBuffer), &bw);
USART1_printf(USART1,"\r\n 文件创建成功 \n" );
/*关闭文件 */
f_close(&fdst);
}
else if ( res == FR_EXIST )
{
USART1_printf(USART1, "\r\n 文件已经存在 \n" );
}
res = f_open(&fdst, "0:/Demo.TXT", FA_OPEN_EXISTING | FA_READ); /* 打开文件 */
br = 1;
a = 0;
for (;;)
{
for ( a=0; a<512; a++ ) /* 清缓冲区 */
buffer[a]=0;
res = f_read( &fdst, buffer, sizeof(buffer), &br ); /* 将文件里面的内容读到缓冲区 */
USART1_printf(USART1,"\r\n %s ", buffer);
if (res || br == 0) break; /* 错误或者到了文件尾 */
}
f_close(&fdst);
while (1)
{}
}
|
|