最新的x25045驱动(C51)双通道读写驱动程序

来源:本站
导读:目前正在解读《最新的x25045驱动(C51)双通道读写驱动程序》的相关信息,《最新的x25045驱动(C51)双通道读写驱动程序》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《最新的x25045驱动(C51)双通道读写驱动程序》的详细说明。
简介:这是一款老的芯片驱动程序,它可兼容x25020的驱动C51编写。

/* x25045的读写程序 用c51写的 */

#define CS P2.7 /*单片机p2.7为片选 可以改为你的实际引脚 */

#define SO P2.6 /*数据输出 */

#define SK P2.5 /* 时钟 */

#define SI P2.4 /* 数据输入*/

#define WREN 0x06

#define WRDI 0x04

#define RDSR 0x05

#define WRSR 0x01

#define READ0 0x03

#define READ1 0x0b

#define WRITE0 0x02

#define WRITE1 0x0a

unsigned char Read8()

{

bit bData;

unsigned char cLoop;

unsigned char cData;

for(cLoop=0;cLoop<8;cLoop++)

{

SK=1;

SK=0;

bData=SO;

cData<<=1;

if(bData)

{

cData|=0x01;

}

}

return cData;

}

void Write8(unsigned char cData)

{

unsigned char cLoop;

for(cLoop=0;cLoop<8;cLoop++)

{

if((cData&0x80)==0)

{

SI=0;

}

else

{

SI=1;

}

SK=0;

SK=1;

cData<<=1;

}

}

unsigned char ReadSR()

{

unsigned char cData;

CS=0;

Write8(RDSR);

cData=Read8();

CS=1;

return cData;

}

unsigned char WriteSR(unsigned char cData)

{

unsigned char cTemp;

cTemp=ReadSR();

if((cTemp&0x01)==1)

return 0;

CS=0;

Write8(WREN);

CS=1;

CS=0;

Write8(WRSR);

Write8(cData);

CS=1;

return 1;

}

void Write1B(unsigned char cData,unsigned char cAddress,bit bRegion)

/* 写入一个字节,cData为写入的数,cAddress为写入地址,bRegion为页 */

{

while((ReadSR()&0x01)==1)

{

}

CS=0;

Write8(WREN);

CS=1;

CS=0;

if(bRegion==0)

{

Write8(WRITE0);

}

else

{

Write8(WRITE1);

}

Write8(cAddress);

Write8(cData);

SK=0;

CS=1;

}

unsigned char Read1B(unsigned char cAddress,bit bRegion)

/* 读入一个字节,cAddress为读入地址,bRegion为页 */

{

unsigned char cData;

while((ReadSR()&0x01)==1)

{

}

CS=0;

if(bRegion==0)

{

Write8(READ0);

}

else

{

Write8(READ1);

}

Write8(cAddress);

cData=Read8();

CS=1;

return cData;

}

提醒:《最新的x25045驱动(C51)双通道读写驱动程序》最后刷新时间 2024-03-14 01:07:56,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《最新的x25045驱动(C51)双通道读写驱动程序》该内容的真实性请自行鉴别。