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

📄 norflash.c

📁 NORflash的应用
💻 C
字号:

#include "config.h"

uchar norflash_check(uint dst)
{
    uchar SR;
	uint  i = 0;
	uint  j = 0;
	
	*(pchar)dst = 0x70;
	SR = *(pchar)dst;
	
	if((SR & 0x80) == 0x80)
	    return TRUE;
	else
	    return FALSE;
}	  

void norflash_erase_block(uint dst)
{
    uint i;
	uchar ReturnStatus;
	
	*(pchar)dst = 0x20;
	*(pchar)dst = 0xd0;
	
	//for(i=0;i<5000;i++);
	
	while(1)
	{
	    ReturnStatus = norflash_check(dst);
	    if(ReturnStatus)    break;
	}
	*(pchar)dst = 0x50;
	*(pchar)dst = 0xff;
}	  

void norflash_write_char(uint dst , uchar src)
{
    uint i;
	uchar ReturnStatus;
	
	*(pchar)dst = 0x40;
	*(pchar)dst = src;
	
    //for(i=0;i<10;i++);
	
	while(1)
	{
	    ReturnStatus = norflash_check(dst);
	    if(ReturnStatus)    break;
	}
	*(pchar)dst = 0x50;
	*(pchar)dst = 0xff;
}

uchar norflash_read_char(uint dst)
{
    uchar i;
	
	*(pchar)dst = 0xff;
    i = *(pchar)dst;
	
	return i;
}		

void norflash_reset(uint dst)
{
    *(pchar)dst = 0xff;
}			

uint norflash_address_convert(ulong src)
{	
    uint dst;
	uint CS;
	
	if(src < 0x100000)
	{
		CS  = 0xb000;
	}
	else    if(src < 0x200000)
	{
	    src -= 0x100000;
		CS   = 0xc000;
    }
	
	*(pchar)0x8000 = src >> 12;
	src &= 0x0fff;
	dst  = src;
	dst += CS;
	
	return dst;
}	

void norflash_write_str(uint dst ,uchar *src ,uint size)
{
    uchar ReturnStatus;
	uint  i;
	uchar data;
	 
	for(i=0;i<size;i++)
	{
	    data = *(src++);
      norflash_write_char(dst++,data);
	}
}	

uchar norflash_read_str(uint src ,uint size)
{
    uint i;
	uchar *dst ;
	
	*(pchar)src = 0xff;
	
	for(i=0;i<size;i++)
	{
	    *(dst++) = norflash_read_char(src++);
	}
	
	return *dst;
}	 

void norflash_write_int(uint dst, uint src)
{
    norflash_write_char(dst++,src>>8);
	norflash_write_char(dst++,src);
}

uint norflash_read_int(uint src)
{
    uchar i, j;
	
    *(pchar)src = 0xff;
	
	i = norflash_read_char(src++);
	j = norflash_read_char(src++);
	return ((i<<8) + j) ;
}
    	         

       
        
		
		

⌨️ 快捷键说明

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