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

📄 sdmmc.h

📁 mp3代码 要用的干净下啊 希望用东西共享啊
💻 H
字号:
/**************************************************************************************
//------------------ MMC/SD-Card Reading and Writing implementation -------------------
//FileName     : mmc.c
//Function     : Connect AVR to MMC/SD 
//Created by   : ZhengYanbo
//Created date : 15/08/2005
//Version      : V1.2
//Last Modified: 19/08/2005
//Filesystem   : Read or Write MMC without any filesystem

//CopyRight (c) 2005 ZhengYanbo
//Email: Datazyb_007@163.com
****************************************************************************************/

#ifndef _MMC_H_
#define _MMC_H_

//If use MMC-Card then set to 1
#define	USE_MMC 		1       //EXPERIMENTAL NOT READY!!!! 
#define HW_SPI_Mode     0       //1:hardware SPI 0:software SPI

#define MMC_PORT		    PORTB	//SPI port register
#define MMC_PIN		    	PINB	//Data PIN
#define MMC_DDR				DDRB    //Direction register

#define SPI_MISO			6	//-->MMC_DO_PIN
#define SPI_MOSI			5	//-->MMC_DI_PIN
#define SPI_CLK				7	//-->MMC_CLK_PIN
#define MMC_Chip_Select		4	//-->MMC_CS_PIN 
#define SPI_Busy        	0   //busy led

//#define MMC_DO_PIN      MMC_PIN&BIT(SPI_MISO)
//#define MMC_DI_PIN      MMC_PORT.SPI_MOSI
//#define MMC_CLK_PIN     MMC_PORT.SPI_CLK
//#define MMC_CS_PIN      MMC_PORT.MMC_Chip_Select



//#define MMC_BUSY_LED    MMC_PORT.SPI_BUSY //busy led for spi port
//set MMC_Chip_Select to low (MMC/SD-Card Active)
#define MMC_Enable()    MMC_PORT&=~(1<<MMC_Chip_Select);
//set MMC_Chip_Select to high (MMC/SD-Card Invalid)    
#define MMC_Disable()    MMC_PORT|=(1<<MMC_Chip_Select);    
//--------------------------------------------------------------
// Hardwre SPI port define. Here for ATmega162
//--------------------------------------------------------------
#define HW_SPI_MOSI       5
#define HW_SPI_MISO  		6
#define HW_SPI_SCK 		7
#define HW_SPI_SS  		4

#define HW_SPI_Direction_REG  DDRB
#define HW_SPI_PORT_REG       PORTB

//------------------------------------------------------------
// Error define
//-------------------------------------------------------------
#define INIT_CMD0_ERROR     0x01
#define INIT_CMD1_ERROR		0x02
#define WRITE_BLOCK_ERROR	0x03
#define READ_BLOCK_ERROR   	0x04 



//------------------------------------------------------------
// MMC/SD commands
//-------------------------------------------------------------
#define MMC_RESET		0x40 + 0
#define MMC_INIT		0x40 + 1
#define MMC_READ_CSD		0x40 + 9
#define MMC_READ_CID		0x40 + 10
#define MMC_STOP_TRANSMISSION	0x40 + 12
#define MMC_SEND_STATUS		0x40 + 13
#define MMC_SET_BLOCKLEN	0x40 + 16
#define MMC_READ_BLOCK		0x40 + 17
#define MMC_READ_MULTI_BLOCK	0x40 + 18
#define MMC_WRITE_BLOCK		0x40 + 24
#define MMC_WRITE_MULTI_BLOCK	0x40 + 25
//-------------------------------------------------------------
// data type
//-------------------------------------------------------------   
// this structure holds info on the MMC card currently inserted 
typedef struct MMC_VOLUME_INFO
{ //MMC/SD Card info
  uint16   size_MB;
  uint8   sector_multiply;
  uint16   sector_count;
  uint8   name[6];
} VOLUME_INFO_TYPE; 


typedef struct STORE 
{ 
  uint8   data[512]; 
} BUFFER_TYPE; //256 bytes, 128 words




extern uint8 MMC_Init(void);
extern uint8 MMC_Write_Sector(uint32 addr,uint8 *Buffer);
extern uint8 MMC_Read_Sector(uint32 addr,uint8 *Buffer);
extern uint8 Write_Command_MMC(uint8 *CMD);
extern void MMC_get_volume_info(VOLUME_INFO_TYPE *vinf);

extern uint8 MMC_Start_Read_Sector(uint32 sector);
extern void MMC_get_data(uint16 Bytes,uint8 *buffer);
extern void MMC_get_data_LBA(uint32 lba, uint16 Bytes,uint8 *buffer);
extern void MMC_GotoSectorOffset(uint32 LBA,uint16 offset);
extern void MMC_LBA_Close(void);

#endif //_MMC_H_


⌨️ 快捷键说明

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