This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Interfacting 89c51 with SPI EEPROM

Hi, i am trying to interface 89c51 with a EEPROM (SPI)(25aa080a). i written the code but it's not working.

the code is below. if there is any mistakes please correct me.

i am trying to interface it in proteus.

thank you.

#include <REGX51.H>
#include <intrins.H>

#define nop _nop_();_nop_();_nop_();_nop_();

sbit sck = P2^0;
sbit swr = P2^1;
sbit srd = P2^2;
sbit cs  = P2^3;

unsigned char bdata wdata;
//sfr wdata = 0xa0;

sbit shift7 = wdata^7;

void msdelay(unsigned int ms)
{
        int i,j;
        for(i=0;i<=ms;i++)
        for(j=0;j<=122;j++);
}

void start()
{
        cs = 1;
        nop;
        cs = 0;
}

void stop()
{
        cs = 0;
        nop;
        cs = 1;
}

void write(char wdata)
{

 unsigned char bit_count = 0;

        while(bit_count<8)
        { swr = shift7;
          sck=0;
                  _nop_();
          sck=1;
                  _nop_();
          wdata = wdata<<1;
          bit_count++;
                 }
}

void main()
{

 start();
 write(0x06);  // write enable command
 msdelay(10);
 stop();
 msdelay(10);

 start();
 write(0x01);  // write enable command
 msdelay(10);
 write(0x00);  // write enable command
 msdelay(10);
 stop();
 msdelay(10);

 start();
 write(0x06);  // write enable command
 msdelay(10);
 stop();
 msdelay(10);

 start();
 write(0x02);  // write command
 msdelay(10);
 write(0x00);  // high byte address
 msdelay(10);
 stop();
 msdelay(10);

 start();
 write(0x02);
 msdelay(10);
 write(0x00);
 msdelay(10);
 write(0x40);  // low byte address
 msdelay(10);
 write(0x3f);  // data to write in spi eeprom
 msdelay(10);
 stop();
 while(1);

}


0