设为首页 - 加入收藏 - 网站地图 我爱嵌入式(www.52embed.com),专注嵌入式开发技术!
当前位置:主页 > 嵌入式软件 > 正文

C8051F020单片机操作NAND FLASH源码

时间:2015-05-13 21:26 来源:未知 作者:admin 阅读:
void Comm_Latch_Cycle(uchar COMMAND)
{
     unsigned char SFRPAGE_SAVE;
SFRPAGE_SAVE = SFRPAGE;
SFRPAGE = CONFIG_PAGE;
P7MDOUT = 0xFF; 
     RE=1;
WE=1;
ALE=0; 
CLE=1;
 
     P7=COMMAND;                         //WRITE COMMAND
WE=0;
WE=0;
WE=1;
WE=1;
CLE=0;
SFRPAGE = SFRPAGE_SAVE;
}
 
//------------------ 传送地址------------------------------
void Add_Latch_Cycle(ulong  rolAdd,uint colAdd)//传送地址,ADDR为页地址,从addr页第0字节开始
{
unsigned char SFRPAGE_SAVE;
     SFRPAGE_SAVE = SFRPAGE;
     SFRPAGE = CONFIG_PAGE; 
P7MDOUT = 0xFF;
RE=1;
  CLE=0;
ALE=1;
WE=1;
 
     P7 = colAdd;                      //A0-A7,column address
     WE=0;
WE=0;
     WE=1;
  WE=1;
 
     P7 = colAdd>>8;                  //A8-A10,column address
     WE=0;
WE=0;
     WE=1;
WE=1;
 
     P7=rolAdd;                         //A11-A18 
     WE=0;
WE=0;
     WE=1;
WE=1;
 
     P7=rolAdd>>8;                     //A19-A26
     WE=0;
WE=0;
     WE=1;
WE=1;
 
     P7=rolAdd>>16;                     //A27
     WE=0;
WE=0;
     WE=1;
WE=1;
 
ALE=0;
 
     SFRPAGE=SFRPAGE_SAVE;
}
 
 
void Page_Read_to_Buff(ulong page_number,uint colAdd,uchar *p,uint len)
   { 
 
SFRPAGE = CONFIG_PAGE;
Comm_Latch_Cycle(0x00);
Add_Latch_Cycle(page_number,colAdd); 
Comm_Latch_Cycle(0x30);
SFRPAGE = CONFIG_PAGE;
P7MDOUT = 0x00; 
RB = 1;  
while(!RB);
while(len--)
{
P7 = 0xFF;
RE = 1;
RE = 1;
RE = 0;
RE = 0;
*(p++)=P7;
RE = 1;
}
 
 }
 
 
void Write_Buff_to_Page(ulong page_val,uint colAdd,uchar *p_buff,uint len)
{   
    
    uint i;
    Comm_Latch_Cycle(0x80);
    Add_Latch_Cycle(page_val,colAdd);
    SFRPAGE = CONFIG_PAGE;
P7MDOUT = 0xFF;
for(i=0;i<len;i++)
        { 
 
      P7 =*p_buff++;
      WE=0; 
  WE=0;
      WE=1; 
  WE=1;
        }
 
    Comm_Latch_Cycle(0x10);
SFRPAGE = CONFIG_PAGE;
RB = 1;
while(!RB);
 
}

uchar Status_Read(void)   //when flash program ok,return 0 else 1    
{
uchar Status;
    Comm_Latch_Cycle(0x70);
Status=Read_Byte();
Status=Status & 0x01;
return Status;   //status=0 erease ok else failled
}
/*
void Write_Byte(unsigned char Wdata)    //Write a data to Flash
{
BYTE SFRPAGE_SAVE;
SFRPAGE_SAVE=SFRPAGE;
SFRPAGE=CONFIG_PAGE;
WE=1;
P7=Wdata;
WE=0;    
WE=0; 
WE=1;
WE=1;
SFRPAGE=SFRPAGE_SAVE;
}*/
 
uchar Read_Byte(void)              //read one byte from flash
{
   uchar Rdata;
char SFRPAGE_SAVE = SFRPAGE; 
SFRPGCN=CONFIG_PAGE;
P7MDOUT = 0x00;                     //Data Bus input mode
   P7 = 0xFF;
   RE=1;
   RE=0;
   RE=0;   
   Rdata=P7;
   RE=1; 
SFRPAGE = SFRPAGE_SAVE;
        return(Rdata); 
}

(责任编辑:admin)

顶一下
(0)
0%
踩一下
(0)
0%
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。