📄 spiflash.h
字号:
/***************************************************************
2007 3.26
当采用硬件SPI模式时,请安下列要求配置MCU的SPI
1〉Enable SPI0
2> operation in Master Mode
3> data centered on first edge of sck
4> sck line low idle state
5〉3 wire mode
******************************************************************/
#ifndef __SPIFLASH__H__
#define __SPIFLASH__H__
#include "C8051F310.h" //如果采用C8051F340,请改为340的头文件
#define SIMULATION_SPI 1 //1--软件模拟SPI时序 0--硬件SPI
#define USE_M25P80 //如果型号改变请修改此值
/* Possible Values: USE_M25P40 USE_M25P80 USE_M25P16 USE_M25P32 */
#define COUNT_FOR_WRITE_DELAY (0x5FFFFL) //根据不同的硬件来调整
#if SIMULATION_SPI //软件SPI的管脚定义
sbit SPI_SCK = P0^0; //串行时钟
sbit SPI_MOSI= P0^2; //串行数据主输出从输入
sbit SPI_MISO= P0^1; //串行数据主输入从输出
sbit SPI_NSS = P0^3; //从选择
sbit SPI_WP = P3^3; //写保护
#else //硬件SPI的管脚定义
sbit SPI_NSS = P0^3; //从选择
sbit SPI_WP = P3^3; //写保护
#endif
unsigned char SPIFLASH_init(void); //初始化SPIFlash 读取相关状态,并硬件写保护
unsigned char SPIFLASH_protect(void); //硬件保护SPIFlash
unsigned char SPIFLASH_unProtect(void); //解保护
unsigned char SPIFLASH_erase_sector(unsigned char sectorNo); //擦除扇区
unsigned char SPIFLASH_write(unsigned long addr, unsigned char xdata *wbuf, unsigned char wlen); //写数据
unsigned char SPIFLASH_read(unsigned long addr, unsigned char xdata *rbuf, unsigned char rlen); //读数据
/*--------------------------------------------------------------------------------*/
#ifdef USE_M25P40 /* The M25P40 device */
#define EXPECTED_DEVICE (0x13) /* Device Identification for the USE_M25P40 */
#define FLASH_SIZE (0x080000) /* Total device size in Bytes */
#endif /* USE_M25P40 */
#ifdef USE_M25P80 /* The M25P80 device */
#define EXPECTED_DEVICE (0x14) /* Device Identification for the USE_M25P80 */
#define FLASH_SIZE (0x0100000) /* Total device size in Bytes */
#endif /* USE_M25P80 */
#ifdef USE_M25P16 /* The M25P16 device */
#define EXPECTED_DEVICE (0x15) /* Device Identification for the USE_M25P16 */
#define FLASH_SIZE (0x0200000) /* Total device size in Bytes */
#endif /* USE_M25P16 */
#ifdef USE_M25P32 /* The USE_M25P32 device */
#define EXPECTED_DEVICE (0x16) /* Device Identification for the USE_M25P32 */
#define FLASH_SIZE (0x0400000) /* Total device size in Bytes */
#endif /* USE_M25P32 */
#ifdef USE_M25P64 /* The USE_M25P64 device */
#define EXPECTED_DEVICE (0x17) /* Device Identification for the USE_M25P64 */
#define FLASH_SIZE (0x0800000) /* Total device size in Bytes */
#endif /* USE_M25P64 */
#define FLASH_SECTOR_COUNT ((unsigned char)(FLASH_SIZE/65536L))
#define ManufacturerID 0x20 //厂商ID
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -