/* Buffer to Main Memory Page Program with Built-in Erase.  */
unsigned char AT45DBxxxDBuftoMm(unsigned char ucBufferNum, unsigned long ulPageAddr)
/* Buffer to Main Memory Page Program with Built-in Erase.  */
unsigned char AT45DBxxxDBuftoMm(unsigned char ucBufferNum, unsigned long ulPageAddr)
{
    unsigned int i = 0;
    if(ulPageAddr >= AT45DBxxxDInfo.ulTatalPages) return AT45DBxxxD_OP_INVALID;
    while(!AT45DBxxxDWaitReady())
    {
    	if(++i > AT45DBxxxD_OVERTIME)
    	{
    		return AT45DBxxxD_OP_BUSY;
    	}
    }
    AT45DBxxxD_CS_CLR;
    if (ucBufferNum == AT45DBxxxD_BUF1)
    {
    	SPISingleDataReadWrite(AT45DBxxxD_SPI_PORT, AT45DBxxxD_CMD_B1TMW);
    }
    else
    {
    	SPISingleDataReadWrite(AT45DBxxxD_SPI_PORT, AT45DBxxxD_CMD_B2TMW);
    }
    AT45DBxxxDWritePageAddr(ulPageAddr);
    AT45DBxxxD_CS_SET;
    return AT45DBxxxD_OP_OK;
}