我要跳楼了!!!25045的问题!急死我了!!!!!
我在写25045的问题!!用C语言写的!现在可以写进去了!可读出来就不一样啊!写入“0X00”时读出来是对的!可写其他的数据读出来是“0XCC”!不知道什么原因!我也延时了!可读出来不对!那位大虾看看!程序在下面!!谢谢了!
#include <reg52.h>
#include <intrins.h>
#define Nop() _nop_()
#define WREN 0x06
#define WRDI 0x04
#define RDRS 0x05
#define WRSR 0x01
#define READ0 0x03
#define READ1 0x0B
#define WRITE0 0x02
#define WRITE1 0x0a
sbit cs=P1^0;
sbit so=P1^1;
sbit sck=P1^2;
sbit si=P1^3;
sbit com=P1^7;
unsigned char dd;
void delay(unsigned int x)
{
while(x--)
{
}
}
/************读8位数据*************/
unsigned char Read8()
{
unsigned char cloop;
unsigned char cData=0;
for(cloop=0;cloop <8;cloop++)
{
sck=1;
Nop();
Nop();
Nop();
Nop();
Nop();
sck=0;
Nop();
Nop();
Nop();
Nop();
Nop();
cData < <=1;
if(so==1)
{
cData=cData+1;
}
}
sck=0;
return cData;
}
/***********写8位数据*****************/
void Write8(unsigned char cData)
{
unsigned char cloop;
for(cloop=0;cloop <8;cloop++)
{
if((cData&0x80)==0)
{
si=0;
}
else
{
si=1;
}
sck=0;
sck=1;
cData < <=1;
}
sck=0;
}
/***************读寄存器状态**************/
unsigned char ReadSR()
{
unsigned char cData;
cs=0;
Write8(RDRS);
cData=Read8();
sck=0;
cs=1;
return cData;
}
/************写寄存器状态*************/
void WriteSR(unsigned char cData)
{
unsigned char cTemp;
cTemp=ReadSR();
while((cTemp&0x01)==1)
{com=1;}
cs=0;
Write8(WREN);
cs=1;
cs=0;
Write8(WRSR);
cs=0;
Write8(cData);
sck=0;
cs=1;
}
/******************写1个字节*****************/
void write1b(unsigned char address,unsigned char cData)
{cs=0;
while(ReadSR()&0x01)
{com=1;}
cs=0;
Write8(WREN);
cs=1;
cs=0;
Write8(WRITE0);
Write8(address);
Write8(cData);
sck=0;
cs=1;
}
/**************************页写入数据函数***************/
void writepage(unsigned char address,unsigned char bb[],unsigned char k )
{
unsigned char i;
cs=0;
while(ReadSR()&0x01)
{com=1;}
cs=0;
Write8(WREN);
cs=1;
cs=0;
Write8(WRITE0);
Write8(address);
for(i=0;i <k;i++)
Write8(bb[i]);
cs=1;
sck=0;
}
/*********************读一个字节*****************/
unsigned char read1b(unsigned char address)
{
//unsigned char cData=0;
while(ReadSR()&0x01)
{
com=1;}
cs=0;
Write8(READ0);
Write8(address);
dd=Read8();
sck=0;
cs=1;
return dd;
}
main()
{unsigned char xx[4]={0xff,0xff,0x0f,0xf0};
WriteSR(0x30);
write1b(0x40,0x00);
delay(3000);
writepage(0x50,xx,4);
read1b(0x40);
delay(100);
if(dd==0x00)
//write1b(0x70,dd);
while(1)
{
com=0;
}
else
while(1)
{com=1;}
}
发表时间:2004年7月27日15:44:34