/* Buffer to Main Memory Page Program with Built-in Erase.  */
void AT45DB161_Buf_to_Mm(unsigned char ucBufferNum, unsigned short usPageAddr)
/* Buffer to Main Memory Page Program with Built-in Erase.  */
void AT45DB161_Buf_to_Mm(unsigned char ucBufferNum, unsigned short usPageAddr)
{
    while(!AT45DB161_WaitReady());
    if (usPageAddr < AT45DB161_PAGES)
    {
        AT45DB161_CS = 0;
        if (ucBufferNum == AT45DB161_BUF1)SPISingleDataReadWrite(AT45DB161_SPI_PORT, AT45DB161_CMD_B1TMW);
        else SPISingleDataReadWrite(AT45DB161_SPI_PORT, AT45DB161_CMD_B2TMW);
        xSPISingleDataReadWrite(AT45DB161_SPI_PORT, (unsigned char)(usPageAddr >> 6));
        xSPISingleDataReadWrite(AT45DB161_SPI_PORT, (unsigned char)((usPageAddr & 0x003F) << 2));
        xSPISingleDataReadWrite(AT45DB161_SPI_PORT, 0x00);
        AT45DB161_CS = 1;
    }
}