📄 at45db642.txt
字号:
//---------------SPIInit();
//---------------SPI初始化---------------
//-------------------------------------------------------
//*************************************************************************************************************
uint32 SPIInit( void )
{
S0SPCR = 0x00;
PINSEL0 &= 0xFFFF00FF;
PINSEL0 |= 0x00001500; //引脚定义...
IOSET = AT45DB_CS;
/* Setting SPI0 clock, for Atmel SEEPROM, SPI clock should be no more
than 3Mhz on 4.5V~5.5V, no more than 2.1Mhz on 2.7V~5.5V */
S0SPCCR = 0x8; //速度...
//#if INTERRUPT_MODE
// if ( install_irq( SPI0_INT, (void *)SPI0Handler ) == FALSE )
// {
// return (FALSE);
// }
/* 8 bit, CPOL=CPHA=0, master mode, MSB first, interrupt enabled */
// S0SPCR = SPI0_SPIE | SPI0_MSTR;
//#else
S0SPCR = SPI0_MSTR; //用查询方式 ...
//#endif
return( TRUE );
}
//*************************************************************************************************************
//-------------------------------------------------------
//---------------Buffer1_To_Write_AT45 (uint16 u16_page);....---u16_page为主存的页地址.------
//---------------SPI,转缓存1写入主存页中---------------
//-------------------------------------------------------
//*************************************************************************************************************
void Buffer1_To_Write_AT45 (uint16 u16_page)
{
// uint16 u16_cnt;
IOCLR = AT45DB_CS;
IOCLR = AT45DB_CS;
S0SPDR = 0x83;
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_page>>5);
while(0 == (S0SPSR&0x80));
S0SPDR = ( (uint8)(u16_page))<<3;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
IOSET = AT45DB_CS;
IOSET = AT45DB_CS;
while(!(IOPIN&Rdy_busy));
}
//*************************************************************************************************************
//-------------------------------------------------------
//---Write_Buffer1_AT45();.---u16_address为缓存1的起始地址,u16_Counter为要写入的字节数.store_data写入数据的起始字节地址....
//---------------SPI,写缓存1---------------
//-------------------------------------------------------
//*************************************************************************************************************
void Write_Buffer1_AT45 (uint16 u16_address,uint16 u16_Counter,uint8 *store_data)
{
uint16 u16_cnt;
IOCLR = AT45DB_CS;
IOCLR = AT45DB_CS;
S0SPDR = 0x84;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_address>>8);
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_address);
while(0 == (S0SPSR&0x80));
for(u16_cnt=0;u16_cnt<u16_Counter;u16_cnt++)
{
S0SPDR = *(store_data+u16_cnt);
while(0 == (S0SPSR&0x80));
}
IOSET = AT45DB_CS;
IOSET = AT45DB_CS;
while(!(IOPIN&Rdy_busy));
}
//*************************************************************************************************************
//-------------------------------------------------------
//---Main_to_Buffer1_AT45();.---u16_page为主存的页地址....
//---------------SPI,主存页的内容转到缓存1中---------------
//-------------------------------------------------------
//*************************************************************************************************************
void Main_to_Buffer1_AT45(uint16 u16_page)
{
// IOSET = Light2;
IOCLR = AT45DB_CS;
IOCLR = AT45DB_CS;
S0SPDR = 0x53;
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_page>>5);
while(0 == (S0SPSR&0x80));
S0SPDR = ( (uint8)(u16_page))<<3;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
while(!(IOPIN&Rdy_busy));
IOSET = AT45DB_CS;
IOSET = AT45DB_CS;
// IOCLR = Light2;
}
//------------------------------------------------------
/*
//-------------------页写-----------------------
void Write_AT45 (uint16 u16_page,uint8 *store_data)
{
uint16 u16_cnt;
IOCLR = AT45DB_CS;
S0SPDR = 0x82;
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_page>>5);
while(0 == (S0SPSR&0x80));
S0SPDR = ( (uint8)(u16_page))<<3;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
for(u16_cnt=0;u16_cnt<1056;u16_cnt++)
{
S0SPDR = *(store_data+u16_cnt);
while(0 == (S0SPSR&0x80));
}
IOSET = AT45DB_CS;
while(!(IOPIN&Rdy_busy));
}
*/
//***************************************************
/*
void Read_AT45 (void)
{
uint16 u16_cnt;
IOCLR = AT45DB_CS;
S0SPDR = 0xd2;
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_page>>5);
while(0 == (S0SPSR&0x80));
S0SPDR = ((uint8)(u16_page))<<3;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
for(u16_cnt=0;u16_cnt<1056;u16_cnt++)
{
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
DIS_FOR_IIC[u16_cnt] = S0SPDR;
}
IOSET = AT45DB_CS;
}
*/
//---------------------------------------
//*************************************************************************************************************
//-------------------------------------------------------
//---Reda_AT45_Continue();.---u16_page为主存的页地址.u16_address要读的数据的起始地址.u16_cnt要读的字节数.Store_temp存放数据的起始位置.
//---------------SPI,直接读主存的任意地址数据..---------------Reda_AT45_Continue MUST BE 'Read_AT45_Continu'haha....
//-------------------------------------------------------
//*************************************************************************************************************
void Reda_AT45_Continue(uint16 u16_page,uint16 u16_address,uint16 u16_cnt,uint8 *Store_temp)
{
uint16 i;
if(COMMUNICATE) //字库通讯显示........
{
COMMUNICATING();
}
IOCLR = AT45DB_CS;
// IOCLR = AT45DB_CS;
S0SPDR = 0xe8;
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_page>>5);
while(0 == (S0SPSR&0x80));
S0SPDR = (( (uint8)(u16_page))<<3)|( (uint8)(u16_address>>8));
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_address);
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;;
while(0 == (S0SPSR&0x80));;
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
for(i=0;i<u16_cnt;i++)
{
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
*(Store_temp+i) = S0SPDR;
}
// IOSET = AT45DB_CS;
IOSET = AT45DB_CS;
while(!(IOPIN&Rdy_busy));
}
//*************************************************************************************************************
//-------------------------------------------------------
//---------------Buffer2_To_Write_AT45 (uint16 u16_page);....---u16_page为主存的页地址.------
//---------------SPI,转缓存2写入主存页中---------------
//-------------------------------------------------------
//*************************************************************************************************************
void Buffer2_To_Write_AT45 (uint16 u16_page)
{
IOCLR = AT45DB_CS;
IOCLR = AT45DB_CS;
S0SPDR = 0x86;
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_page>>5);
while(0 == (S0SPSR&0x80));
S0SPDR = ( (uint8)(u16_page))<<3;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
IOSET = AT45DB_CS;
IOSET = AT45DB_CS;
while(!(IOPIN&Rdy_busy));
}
//*************************************************************************************************************
//-------------------------------------------------------
//---Write_Buffer1_AT45();.---u16_address为缓存1的起始地址,u16_Counter为要写入的字节数.store_data写入数据的起始字节地址....
//---------------SPI,写缓存1---------------
//-------------------------------------------------------
//*************************************************************************************************************
void Write_Buffer2_AT45 (uint16 u16_address,uint16 u16_Counter,uint8 *store_data)
{
uint16 u16_cnt;
IOCLR = AT45DB_CS;
IOCLR = AT45DB_CS;
S0SPDR = 0x87;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_address>>8);
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_address);
while(0 == (S0SPSR&0x80));
for(u16_cnt=0;u16_cnt<u16_Counter;u16_cnt++)
{
S0SPDR = *(store_data+u16_cnt);
while(0 == (S0SPSR&0x80));
}
IOSET = AT45DB_CS;
IOSET = AT45DB_CS;
while(!(IOPIN&Rdy_busy));
}
//*************************************************************************************************************
//-------------------------------------------------------
//---Main_to_Buffer1_AT45();.---u16_page为主存的页地址....
//---------------SPI,主存页的内容转到缓存1中---------------
//-------------------------------------------------------
//*************************************************************************************************************
void Main_to_Buffer2_AT45(uint16 u16_page)
{
IOCLR = AT45DB_CS;
IOCLR = AT45DB_CS;
S0SPDR = 0x55;
while(0 == (S0SPSR&0x80));
S0SPDR = (uint8)(u16_page>>5);
while(0 == (S0SPSR&0x80));
S0SPDR = ( (uint8)(u16_page))<<3;
while(0 == (S0SPSR&0x80));
S0SPDR = 0x00;
while(0 == (S0SPSR&0x80));
IOSET = AT45DB_CS;
IOSET = AT45DB_CS;
while(!(IOPIN&Rdy_busy));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -