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

📄 2808.c

📁 用LPC93251操作nand flash K9F6408
💻 C
字号:
#include <reg932.h>
#include "mp3data4.h"

sbit flash_cle=P2^0;
sbit flash_ce=P2^4;
sbit flash_ale=P2^1;
sbit flash_we=P1^0;
sbit flash_re=P1^1;
sbit flash_rb=P2^7;

unsigned char xdata readdata[512] _at_ 0x00;
unsigned char data savedata[16] _at_ 0x70;
void read(unsigned int block,unsigned int page,unsigned char *buffer)  //读操作
{
   unsigned int i;
   unsigned int blockpage=(block<<4)+page;
//写命令
   flash_ce=0;  
   flash_cle=1;
   flash_we=0;
   P0=0x00;
   flash_we=1;
   flash_cle=0;
   flash_ale=1;

//写地址
   flash_we=0;
   P0=0x00;
   i++;
   flash_we=1;
   
   flash_we=0;
   P0=blockpage & 0xff;
   i++;
   flash_we=1;
   
   flash_we=0;
   P0=(blockpage>>8) & 0xff;
   i++;
   flash_we=1;
   flash_ale=0;
   
   while(!flash_rb);
   P0M1=0xff;
   P0M2=0x00;
   for(i=0;i<512;i++)
   {
      flash_re=0;
      *(buffer+i)=P0;
      flash_re=1;
   }
   P0M1=0x00;
   P0M2=0x00;  
   flash_ce=1;
}

void write(unsigned int block,unsigned int page, unsigned char *Buffer, unsigned char *buffer)  //写操作
{
   unsigned int i;
   unsigned int j;
   unsigned int blockpage=(block<<4)+page;
   flash_cle=0;
   flash_ce=0;
   flash_we=1;
   flash_ale=0;
   flash_re=1;
   for(i=0;i<3;i++);
//写命令  
   flash_cle=1;
   flash_we=0;
   P0=0x80;
   i++;
   flash_we=1;
   flash_cle=0;
   
   for(i=0;i<3;i++);
//写地址
   flash_ale=1;
   flash_we=0;
   P0=0x00;
   i++;
   flash_we=1;
   
   flash_we=0;
   P0=blockpage & 0xff;
   i++;
   flash_we=1;
   
   flash_we=0;
   P0=(blockpage>>8) & 0xff;
   i++;
   flash_we=1;
   flash_ale=0;
   for(i=0;i<3;i++);

  for(j=0;j<512;j++)
  {
      flash_we=0;
      P0=*Buffer++;
      i++;
      flash_we=1;     
  }
    
//写命令  
   flash_cle=1; 
   flash_we=0;
   P0=0x10;
   i++;
   flash_we=1;
//读状态
   flash_cle=1;
   flash_we=0;
   P0=0x70;
   i++;
   flash_we=1;
   flash_cle=0;
   P0M1=0xff;
   P0M2=0x00;
   while(!flash_rb);
   flash_re=0;
   *(buffer+6)=P0; 
   for(i=0;i<3;i++);
   flash_re=1;
   P0M1=0x00;
   P0M2=0x00; 
   
   flash_ce=1;
}

void erase_block(unsigned int block, unsigned char *buffer)
{
   unsigned int i;
   unsigned int blockpage=(block<<4);
   flash_cle=0;
   flash_ce=1;
   flash_we=1;
   flash_ale=0;
   flash_re=1;
   
//写命令
   flash_cle=1;
   flash_ce=0;
   flash_we=0;
   P0=0x60;
   i++;
   flash_we=1;
   for(i=0;i<3;i++);

//写页地址  
   flash_ale=1;
   flash_cle=0;
   flash_we=0;
   P0=blockpage & 0xff;
   i++;
   flash_we=1;  
   flash_we=0;
   P0=(blockpage>>8) & 0xff;
   i++; 
   flash_we=1;
   for(i=0;i<3;i++);

//写命令  
   flash_cle=1;
   flash_ale=0;
   flash_we=0;
   P0=0xd0;
   i++;
   flash_we=1;
   flash_cle=0;  
   for(i=0;i<10;i++);

//读状态
   flash_cle=1;
   flash_we=0;
   P0=0x70;
   i++;
   flash_we=1;
   flash_cle=0;
   P0M1=0xff;
   P0M2=0x00;
   while(!flash_rb);
   flash_re=0;
   *(buffer+5)=P0; 
   for(i=0;i<3;i++);
   flash_re=1; 
   P0M1=0x00;
   P0M2=0x00;
}
   
   
main(void)
{
   unsigned int flash_block=8;
   unsigned int flash_page;
//   unsigned char j=2;
   P0M1=0x00;
   P0M2=0x00;
   P1M1=0x00;
   P1M2=0x00;
   P2M1=0x80;
   P2M2=0x00;
     
    erase_block(flash_block,&savedata);
	 for(flash_page=0;flash_page<16;flash_page++)
     {
	   write(flash_block,flash_page,&mp3_data[flash_page*512],&savedata);
     }

	 for(flash_page=0;flash_page<16;flash_page++)
	 {
	   read(flash_block,flash_page,&readdata);
     }
   while(1);
}
   

⌨️ 快捷键说明

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