cpubbs论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

LabVIEW+单片机学习套件全套教程资料下载[免费]LabVIEW论坛精华列表贴USB0816数据采集卡《LabVIEW宝典》
LabWindows/CVI论坛精华贴NET0816以太网数据采集卡RC0210远程设备授权系统 关闭关停锁定打开设备 户外分布式数据采集
NET1624低速高精度以太网数据采集卡WIFI0824SD无线WIFI网络数据采集卡脱机运行 SD存储 小尺寸微型 串口采集远程采集 安卓 手持移动采集 纪录仪
查看: 1304|回复: 0

W29C020C.rar(1K)来一份见面礼,W29C020C的读写程序,请大家指教(神采飞扬)[转贴]

[复制链接]
发表于 2004-11-6 02:16:47 | 显示全部楼层 |阅读模式
<>#include&lt;REG51.H&gt;
#include&lt;INTRINS.H&gt;
#include&lt;ABSACC.H&gt;
#include&lt;MATH.H&gt;
#include&lt;stdio.h&gt;</P>
<>#define Uchar unsigned char
#define Uint  unsigned int
#define Ulong unsigned long</P>
<>sbit ChipSelect=P1^4;
sbit BankPort0=P1^0;
sbit BankPort1=P1^1;
sbit WriteEn=P3^6;
sbit Led=P1^2;
bit  ErrorFlag=0;</P>
<P>void DelayMS ( Uchar TMS )
{
Uchar i,j;
for ( i=4*TMS;i&gt;0;i-- )
  for ( j=200;j&gt;0;j-- );
}</P>
<P>/*入口参数:Address为欲读地址,0&lt;=Address&lt;=0x3ffff,既0-256k
  出口参数:所读数据,0-0xff
如:data=ReadByte(0x2ffffL);注意:一定要在地址后加L
*/
Uchar ReadByte ( Ulong Address )
{
Uchar Banksel,ReadData;
Uint  BankAddress;
if ( Address&gt;=0l&amp;&amp;Address&lt;=0xffffl ){Banksel=0;BankAddress=Address;}
if ( Address&gt;=0x10000l&amp;&amp;Address&lt;=0x1ffffl ){Banksel=1;BankAddress=Address-0x10000l;}
if ( Address&gt;=0x20000l&amp;&amp;Address&lt;=0x2ffffl ){Banksel=2;BankAddress=Address-0x20000l;}
if ( Address&gt;=0x30000l&amp;&amp;Address&lt;=0x3ffffl ){Banksel=3;BankAddress=Address-0x30000l;}
// else { ErrorFlag=1;goto ReadError; }
switch(Banksel)
  {
  case 0:BankPort0=0;BankPort1=0;break;
  case 1:BankPort0=1;BankPort1=0;break;
  case 2:BankPort0=0;BankPort1=1;break;
  case 3:BankPort0=1;BankPort1=1;break;
}
ChipSelect=0;
ReadData=XBYTE[BankAddress];
  _nop_();
  _nop_();
ChipSelect=1;
return ( ReadData );
// ReadError: ;
}</P>
<P>/*入口参数:Address为欲写数据的起始地址,该地址应为128的整数倍,包括0L,注意:一定要在地址后加L
   WriteData为待写数据,0&lt;=WriteData&lt;=0xff
如:for(i=0;i&lt;=127;i++)
   WriteByte ( 0x30000L,i );
则可以把0-127写到0x30000L-0x3007fL
如果要写0xbb到芯片的0x30001L,则需写成:
   WriteByte ( 0x30000L,ReadByte(0x30000L) );
   WriteByte ( 0x30001L,0xbb );
   for ( i=0;i&lt;126;i++ )
WriteByte ( 0x30002L+i,ReadByte(0x30002L+i) );
这样才可以保证其他地址内容不变
*/
void WriteByte ( Ulong Address,Uchar WriteData )
{
Uchar Banksel;
Uint  BankAddress;
if      ( Address&gt;=0&amp;&amp;Address&lt;=0xffff ){Banksel=0;BankAddress=Address;}
else if ( Address&gt;=0x10000l&amp;&amp;Address&lt;=0x1ffffl ){Banksel=1;BankAddress=Address-0x10000l;}
else if ( Address&gt;=0x20000l&amp;&amp;Address&lt;=0x2ffffl ){Banksel=2;BankAddress=Address-0x20000l;}
else {Banksel=3;BankAddress=Address-0x30000l;}//if ( Address&gt;=0x30000l&amp;&amp;Address&lt;=0x3ffffl )
// else { ErrorFlag=1;goto WriteError; }
switch(Banksel)
  {
  case 0:BankPort0=0;BankPort1=0;break;
  case 1:BankPort0=1;BankPort1=0;break;
  case 2:BankPort0=0;BankPort1=1;break;
  case 3:BankPort0=1;BankPort1=1;break;
  default :break;
}
ChipSelect=0;
XBYTE[BankAddress]=WriteData;
if ( ((BankAddress+1)%128)==0 )DelayMS ( 10 );
     ChipSelect=1;
}</P>
<P>void DisableProtect ( void )//禁止软件写保护
{
WriteByte ( 0x5555,0xaa );
WriteByte ( 0x2aaa,0x55 );
WriteByte ( 0x5555,0x80 );
WriteByte ( 0x5555,0xaa );
WriteByte ( 0x2aaa,0x55 );
WriteByte ( 0x5555,0x20 );
DelayMS ( 10 );
}</P>
<P>void EarseChip ( void )    //整片擦除为0xff,一般不调用
{
WriteByte ( 0x5555,0xaa );
WriteByte ( 0x2aaa,0x55 );
WriteByte ( 0x5555,0x80 );
WriteByte ( 0x5555,0xaa );
WriteByte ( 0x2aaa,0x55 );
WriteByte ( 0x5555,0x10 );
DelayMS ( 50 );
}</P>
<P>void main ( void )
{
Ulong i;
DisableProtect ( );
EarseChip ( );
for ( i=0x0000l;i&lt;=0x3ffffl;i++ )
{
WriteByte ( i,0x99 );
}
P1=ReadByte ( 0x2ffffL );
while(1);
}
</P>
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|cpubbs论坛. ( 粤ICP备09171248号 )

GMT+8, 2025-4-4 02:33 , Processed in 0.981391 second(s), 7 queries , Gzip On, File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表