void NAND_Init()
{
*(unsigned int *)(0x20030000 + 0xd0) = 7; delay_x(0X5000);
*(unsigned int *)(0x20030000 + 0xd0) = 6; delay_x(0X5000);
*(unsigned int *)(0x200f0000 + 0x1fc) = 0;//muxctrl_reg127 NF_DQ0 管脚复用控制寄存器
*(unsigned int *)(0x200f0000 + 0x200) = 0;
*(unsigned int *)(0x200f0000 + 0x204) = 0;
*(unsigned int *)(0x200f0000 + 0x208) = 0;
*(unsigned int *)(0x200f0000 + 0x20C) = 0;
*(unsigned int *)(0x200f0000 + 0x210) = 0;
*(unsigned int *)(0x200f0000 + 0x214) = 0;
*(unsigned int *)(0x200f0000 + 0x218) = 0;//7
*(unsigned int *)(0x200f0000 + 0x21C) = 0;
*(unsigned int *)(0x200f0000 + 0x220) = 0;
//p626
*(unsigned int *)(NANDC_ADDR +0X00) = 0x85;//NFC_CON
*(unsigned int *)(NANDC_ADDR +0X04) = 0x666;//NFC_PWIDTH 为读写脉冲宽度配置寄存器。
*(unsigned int *)(NANDC_ADDR +0X24) = 0x0;//NFC_INTEN 为中断使能寄存器
delay_x(0X500);
}
void NAND_Read_Page()
{
*(unsigned int *)(NANDC_ADDR +0X10) = 0x0;//NFC_ADDRL 为低位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X14) = 0x0;//NFC_ADDRH 为高位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X0c) = 0x00003000;//NFC_CMD 为命令字配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X18) = 0x800;
delay_x(0X500);
//地址周期 cmd1_en addr_wen data_wen cmd2_en ready/busy data_ren read_stus_en
*(unsigned int *)(NANDC_ADDR +0X1c) = 5<<9 | 1<<6 | 1<<5 | 0<<4 | 1<<3 |1<<2 | 1<<1 | 0;//0xa6e;//NFC_OP 为操作寄存器。
delay_x(0X500);
retu = *(unsigned int *)(NANDC_ADDR +0X20) ;//NFC_STATUS 为状态寄存器。
delay_x(0X5000);
}
void NAND_Read_Random()
{
*(unsigned int *)(NANDC_ADDR +0X10) = 0x0;//NFC_ADDRL 为低位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X14) = 0x0;//NFC_ADDRH 为高位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X0c) = 0x0000e005;//NFC_CMD 为命令字配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X18) = 0x20;
delay_x(0X500);
//*(unsigned int *)(NANDC_ADDR +0X1c) = 0x46e;//NFC_OP 为操作寄存器。
//地址周期 cmd1_en addr_wen data_wen cmd2_en ready/busy data_ren read_stus_en
*(unsigned int *)(NANDC_ADDR +0X1c) = 2<<9 | 1<<6 | 1<<5 | 0<<4 | 1<<3 |1<<2 | 1<<1 | 0;////NFC_OP 为操作寄存器。
delay_x(0X500);
retu = *(unsigned int *)(NANDC_ADDR +0X20) ;//NFC_STATUS 为状态寄存器。
delay_x(0X5000);
}
void NAND_Write_Page()
{
*(unsigned int *)(NANDC_ADDR +0X10) = 0x0;//NFC_ADDRL 为低位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X14) = 0x0;//NFC_ADDRH 为高位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X0c) = 0x00001080;//NFC_CMD 为命令字配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X18) = 8;
delay_x(0X500);
*(unsigned int *)(0x50000000) = 0x11223344;
delay_x(0X500);
*(unsigned int *)(0x50000004) = 0x55667788;
delay_x(0X500);
// *(unsigned int *)(NANDC_ADDR +0X1c) = 0xa7d;//NFC_OP 为操作寄存器。
//地址周期 cmd1_en addr_wen data_wen cmd2_en ready/busy data_ren read_stus_en
*(unsigned int *)(NANDC_ADDR +0X1c) = 5<<9 | 1<<6 | 1<<5 | 1<<4 | 1<<3 |1<<2 | 0<<1 | 0;//NFC_OP 为操作寄存器。
delay_x(0X500);
retu = *(unsigned int *)(NANDC_ADDR +0X20) ;//NFC_STATUS 为状态寄存器。
delay_x(0X5000);
}
void NAND_ReadID()
{
*(unsigned int *)(NANDC_ADDR +0X10) = 0x20;//NFC_ADDRL 为低位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X14) = 0x0;//NFC_ADDRH 为高位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X0c) = 0x00000090;//NFC_CMD 为命令字配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X18) = 5;
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X1c) = 0x266;//NFC_OP 为操作寄存器。
delay_x(0X500);
retu = *(unsigned int *)(NANDC_ADDR +0X20) ;//NFC_STATUS 为状态寄存器。
delay_x(0X5000);
}
void NAND_Erase_Block()
{
*(unsigned int *)(NANDC_ADDR +0X10) = 0x0;//NFC_ADDRL 为低位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X14) = 0x0;//NFC_ADDRH 为高位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X0c) = 0x0070d060;//NFC_CMD 为命令字配置寄存器。
delay_x(0X500);
//*(unsigned int *)(NANDC_ADDR +0X1c) = 0x66c;//NFC_OP 为操作寄存器。
//地址周期 cmd1_en addr_wen data_wen cmd2_en ready/busy data_ren read_stus_en
*(unsigned int *)(NANDC_ADDR +0X1c) = 3<<9 | 1<<6 | 1<<5 | 0<<4 | 1<<3 |1<<2 | 0<<1 | 0;//0xa6e;//NFC_OP 为操作寄存器。
delay_x(0X500);
retu = *(unsigned int *)(NANDC_ADDR +0X20) ;//NFC_STATUS 为状态寄存器。
delay_x(0X5000);
}
int NAND_test(unsigned int data)
{
int i=0;
UART_Init();
NAND_Erase_Block();
//写数据
*(unsigned int *)(NANDC_ADDR +0X10) = 0x0;//NFC_ADDRL 为低位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X14) = 0x0;//NFC_ADDRH 为高位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X0c) = 0x00001080;//NFC_CMD 为命令字配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X18) = 0x800;
delay_x(0X500);
for(i=0;i {
*(unsigned int *)(0x50000000 + i*4) = data;
delay_x(0X500);
}
// *(unsigned int *)(NANDC_ADDR +0X1c) = 0xa7d;//NFC_OP 为操作寄存器。
//地址周期 cmd1_en addr_wen data_wen cmd2_en ready/busy data_ren read_stus_en
*(unsigned int *)(NANDC_ADDR +0X1c) = 5<<9 | 1<<6 | 1<<5 | 1<<4 | 1<<3 |1<<2 | 0<<1 | 0;//NFC_OP 为操作寄存器。
delay_x(0X500);
retu = *(unsigned int *)(NANDC_ADDR +0X20) ;//NFC_STATUS 为状态寄存器。
//读数据
NAND_Read_Page();
//随即读
*(unsigned int *)(NANDC_ADDR +0X10) = 0x0;//NFC_ADDRL 为低位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X14) = 0x0;//NFC_ADDRH 为高位地址配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X0c) = 0x0000e005;//NFC_CMD 为命令字配置寄存器。
delay_x(0X500);
*(unsigned int *)(NANDC_ADDR +0X18) = 0x800;
delay_x(0X500);
//*(unsigned int *)(NANDC_ADDR +0X1c) = 0x46e;//NFC_OP 为操作寄存器。
//地址周期 cmd1_en addr_wen data_wen cmd2_en ready/busy data_ren read_stus_en
*(unsigned int *)(NANDC_ADDR +0X1c) = 2<<9 | 1<<6 | 1<<5 | 0<<4 | 1<<3 |1<<2 | 1<<1 | 0;////NFC_OP 为操作寄存器。
delay_x(0X500);
retu = *(unsigned int *)(NANDC_ADDR +0X20) ;//NFC_STATUS 为状态寄存器。
//判断数据是否正确。
for(i=0;i {
retu = *(unsigned int *)(0x50000000 + i*4);
if(retu != data)
return 1;
delay_x(0X500);
}
return 0;
}