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

📄 main.c

📁 周立功2103开发板CD资料
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzhou ZHIYUAN electronics Co.,LTD.
**                                 http://www.zyinside.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:           main.c
** Last modified Date:  2006-02-22
** Last Version:        1.0
** Descriptions:        header file of the specific codes for LPC2200 target boards
**              Every project should include a copy of this file, user may modify it as needed
**------------------------------------------------------------------------------------------------------
** Modified by: 
** Modified date:
** Version: 
** Descriptions: 
**
********************************************************************************************************/

#define IN_MAIN
#include "config.h"
#include "string.h"
#include "UART.h"
#pragma import(__use_no_semihosting_swi)	// don't delete this line

#define CMD_SD_INIT		   0x00				/* 卡初始化卡命令  */
#define CMD_SD_READ    	   0x01				/* 卡读命令        */
#define CMD_SD_WRITE   	   0x02				/* 卡写命令        */
#define CMD_SD_ERASE	   0x03				/* 卡擦除命令      */

#define CMD_DATA_TRANS	   0x04				/* 将sd_buf中的数据发送到PC机 */
#define CMD_DATA_RECV	   0x05				/* 接收来自串口的数据,并放入sd_buf中 */

/* SD/MMC卡读写缓冲区,比SDMMC卡一个块大8字节 */  
uint8  sd_buf[520];
uint8  Command[8];		//
uint8  Rcv_Flag = 0;	// 接收到新命令标志 
/*********************************************************************************************************
** Function name:			IRQ_Exception
** Descriptions:			interrupt exceptional handler , change it as needed
**                          don't delete this function 
********************************************************************************************************/
void  IRQ_Exception(void)
{
}
/*********************************************************************************************************
** 函数名称:UART0_Exception
** 函数功能:UART0中断服务函数。
********************************************************************************************************/
void  UART0_Exception(void)
{
	uint8  i;
	for( i = 0;i < 8;i++)			// 接收命令
		Command[i] = U0RBR;	
	Rcv_Flag = 1;
	VICVectAddr = 0x00;	
}
/*********************************************************************************************************
** 函数名称:main
** 函数功能:SD卡读卡函数
********************************************************************************************************/
void Main(void)
{
    uint8 *pRec = Command;
	uint32 bufaddr,blockaddr,blocknum;

    TargetInit(VPBDIV_DATA, PLLCFG_DATA, MAMTIM_DATA);      // don't delete
    while((PLLSTAT & (1 << 10)) == 0);                      // can delete
    UARTn_Init(0 , 115200 ,8 , 1 , 0 ,1);	// 初始化UART0
	Set_FIFO(0 , 8);						// 8字节FIFO
	IRQEnable();
    SetISR( 6 , 0 , (uint32)UART0_Exception);

	while(1)
	{
		if(Rcv_Flag == 1)
		{
			Rcv_Flag = 0;
			switch(pRec[0])
	    	{
	    		case CMD_SD_INIT: pRec[1] = SD_Initialize();			   /* 初始化SD卡 */
	    		break; 
	    		
	    		case CMD_SD_READ:
	    			 blockaddr = (pRec[1] << 24) + (pRec[2] << 16) +	   /* 计算块地址 */
	    						 (pRec[3] << 8) + pRec[4];
	    			 pRec[1] = SD_ReadBlock(blockaddr, sd_buf);		 	   /* SD卡单块读 */ 			
	    		break;
	    		 	    		
	    		case CMD_SD_WRITE:	 
	    			 blockaddr = (pRec[1] << 24) + (pRec[2] << 16) + 
	    						 (pRec[3] << 8) + pRec[4];
	    			 pRec[1] = SD_WriteBlock(blockaddr, sd_buf);		   /* SD 卡单块写 */
	    		break;
	    			
	    		case CMD_SD_ERASE:	 
	    			 blockaddr = (pRec[1] << 24) + (pRec[2] << 16) + 
	    						 (pRec[3] << 8) + pRec[4];				   /* 擦卡起始地址 */
	    			 blocknum  = (pRec[5] << 16) + (pRec[6] << 8) +	
	    				 		 (pRec[7]);								   /* 块数 */
	    			 pRec[1] = SD_EraseBlock(blockaddr, blocknum);		   /* 擦除操作 */
	    		break;
	   			
	    		case CMD_DATA_RECV:	 
	    			 bufaddr = (pRec[1] << 8) + pRec[2];				   /* 计算缓冲区地址 */
	    			 memcpy(sd_buf + bufaddr, &pRec[3], 5);				   /* 收到数据放入pRec */
	    		break;
	    			
	    		case CMD_DATA_TRANS: 
	    			 bufaddr = (pRec[1] << 8) + pRec[2];				   /* 计算缓冲区地址 */ 
	    			 memcpy(&pRec[1], sd_buf + bufaddr, 7);				   /* sd_buf数据放入pRec */
	    		break;  							
	    	
	    		default: break;
	    	}
			UARTn_SendData(0 , pRec , 8);									/* 发送响应帧 */
		}
	}

}
/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

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