NAND FLASH的读写程序.txt
上传用户:luntai
上传日期:2013-03-02
资源大小:1k
文件大小:3k
- NAND FLASH的读写程序(注意片选)
- 【浩惠电子 http://www.hheet.com/bbs 版权所有】
- FLASH是K9F5608U0B,32M
- #include<INIT_REG.H>
- #define FLASH_MD1 0xeff0 //chip enable nand flash 1
- #define FLASH_MD2 0xfff0 //chip enable nand flash 2
- #define FLASH_MA1 0xeff2 //enable address nand flash 1
- #define FLASH_MA2 0xfff2 //enable address flash 2
- #define FLASH_MC1 0xeff1 //enable command nand flash 1
- #define FLASH_MC2 0xfff1 //enable command nand flash 2
- #define read_id 0x90
- void read_flash_id(void);
- void page_write_flash(unsigned char addrlow,addrmid,addrhigh);
- void read_flash(unsigned char addrlow,addrmid,addrhigh);
- void delay();
- void flash_reset();
- void main(void)
- {
- unsigned char i=0,j=0;
- init_snd1();
- flash_reset();
- read_flash_id();
- page_write_flash(0x0,0x0,0x0);
- read_flash(0x0,0x0,0x0);
- while(1);
- }
- void flash_reset()
- {
- unsigned char xdata *xaddress;
- xaddress=FLASH_MC1;
- *xaddress=0xff;
- delay();
-
- }
- void read_flash_id(void) // 串口输出ID码
- {
- unsigned char xdata *xaddress;
- unsigned char x,y;
- xaddress=FLASH_MC1;
- *xaddress=read_id;
- xaddress=FLASH_MA1;
- *xaddress=0x00;
- xaddress=FLASH_MD1;
- x=*xaddress;
- printf(x);
- y=*xaddress;
- printf(y);
- }
- void page_write_flash(unsigned char addrlow,addrmid,addrhigh)
- {
- unsigned char xdata *buff;
- unsigned char temp;
- unsigned int i;
- //erase flash block
- buff=FLASH_MC1;
- *buff=0x60;
- buff=FLASH_MA1;
- *buff=addrmid;
- *buff=addrhigh;
- buff=FLASH_MC1;
- *buff=0xd0;
- delay();
- do{
- buff=FLASH_MC1;
- *buff=0x70;
- buff=FLASH_MD1;
- temp=*buff;
- printf(temp);
- temp=temp&0x01;
- }
- while(temp!=0x00);
- //while(1);
- //erase sucessfull
- //write one page data
- buff=FLASH_MC1;
- *buff=0x80;
- buff=FLASH_MA1;
- *buff=addrlow;
- *buff=addrmid;
- *buff=addrhigh;
- buff=FLASH_MD1;
- for(i=0;i<512;i++)
- {
-
- *buff=i;
- printf(i);
- }
- buff=FLASH_MC1;
- *buff=0x10;
- delay();
- do{
- buff=FLASH_MC1;
- *buff=0x70;
- buff=FLASH_MD1;
- temp=*buff;
- printf(temp);
- temp=temp&0x41;
- }
- while(temp!=0x40);
- }
- void read_flash(unsigned char addrlow,addrmid,addrhigh)
- {
- unsigned char xdata *source;
- unsigned int i,temp;
- source=FLASH_MC1;
- *source=0x00;
- source=FLASH_MA1;
- *source=addrlow;
- *source=addrmid;
- *source=addrhigh;
- delay();
- do{
- source=FLASH_MC1;
- *source=0x70;
- source=FLASH_MD1;
- temp=*source;
- printf(temp);
- temp=temp&0x40;
- }
- while(temp!=0x40);
- source=FLASH_MD1;
- i=512;
- while((i--)>0)
- {
- temp=*source;
- printf(temp);
- }
- }
- void delay()
- {
- unsigned int temp;
- for (temp=0; temp<3000;temp++) ;
- }