?? spi.c
字號(hào):
/***************************************************************************
Project : Car two ting dvd System
Compiler : ST7 HiCross C (HiWARE)
Module : autos.c
Version : V 1.0
Created : 24 11, 2005
Author : tomi / SA
Description
- Main Program of the car two ting dvd System.
Modified
- tomi
***************************************************************************/
#include "SPI.h"
#include "Libr.h"
#include "St72321.h"
#include "IOport.h"
#include "Sys_config.h"
void SPI_HostWriteByte(unsigned char wByte);
unsigned char SPI_HostReadByte(void);
unsigned char AT45DB041B_StatusRegisterRead(void);
void AT45DB041B_ContinuousArrayRead(unsigned int PA,unsigned int BFA,unsigned char *pHeader,unsigned int len);
void AT45DB041B_BufferWrite(unsigned char buffer,unsigned int BFA,unsigned char *pHeader,unsigned int len);
void AT45DB041B_BufferToMainMemoryPageProgramWithBuilt_inErase(unsigned char buffer,unsigned int PA,unsigned int BFA,unsigned char *pHeader,unsigned int len);
void AT45DB041B_BufferToMainMemoryPageProgramWithoutBuilt_inErase(unsigned char buffer,unsigned int PA,unsigned int BFA,unsigned char *pHeader,unsigned int len);
void SPI_HostWriteByte(unsigned char wByte)
{
unsigned char i,j;
for(i=0;i<8;i++)
{
if((wByte<<i)&0x80)
Set_SPI_SI_high;
else
Set_SPI_SI_low;
Set_SPI_CLK_low;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
Set_SPI_CLK_high;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
}
}
unsigned char SPI_HostReadByte(void)
{
unsigned char i,j,rByte=0;
for(i=0;i<8;i++)
{
Set_SPI_CLK_low;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
Set_SPI_CLK_high;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
rByte<<=1;
if(IS_SPI_SO_high)
rByte|=1;
}
return rByte;
}
unsigned char AT45DB041B_StatusRegisterRead(void)
{
unsigned char R_data;
Set_SPI_CS_low;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
SPI_HostWriteByte(0x57);
R_data=SPI_HostReadByte();
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
Set_SPI_CS_high;
return R_data;
}
/******************************************************************************/
/*描述: */
/* When the last bit in the main memory array has been read,the device will*/
/* continue reading back at the beginning of the first page of memory.As w-*/
/* ith crossing over page boundaries,no delays will be incurred when wrapp-*/
/* ing around from the end of the array to the beginning of the array. */
/*參數(shù): */
/* PA - 頁(yè)地址,0~2047 */
/* BFA - 指定BUFFER中的起始寫入地址 */
/* pHeader - 指定數(shù)據(jù)的首地址 */
/* len - 指定數(shù)據(jù)的長(zhǎng)度 */
/******************************************************************************/
void AT45DB041B_ContinuousArrayRead(unsigned int PA,unsigned int BFA,unsigned char *pHeader,unsigned int len)
{
unsigned int i=0;
while(i++<255)
{if(AT45DB041B_StatusRegisterRead()&0x80)
{break;}
}
Set_SPI_CS_low;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
SPI_HostWriteByte(0xe8);
SPI_HostWriteByte((unsigned char)(PA>>7));
SPI_HostWriteByte((unsigned char)((PA<<1)|(BFA>>8)));
SPI_HostWriteByte((unsigned char)BFA);
for(i=0;i<4;i++){SPI_HostWriteByte(0x00);}
for(i=0;i<len;i++)
pHeader[i]=SPI_HostReadByte();
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
asm nop;
Set_SPI_CS_high;
}
/******************************************************************************/
/*描述: */
/* 將指定數(shù)據(jù)寫入從某個(gè)地址(0~263)開始的BUFFER中。 */
/*參數(shù): */
/* buffer - 選擇BUFFER,01H選擇BUFFER 1,02H選擇BUFFER 2 */
/* 在該指令序列中,操作碼84H選擇BUFFER 1,87H選擇BUFFER 2 */
/* BFA - BUFFER中的起始地址,0~263 */
/* pHeader - 待存數(shù)據(jù)的頭指針 */
/* len - 待存數(shù)據(jù)的長(zhǎng)度1~264 */
/******************************************************************************/
void AT45DB041B_BufferWrite(unsigned char buffer,unsigned int BFA,unsigned char *pHeader,unsigned int len)
{
unsigned int i=0;
while(i++<255)
{if(AT45DB041B_StatusRegisterRead()&0x80)
{break;}
}
Set_SPI_CS_low;
switch(buffer)
{
case 1:SPI_HostWriteByte(0x84);break;
case 2:SPI_HostWriteByte(0x87);break;
}
SPI_HostWriteByte(0x00);
SPI_HostWriteByte((unsigned char)(BFA>>8));
SPI_HostWriteByte((unsigned char)BFA);
for(i=0;i<len;i++)
SPI_HostWriteByte(pHeader[i]);
Set_SPI_CS_high;
}
/******************************************************************************/
/*描述: */
/* 將指定數(shù)據(jù)寫入從某個(gè)地址(0~263)開始的頁(yè)中:包含2個(gè)動(dòng)作,首先將指定數(shù)據(jù)*/
/* 寫入到BUFFER 1或者BUFFER 2中,其中可以指定BUFFER中的起始寫入地址,此寫入*/
/* 動(dòng)作不影響B(tài)UFFER中其它地址中的數(shù)據(jù),然后再將BUFFER中的整個(gè)數(shù)據(jù)寫入到某指*/
/* 定頁(yè)中(帶預(yù)擦除)。 */
/*參數(shù): */
/* buffer - 選擇BUFFER,01H選擇BUFFER 1,02H選擇BUFFER 2 */
/* PA - 頁(yè)地址,0~2047 */
/* BFA - 指定BUFFER中的起始寫入地址 */
/* pHeader - 指定數(shù)據(jù)的首地址 */
/* len - 指定數(shù)據(jù)的長(zhǎng)度 */
/******************************************************************************/
void AT45DB041B_BufferToMainMemoryPageProgramWithBuilt_inErase(unsigned char buffer,unsigned int PA,unsigned int BFA,unsigned char *pHeader,unsigned int len)
{
unsigned int i;
AT45DB041B_BufferWrite(buffer,BFA,pHeader,len);
while(i++<1000)
{if(AT45DB041B_StatusRegisterRead()&0x80)
{break;}
}
Set_SPI_CS_low;
switch(buffer)
{
case 1:SPI_HostWriteByte(0x83);break;
case 2:SPI_HostWriteByte(0x86);break;
}
SPI_HostWriteByte((unsigned char)(PA>>7));
SPI_HostWriteByte((unsigned char)(PA<<1));
SPI_HostWriteByte(0x00);
Set_SPI_CS_high;
}
/******************************************************************************/
/*描述: */
/* 與上一個(gè)函數(shù)的唯一區(qū)別是不帶預(yù)擦除。 */
/******************************************************************************/
void AT45DB041B_BufferToMainMemoryPageProgramWithoutBuilt_inErase(unsigned char buffer,unsigned int PA,unsigned int BFA,unsigned char *pHeader,unsigned int len)
{
unsigned int i=0;
AT45DB041B_BufferWrite(buffer,BFA,pHeader,len);
while(i++<1000)
{if(AT45DB041B_StatusRegisterRead()&0x80)
{break;}
}
Set_SPI_CS_low;
SPI_HostWriteByte(0x88+buffer);
SPI_HostWriteByte((unsigned char)(PA>>7));
SPI_HostWriteByte((unsigned char)(PA<<1));
SPI_HostWriteByte(0x00);
for(i=0;i<len;i++)
SPI_HostWriteByte(pHeader[i]);
Set_SPI_CS_high;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -