📄 at45db.bak
字号:
/******************************************************
// Filename : CS5460.c
// Abstract : This file implements main function.
//
// Device : uPD78F0396
// CreateTime: 2006/11/01
// Author :
******************************************************/
#include "UsrComm.h"
#include "AT45DB.h"
#define AT45DBBUSYWAIT 10
void SYS_SPIInit(void);
void CSI11_Init( void );
MD_STATUS AT45DB_PageErase(unsigned int pPAdress );
#define AT45DB_CS P0.0
void SYS_SPIInit(void)
{
PM2.3 = 1; //SI
PM2.4 = 0; //SO
PM2.5 = 0; //SCK
P2.4 = 0;
P2.5 = 0;
// CSIM1 = 0xC1; //fisrt bit MSB
// CSIC1 = 0x1A; //user SPI mode 4 ,sck = fx/2^4
}
#define SPI_SI (1 << P03)
#define SPI_SO (1 << P02)
#define SPI_SCK (1 << P04)
void CSI11_Init( void )
{
ClrIORBit(PM0, SPI_SO); // Setting Output
ClrIORBit(PM0, SPI_SCK); // Setting Output
SetIORBit(PM0, SPI_SI); //setting input
ClrIORBit(P0, SPI_SO);
ClrIORBit(P0, SPI_SCK);
SetIORBit(P0, SPI_SCK);
SetIORBit(CSIC11,CSIC11_CKP11); // user Mode 4
SetIORBit(CSIC11,CSIC11_DAP11);
SetIORBit(CSIC11,CSIC11_CKS112); // Sck = FPRS/2^6
ClrIORBit(CSIC11,CSIC11_CKS111);
SetIORBit(CSIC11,CSIC11_CKS110);
ClrIORBit(CSIM11,CSIM11_DIR11); // transfor first bit MSB
ClrIORBit(CSIM11,CSIM11_SSE11); // no use SSE
SetIORBit(CSIM11,CSIM11_CSIE11); //enable CSIC11
SetIORBit(CSIM11,CSIM11_TRMD11);
//ClrIORBit(IF1H, 0x02);
//ClrIORBit(MK1H, 0x02); // transfer end interrupt enable
//SetIORBit(PR1H, 0x02); // interrupt low
}
//===============================================================
MD_STATUS CSI11_Send1Byte( unsigned char ucData)
{
SOTB11 = ucData;
while( (CSIM11 & CSIM11_CSOT11) ); // CSOT11 bit 1 the CSI is busy
//while( (IF1H & IF1H_CSIIF11));
return MD_OK;
}
//===============================================================
MD_STATUS AT45DB_StatuRead(void)
{
unsigned char ucTemp;
SOTB11 = 0xff;
while( (CSIM11 & CSIM11_CSOT11) );
ucTemp = SIO11;
return ucTemp;
}
//===============================================================
MD_STATUS AT45DB_PageErase(unsigned int pPAdress )
{
unsigned int wWait = 0;
AT45DB_CS = 0;
while((!(AT45DB_StatuRead()&0x80)) &&(wWait < AT45DBBUSYWAIT)){
wWait++;
}
if(wWait >= AT45DBBUSYWAIT)
{
return MD_ERROR;
}
SOTB11 = AT45DB_PAGE_ERASE ;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pPAdress>>7);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pPAdress<<1) ;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = 0xff;
while( (CSIM11 & CSIM11_CSOT11) );
AT45DB_CS = 1;
return MD_OK;
}
//===============================================================
void AT45DB_BlockErase(unsigned int pPAdress,unsigned int pBAdress )
{
AT45DB_CS = 0;
SOTB11 = AT45DB_PAGE_ERASE ;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pPAdress>>7);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pBAdress<<1) ;
while( (CSIM11 & CSIM11_CSOT11) );
AT45DB_CS = 1;
}
//===============================================================
void AT45DB_BufferWrite(unsigned char ucBufSel, unsigned int pBAddr,unsigned char *pBuf)
{
unsigned int i;
AT45DB_CS = 0;
SOTB11 = AT45DB_BUFFER1_WRITE + ucBufSel;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 =0;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 =(unsigned char)(pBAddr>>8);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 =(unsigned char)(pBAddr&0x00ff);
while( (CSIM11 & CSIM11_CSOT11) );
for(i = 0; i < 264 ; i++)
{
SOTB11 = pBuf[i];
while( (CSIM11 & CSIM11_CSOT11) );
}
AT45DB_CS = 1;
}
//===============================================================
MD_STATUS AT45DB_MainPageToBufferCompare(unsigned char ucBufSel,unsigned int pPAddr )
{
unsigned char ucStatu;
AT45DB_CS = 0;
SOTB11 = AT45DB_MMP_BUFFER1C + ucBufSel;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pPAddr >> 7);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pPAddr << 1);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = 0;
while( (CSIM11 & CSIM11_CSOT11) );
ucStatu = AT45DB_StatuRead();
AT45DB_CS = 1;
if(ucStatu & 0x40)
return MD_OK;
else
return MD_ERROR;
}
//===============================================================
MD_STATUS AT45DB_BufferToMainPageProgramErase(unsigned char ucBufSel, unsigned int pPAddr,unsigned int pBAddr, unsigned char *pBuf)
{
unsigned int wWait;
AT45DB_BufferWrite(ucBufSel,pBAddr,pBuf );
AT45DB_CS = 0;
while((!(AT45DB_StatuRead()&0x80)) &&(wWait < AT45DBBUSYWAIT)){
wWait++;
}
if(wWait >= AT45DBBUSYWAIT)
{
return MD_ERROR;
}
SOTB11 = AT45DB_BUFFER1_TOMPPE + ucBufSel*3 ;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pPAddr>>7);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pPAddr<<1);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 =0 ;
while( (CSIM11 & CSIM11_CSOT11) );
AT45DB_CS = 1;
return MD_OK;
}
//===============================================================
MD_STATUS AT45DB_MainPageProgramThoughBuffer(unsigned char ucBufSel, unsigned int pPAddr,unsigned int pBAddr,unsigned int BufLength,unsigned char *pBuf)
{
unsigned int i;
unsigned int wWait;
AT45DB_CS = 0;
while((!(AT45DB_StatuRead()&0x80)) &&(wWait < AT45DBBUSYWAIT)){
wWait++;
}
if(wWait >= AT45DBBUSYWAIT)
{
return MD_ERROR;
}
SOTB11 = AT45DB_MMPPT_BUFFER1 + ucBufSel*3 ;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pPAddr>>7);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)((pPAddr<<1)| (pBAddr>>8)&0x00ff);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pBAddr) ;
while( (CSIM11 & CSIM11_CSOT11) );
for(i = 0; i < BufLength ; i++)
{
SOTB11 = pBuf[i];
while( (CSIM11 & CSIM11_CSOT11) );
}
AT45DB_CS = 1;
return MD_OK;
}
//===============================================================
MD_STATUS AT45DB_BufferRead(unsigned char ucBufSel, unsigned int pBAddr)
{
unsigned int i;
unsigned char pBuf[264];
AT45DB_CS = 0;
SOTB11 = AT45DB_BUFFER1_READ + ucBufSel<<1;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 =0;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 =(unsigned char)(pBAddr>>8);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 =(unsigned char)(pBAddr&0x00ff);
while( (CSIM11 & CSIM11_CSOT11) );
for(i = 0; i < 264; i++)
{
pBuf[i] = SIO11;
while( (CSIM11 & CSIM11_CSOT11) );
}
AT45DB_CS = 0;
return MD_OK;
}
//===============================================================
MD_STATUS AT45DB_MainPageToBufferTransfer(unsigned char ucBufSel, unsigned int pPAddr)
{
unsigned int wWait;
AT45DB_CS = 0;
while((!(AT45DB_StatuRead()&0x80)) &&(wWait < AT45DBBUSYWAIT)){
wWait++;
}
if(wWait >= AT45DBBUSYWAIT)
{
return MD_ERROR;
}
SOTB11 = AT45DB_MMP_BUFFER1T + ucBufSel*2;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pPAddr>>7);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 = (unsigned char)(pPAddr<<1);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 =0 ;
while( (CSIM11 & CSIM11_CSOT11) );
AT45DB_CS = 1;
return MD_OK;
}
//===============================================================
void AT45DB_MainPageRead(unsigned char ucBufSel, unsigned int pPAddr,unsigned int pBAddr, unsigned int BufLength)
{
unsigned char pBuf[264];
unsigned char i;
AT45DB_CS = 0;
SOTB11 = AT45DB_BUFFER1_READ + ucBufSel<<1;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 =0;
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 =(unsigned char)(pBAddr>>8);
while( (CSIM11 & CSIM11_CSOT11) );
SOTB11 =(unsigned char)(pBAddr&0x00ff);
while( (CSIM11 & CSIM11_CSOT11) );
for(i = 0; i < BufLength; i++)
{
pBuf[i] = SIO11;
while( (CSIM11 & CSIM11_CSOT11) );
}
AT45DB_CS = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -