* x25045的讀寫程序 用c51寫的 */
#define CS P2.7 /*單片機(jī)p2.7為片選 可以改為你的實(shí)際引腳 */
#define SO P2.6 /*數(shù)據(jù)輸出 */
#define SK P2.5 /* 時(shí)鐘 */
#define SI P2.4 /* 數(shù)據(jù)輸入*/
/* here is the instrution of x25045*/
#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)
/* 寫入一個(gè)字節(jié),cData為寫入的數(shù),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)
/* 讀入一個(gè)字節(jié),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;
-
單片機(jī)
+關(guān)注
關(guān)注
6037文章
44562瀏覽量
635913 -
程序
+關(guān)注
關(guān)注
117文章
3788瀏覽量
81102 -
x25045
+關(guān)注
關(guān)注
0文章
9瀏覽量
13986
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論