main.c

来自「SD卡驱动基于SPI总线与SD卡通信」· C语言 代码 · 共 40 行

C
40
字号
#include "./SD_Driver/SD_INC.h"

xdata unsigned char ReadBuf[512];
xdata unsigned char WriteBuf[512];

int main(void)
{
	unsigned int i,ret;
	while(SD_Initialize() != SD_NO_ERR);	// Wait for Initialize
	for(i = 0; i < 512; i++)
	{
		WriteBuf[i] = i; 					// Initialize the buffer
	}
	ret = SD_WriteBlock(10, WriteBuf); 		// Write the content of WriteBuf to Block 10
	ret = SD_WriteBlock(11, WriteBuf); 		// Write the content of WriteBuf to Block 11
	if(ret!= SD_NO_ERR)
	{
		while(1);						 	// Write Err
	}
	ret = SD_ReadBlock(10, ReadBuf); 		// Read the content of Block 10 to the ReadBuf
	if(ret != SD_NO_ERR)
	{
		while(1);							// Read Err
	}
	for(i = 0; i < 512; i++)				// Compare
	{
		if(i != ReadBuf[i])
		{
			while(1);					 	// Content Err
		}
	}
	SD_EraseBlock(10,2);					// Erase tow blocks start with Block 10
	ret = SD_ReadBlock(11, ReadBuf); 		// Read the content of Block 11 to the ReadBuf
	if(ret != SD_NO_ERR)
	{
		while(1);							// Read Err
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?