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); }
Thank you Christian for the reply.
the problem is, i just started to learn the debugging in keil. so i used the proteus to simulate, after writing the code, i run the simulation. when i checked the eeprom's memory nothing is there.
i learned, there is lot of mistakes. the main one, i think that i missed to write the status register.
now i can communicate with spi eeprom.
i corrected my code as you said. but still i don't know why my code is not working, I used the bit addressable bdata.
Thank you.
Hi,
maybe this helps...
http://www.keil.com/support/docs/1863.htm
Christian.
Thank you again Christian,
i learned about bdata.