⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 SD和FAT文件系统.rar
💻 C
字号:
#include 	<string.h>
#include "..\inc\datatype.h"
#include "..\inc\sd.h"
#include "..\inc\option.h"
#include "..\inc\44b.h"
#include "..\inc\def.h"
#include "..\inc\44blib.h"
#include "..\inc\fat16.h"

void Isr_Init(void);
int Main(void)
{
	
	INT32U i = 0;
	INT8U j;
	INT8U CHA[]={"WINDOWS.WAV"};
	rSYSCFG = SYSCFG_8KB;
#if (PLLON==1)				//锁相环许可
	ChangePllValue(PLL_M, PLL_P, PLL_S);
#endif
	Isr_Init();
	Port_Init ();
	Uart_Init (0, 115200);
	Uart_Select (0);
	Delay (0);  			//计算延时时间
	Delay (5000);

	if(SD_Init(&g_SDInfo) == 0)
	{
		Uart_Printf("\n存储卡初始化完成\r\n");
		Uart_Printf("卡类型");
		if(g_SDInfo.ct == SD_TYPE_MMC)
		{
			Uart_Printf("MMC\r\n");
		}
		else if(g_SDInfo.ct == SD_TYPE_SD)
		{
			Uart_Printf("SD\r\n");
		}
		Uart_Printf("x:容量:");
		Uart_Printf("%d",g_SDInfo.mdt);
	//	Uart_Printf("%d",g_SDInfo.cap / 10000 + 0x30);
	/*	Uart_Printf(g_SDInfo.cap % 10000 / 1000 + 0x30);
		Uart_Printf(g_SDInfo.cap % 1000 / 100 + 0x30);
		Uart_Printf(g_SDInfo.cap % 100 / 10  + 0x30);
		Uart_Printf(g_SDInfo.cap %  10  + 0x30);
		Uart_Printf("M\r\n");*/
	/*	Usart0_PutString("BPB扇区位置:");
		g_u32Fat16BpbSectNo = FAT16_FindBPB();
		Usart0_PutChar("%d",g_u32Fat16BpbSectNo / 1000 + 0x30);
		Usart0_PutChar("%d",g_u32Fat16BpbSectNo % 1000 / 100 + 0x30);
		Usart0_PutChar("%d",g_u32Fat16BpbSectNo % 100 / 10 + 0x30);
		Usart0_PutChar("%d",g_u32Fat16BpbSectNo % 10 + 0x30);
		Usart0_PutString("\r\n");*/
		
		Uart_Printf("x:文件系统初始化...\r\n");
		FAT16_Init(&g_Fat16InitArg);
		if(g_Fat16InitArg.FATType == FAT_TYPE_FAT12)
		{
			Uart_Printf("FAT12文件系统\r\n");
		}
		else if(g_Fat16InitArg.FATType == FAT_TYPE_FAT16)
		{
			Uart_Printf("FAT16文件系统\r\n");
		}
		else if(g_Fat16InitArg.FATType == FAT_TYPE_FAT32)
		{
			Uart_Printf("FAT32文件系统\r\n");
		}
		
		Uart_Printf("簇:");
		Uart_Printf("%d",g_Fat16InitArg.BPBSecNo / 10000 + 0x30);
		Uart_Printf("%d",g_Fat16InitArg.BPBSecNo% 10000 / 1000 + 0x30);
		Uart_Printf("%d",g_Fat16InitArg.BPBSecNo  % 1000 / 100 + 0x30);
		Uart_Printf("%d",g_Fat16InitArg.BPBSecNo % 100 / 10 + 0x30);
		Uart_Printf("%d",g_Fat16InitArg.BPBSecNo  % 10 + 0x30);
		
		
		i = FAT16_GetNextClus(3);
		Uart_Printf("簇5Next:");
		Uart_Printf("%d",i / 10000 + 0x30);
		Uart_Printf("%d",i % 10000 / 1000 + 0x30);
		Uart_Printf("%d",i  % 1000 / 100 + 0x30);
		Uart_Printf("%d",i % 100 / 10 + 0x30);
		Uart_Printf("%d",i  % 10 + 0x30);
		Uart_Printf("\r\n");
		if(FAT16_OpenFile(CHA, &g_FileInfo) == 0)
		{
			
			Uart_Printf("x:找到并打开文件^_^\r\n");
			
			
			for(j = 0; j < 12; j++)
			{
				Uart_Printf("%c",g_FileInfo.Name[j]);
			}
			Uart_Printf("\r\n");
			FAT16_ReadFile(&g_FileInfo);

		}
		else
		{
			Uart_Printf("找不到文件:(");
		}

	}
	else
	{
		Uart_Printf("\r\n存储卡初始化失败\r\n");
	}
	while(1)
	{
	;
	}
}

extern char Image$$RO$$Base[];
void Isr_Init(void)
{
	unsigned int cc;
	//中断向量重映射
	for (cc = _RAM_STARTADDRESS;cc < (_RAM_STARTADDRESS + 0x20);cc += 4)
	{
		*((volatile unsigned *)cc) = 0xEA000000 + ((unsigned int)Image$$RO$$Base - 0x0c000000 - 8) / 4;
	}

	//rINTCON=0x1;	  			// Vectored Int. IRQ enable,FIQ disable
	rINTCON = 0x5;	  			// Non-vectored,IRQ enable,FIQ disable

	rINTMOD = 0x0;	  			// All=IRQ mode
	rINTMSK |= BIT_GLOBAL | BIT_EINT4567;	  // All interrupt is masked.
}

⌨️ 快捷键说明

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