#include "config.h"
#include "sst25vfxx.h"
/* ========================================================================= */
/* Project Name : SPI读写SST25VF040 flash */
/* File Name : SST25VF040.c */
/* Description : SST25VF040操作函数 */
/* Processor : STC12LE5A16S2 */
/* Tools : KEIL C51 */
/* ========================================================================= */
//=============================================================================
// ----Function: void SST25VFxx_SPIinit(void);
// -Description: Initialization SPMC75F2413A SPI.
// --Parameters: none.
// -----Returns: none.
// -------Notes: Bit11:SCK, Bit12:SDI, Bit13:SDO, Bit14:CS.
//=============================================================================
sbit SPI_CLK = P1^7;
sbit SPI_MOSI = P1^5;
sbit SPI_MISO = P1^6;
sbit SPI_SS = P1^4;
//sbit SPI_WP = P3^4;
#define SPIF 6 //注意该处值
#define PIC_FDT_FILESTARTADDR 0X000000 //图像文件名称属性起始地址
#define PIC_DATA_FILESTARTADDR 0X001000 //图像文件数据的起始地址
//#define WCOL 6
void SST25VFxx_SPIinit(void)
{
//P1M1 |= 0x0;
//P1M0 |= 1;
SPI_CLK = 0;
SPI_MOSI = 1;
SPI_MISO = 1;
SPI_SS = 1;
//SPI_WP = 1;
//SPCTL = 0xd3; // 注意在这里CPHA不能为1,只能为0;SSIG只能为1,不能为0
//SPSTAT = 0xc0;
//=============================================================================
// SPCTL寄存器
// |-------|-------|--------|--------|---------|---------|---------|--------|
// | bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 |
// | SSIG | SPEN | DORD | MSTR | CPOL | CPHA | SPR1 | SPR0 |
// |-------|-------|--------|--------|---------|---------|---------|--------|
/* 1 1 0 1 0 0 1 1
SPIG:使能SPI中断
SPEN:使能SPI.SPE置位将使能SPI,进行任何SPI操作之前必须置位SPE.
DORD:置位时,数据的LSB首先发送;否则数据的MSB首先发送
MSTR:主从选择。置位选择主机模式,否则选择从机模式。
CPOL:时钟极限。置位表示空闲时SCK为高电平;否则空闲时SCK为低电平
CPHA:时钟相位。CPHA决定数据是在SCK的起始沿采样还是在SCK的结束沿采样;
置位时表示在结束沿采样,否则在起始沿采样
SPR1,0:确定主机的SCK速率。采样列表如下:
SPI2X SPR1 SPR0 SCK频率
0 0 0 Fosc/4
0 0 1 Fosc/16
0 1 0 Fosc/64
0 1 1 Fosc/128
1 0 0 Fosc/2
1 0 1 Fosc/8
1 1 0 Fosc/32
1 1 1 Fosc/64
SPI2X:为时钟倍速设置。置位后SCK频率将调高一倍
//=============================================================================
// SPSTAT寄存器设置
// |-------|-------|--------|--------|---------|---------|---------|--------|
// | bit7 | bit6 | bit5 | bit4 | bit3 | bit2 | bit1 | bit0 |
// | SPIF | WCOL | -- | -- | -- | -- | -- | SPI2X |
// |-------|-------|--------|--------|---------|---------|---------|--------|
SPIF:SPI中断标志
SPI2X:倍速。若为主机频率可达到CPU的一半;但是若为从机,最高只能保证Fosc/4
*/
}
//=============================================================================
// ----Function: uint16 SST25VFxx_RDID(void);
// -Description: Read Manufacturer and Product ID
// --Parameters: none
// -----Returns: Manufacturer and Product ID
// -------Notes: Return value for example
// |---------------+---------------|
// | High Byte | Low Byte |
// +---------------+---------------+
// | Manufacturer | Product ID |
// |---------------+---------------|
// High Byte: Manufacturer
// 1FH = ATMEL .....
// Low Byte: Product ID
// 65H = 25F512
// 60H = 25F1024
// 63H = 25F2048
// 64H = 25F4096 .....
//=============================================================================
/*
unsigned int SST25VFxx_RDID(void) //Read Manufacturer and Product ID
{
TYPEWORDDEF HIREBUFFER;
unsigned char buffer[4];
unsigned char i;
SPI_SS = 0; //CS为低,有效
buffer[0] = RDID1;
buffer[1] = 0x00; //高地址
buffer[2] = 0x00; //中间八位地址
buffer[3] = 0x00; //低地址
for(i=0;i<4;i++)
{
//SPDAT = buffer[i]; //SPI发送RDID指令和地址
//while(!(SPSTAT & (3<<SPIF))); //等待SPI发送数据完成
//SPSTAT = 0xC0;
SendData(buffer[i]);
}
// SPDAT = 0; //写任何数据,主机产生时钟接收数据
// while(!(SPSTAT & (3<<SPIF))); //等待SPI数据接收完成
// SPSTAT = 0xc0; //清除标志
// HIREBUFFER.B._byte1 = SPDAT; //读取SST25VFxx送回的厂商信息数据BF
HIREBUFFER.B._byte1 = GetData();
// SPDAT = 0; //写任何数据,主机产生时钟接收数据
// while(!(SPSTAT & (3<<SPIF))); //等待SPI数据接收完成
// SPSTAT = 0xc0; //清除标志
// HIREBUFFER.B._byte0 = SPDAT; //读取SST25VFxx送回的芯片ID数据41
HIREBUFFER.B._byte0 = GetData();
SPI_SS = 1; //CS为高
return(HIREBUFFER.W); //返回厂商和ID数据
}*/
//=============================================================================
// ----Function: uint16 SST25VFxx_RDSR(void);
// -Description: Read status register
// --Parameters: none
// -----Returns: SST25VFxx status
// -------Notes: Return value format
// |------+------+------+------+------+------+------+------|
// | Bit7 | Bit6 | Bit5 | Bit4 | Bit3 | Bit2 | Bit1 | Bit0 |
// +------+------+------+------+------+------+------+------+
// | WPEN | ** | ** | ** | BP1 | BP0 | WEN | /RDY |
// |------+------+------+------+------+------+------+------|
// Bit0=0 :Indicates the device is Ready.
// Bit0=1 :Indicates the write cycle is in progress.
//
// Bit1=0 :Indicates the device is not WRITE ENABLED.
// Bit1=1 :Indicates the device is WRITE ENABLED.
//
// Bit2 and Bit3 : Please see SST25VFxx Data Sheet Table.
//
// Bit7 : Please see SST25VFxx Data Sheet Table. .....
//=============================================================================
unsigned char SST25VFxx_RDSR(void) //Read status register
{
unsigned char status = 0;
SPI_SS = 0;
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ov529soft.rar (69个子文件)
stc12&ov529
eeprom.c 2KB
STARTUP.LST 14KB
uart1.h 2KB
uart1.LST 9KB
uart0.C 6KB
stc12&ov529.SearchResults 5KB
delay.OBJ 6KB
stc12&ov529.WK3 38KB
stc12&ov529.PFI 76B
uart1.C 5KB
ov529.plg 995B
config.h.bak 3KB
ov529 133KB
stc12&ov529.IAD 568B
stc12le5a ov529 140KB
stc12&ov529.PO 776B
stc12le5a&ov529.Uv2 2KB
stc12le5a&ov529.plg 14KB
main.hex 23KB
STARTUP.A51 6KB
delay.LST 3KB
stc12le5a ov529.M51 102KB
config.h 3KB
ov529.C 4KB
stc12le5a&ov529_Opt.Bak 2KB
ov529.lnp 158B
stc12&ov529.IAB 24KB
delay.h 416B
manager.C 21KB
ov529.OBJ 16KB
rtc.h 1KB
eeprom.OBJ 7KB
serial.plg 19KB
stc12&ov529.PRI 38KB
stc12le5a32s2.H 17KB
ov529.hex 21KB
eeprom.h 422B
delay.c 1KB
stc12&ov529.PS 91KB
stc12le5a&ov529_Uv2.Bak 2KB
stc12&ov529.IMD 448B
uart1.OBJ 14KB
STARTUP.OBJ 749B
sst25vfxx.h 3KB
manager.C.bak 22KB
uart0.OBJ 14KB
manager.h 399B
manager.LST 38KB
sst25vfxx.C 29KB
manager.OBJ 37KB
eeprom.LST 4KB
ov529.M51 92KB
main.C.bak 9KB
rtc.LST 8KB
stc12&ov529.PR 6KB
main.LST 15KB
ov529.LST 8KB
rtc.OBJ 14KB
stc12le5a&ov529.lnp 168B
sst25vfxx.OBJ 13KB
uart0.h 1KB
stc12le5a&ov529.Opt 2KB
main.OBJ 30KB
stc12&ov529.IMB 12KB
sst25vfxx.LST 42KB
uart0.LST 13KB
main.C 8KB
rtc.C 4KB
ov529.h 2KB
共 69 条
- 1
资源评论
lyy21
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功