⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nand.c

📁 ADI BF561开发板nand flash驱动的代码
💻 C
字号:
#include "stdio.h"
#include "ccblkfn.h"
#include "sysreg.h"



#include "../CPLD.h"

#include "NAND_FLASH.h"

void Write_Command(unsigned char command)
{
	Set_CE(0);
	Set_CLE(1);
	if(command == 0x10)
		{
			Write_NAND_FLASH(command);
		}
	else
		{
			Write_NAND_FLASH(command);
			Set_CLE(0);
		}
}

void Write_Address(unsigned char NAND_Address0,unsigned char NAND_Address1,
				   unsigned char NAND_Address2,
				   unsigned char NAND_Address3,
				   unsigned char Valid_Address)
{	
	
	
		Set_ALE(1);
		if(Valid_Address == 1)
			{
				Write_NAND_FLASH(NAND_Address0);
			}
		else if(Valid_Address == 3)
			{
				Write_NAND_FLASH(NAND_Address0);
				Write_NAND_FLASH(NAND_Address1);
				Write_NAND_FLASH(NAND_Address2);
			}
		else 
			{
				Write_NAND_FLASH(NAND_Address0);
				Write_NAND_FLASH(NAND_Address1);
				Write_NAND_FLASH(NAND_Address2);	
				Write_NAND_FLASH(NAND_Address3);

			}
		Set_ALE(0);
	

}

bool Wait_NAND_RADY(void)
{
	while(*pFIO2_FLAG_D != 0x0400)
	{
		*pFIO2_INEN	= 0x0000;
		ssync();
		*pFIO2_FLAG_C = 0;
		ssync();
		*pFIO2_INEN	= 0x0400;
	}
	return true;
}

void NAND_Finish(void)
{
	Set_CE(1);
	Set_CLE(0);
	Set_ALE(0);
	Command_Status = 0;
}

/*****************************************************************/


void Write_NAND_FLASH(unsigned char Write_Data)
{
	*pNAND_BaseaAddr = Write_Data;
	delay(100);
}

void Set_CE(bool state)
{
	if(!state)
	{
		Command_Status = Command_Status | CLR_CE1;
		*pNAND_CtrlBaseaAddr = Command_Status;
	}
	else
	{
		Command_Status = Command_Status & SET_CE1;
		*pNAND_CtrlBaseaAddr = Command_Status;
	}
	delay(100);
}

void Set_CLE(bool state)
{
	delay(100);
	if(!state)
	{
		Command_Status = Command_Status & CLR_CLE;
		*pNAND_CtrlBaseaAddr = Command_Status;	
	}
	if(state)
	{
		Command_Status = Command_Status | SET_CLE;
		*pNAND_CtrlBaseaAddr = Command_Status;	
	}
	delay(100);
}

void Set_ALE(bool state)
{
	delay(100);
	if(!state)
	{
		Command_Status = Command_Status & CLR_ALE;
		*pNAND_CtrlBaseaAddr = Command_Status;	
	}
	if(state)
	{
		Command_Status = Command_Status | SET_ALE;
		*pNAND_CtrlBaseaAddr = Command_Status;	
	}
	delay(100);	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -