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

📄 main.c

📁 Embedded SD card Interface
💻 C
字号:

#define THIS_IS_STACK_APPLICATION

#include "p24FJ128GA106.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>  
#include <stdio.h> 
#include <errno.h> 
#include "HardwareProfile.h"
#include "Delay.h"
#include "FSIO.h"

char sendBuffer[] = "This is test string 1";
char send2[] = "5";
char receiveBuffer[50];


int main(void)
{
	
	FSFILE * pointer;
   char path[30];
   char count = 30;
   char * pointer2;
   SearchRec rec;
   unsigned char attributes;
   unsigned char size = 0, i;
	
		/* Initialize GPIO ports */
	_DOZEN = 0;
	_RCDIV2 = 0;
	_RCDIV1 = 0;
	_RCDIV0 = 0;


	asm volatile ( "MOV #OSCCON, w1 \n"
"MOV #0x46, w2 \n"
"MOV #0x57, w3 \n"
"MOV.b w2, [w1] \n"
"MOV.b w3, [w1] \n"
"BCLR OSCCON,#6");

	AD1PCFGL = 0xffff;
	REDLED = 0;
	REDLED_TRIS = 0;
	GREENLED = 0;
	GREENLED_TRIS = 0;
	SD_CS = 1;
	SD_CS_TRIS = 0;

	RPINR18bits.U1RXR = 10;
	RPOR8bits.RP17R = 3;

	ENC_CS_TRIS = 0;
	ENC_CS_IO = 1;
		/* Attach SPI2 module to I/O pads */
	RPINR22bits.SDI2R = 19;			//SDI2 -- RP19	
	RPOR10bits.RP21R = SCK2OUT_IO; 	//SCK1OUT -- RP21
	RPOR13bits.RP26R = SDO2_IO;		//RP26 = SDO2

//	RPINR20 = 0x1F0C;	/* SDI1 -- RP12 */
//	RPOR6 = 0x0800;	/* SCK1OUT -- RP13 */
//	RPOR7 = 0x0007;	/* SDO1 -- RP14 */

// Lock Registers
asm volatile ( "MOV #OSCCON, w1 \n"
"MOV #0x46, w2 \n"
"MOV #0x57, w3 \n"
"MOV.b w2, [w1] \n"
"MOV.b w3, [w1] \n"
"BSET OSCCON, #6" );

	
	while (!MDD_MediaDetect())
	{
		
		REDLED ^= 1;
		GREENLED ^= 1;
		DelayMs(100);
			
	}

   // Initialize the library
   while (!FSInit())
   {
	   	
		REDLED ^= 1;
		GREENLED ^= 1;
		DelayMs(250);
			
	}
	GREENLED = 0;
   // Create a file
   pointer = FSfopen ("FILE1.TXT", "w");
   if (pointer == NULL)
   {
		while(1)
		{
		
		
			REDLED ^= 1;
			DelayMs(250);
		
		}
	}

   // Write 21 1-byte objects from sendBuffer into the file
   if (FSfwrite (sendBuffer, 1, 21, pointer) != 21)
	{
		while(1)
		{
		
		
			REDLED ^= 1;
			DelayMs(250);
		
		}
	}
   // FSftell returns the file's current position
   if (FSftell (pointer) != 21)
   {
	   
		while(1)
		{
		
		
			REDLED ^= 1;
			DelayMs(250);
		
		}
	}

   // FSfseek sets the position one byte before the end
   // It can also set the position of a file forward from the
   // beginning or forward from the current position
   if (FSfseek(pointer, 1, SEEK_END))
   {
	   
		while(1)
		{
		
		
			REDLED ^= 1;
			DelayMs(250);
		
		}
	}

   // Write a 2 at the end of the string
   if (FSfwrite (send2, 1, 1, pointer) != 1)
   {
	   
		while(1)
		{
		
		
			REDLED ^= 1;
			DelayMs(250);
		
		}
	}

   // Close the file
   if (FSfclose (pointer))
   {
	   
		while(1)
		{
		
		
			REDLED ^= 1;
			DelayMs(250);
		
		}
	}
	
	while(1)
	{
		REDLED ^= 1;
		GREENLED ^= 1;
		DelayMs(5);
		
	}
	return 0;
	
}


⌨️ 快捷键说明

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