HI all, i need a small help from you all.... i am trying to interface AT24C32 eeprom with 89S52. my problem is it works perfectly with proteus stimultion but when i tried to built the circuit it give me an error... code... Code:
#include<reg51.h> #include<stdio.h> #include<intrins.h> //For using [_nop_()] sbit sda=P1^7; sbit scl=P1^6; sbit buz=P3^7; bit ack; void save(); void read(); void msdelay(unsigned int value) ; unsigned char reead,write,write2,i,j; unsigned int temp; unsigned char userid[7]={"444444"}; unsigned char chanuser[7]={"000000"}; void aknowledge() //acknowledge condition { scl=1; _nop_(); _nop_(); scl=0; } void start() //start condition { sda=1; scl=1; _nop_(); //No operation _nop_(); sda=0; scl=0; } void stop() //stop condition { sda=0; scl=1; _nop_(); _nop_(); sda=1; scl=0; } void send_byte(unsigned char value) //send byte serially { unsigned int i; unsigned char send; send=value; for(i=0;i<8;i++) { sda=send/128; //extracting MSB send=send<<1; //shiftng left scl=1; _nop_(); _nop_(); scl=0; } ack=sda; //reading acknowledge sda=0; } unsigned char read_byte() //reading from EEPROM serially { unsigned int i; sda=1; reead=0; for(i=0;i<8;i++) { reead=reead<<1; scl=1; _nop_(); _nop_(); if(sda==1) reead++; scl=0; } sda=0; return reead; //Returns 8 bit data here } void save() //save in EEPROM { start(); send_byte(0xA0); //device address aknowledge(); send_byte(0x00); //word address, Page Numbers aknowledge(); send_byte(userid[0]); aknowledge(); send_byte(userid[1]); aknowledge(); send_byte(userid[2]); aknowledge(); send_byte(userid[3]); aknowledge(); send_byte(userid[4]); //send data aknowledge(); send_byte(userid[5]); //send data aknowledge(); stop(); } void Read() { start(); send_byte(0xA0); aknowledge(); send_byte(0x00); aknowledge(); start(); send_byte(0xA1); //device address aknowledge(); chanuser[0]=read_byte(); aknowledge(); chanuser[1]=read_byte(); aknowledge(); chanuser[2]=read_byte(); aknowledge(); chanuser[3]=read_byte(); aknowledge(); chanuser[4]=read_byte(); aknowledge(); chanuser[5]=read_byte(); aknowledge(); stop(); } void main() { save(); msdelay(1000); read(); if(chanuser[i]=='4') { buz=0; msdelay(8000); buz=1; } else { buz=0; msdelay(400); buz=1; msdelay(400); buz=0; msdelay(400); buz=1; msdelay(400); buz=0; msdelay(400); buz=1; msdelay(400); buz=0; msdelay(400); buz=1; msdelay(400); } }//Main Ends Here void msdelay(unsigned int value) { unsigned int i,j; for(i=0;i<value;i++) for(j=0;j<100;j++); }
explaining the code... initailly it save the data's from userid to eeprom and then after a delay(1000) it again reads the data's from eerpom and saves it to chanuser. in main() program it checks if the data's of chanuser are as same as userid then LED lights up and if the data's are not as same as userid it starts blinking. but here as u can see the data's of userid and chanuser are same but still it blinks in my circuit. but works well with proteus stimulation. it does not works well with my circuit means eeprom is not working well... can anybody please help me out of this...
i need a small help from you all.... first help do not use the C251 tools the chip is C51.
well, maybe you are
my problem is it works perfectly with proteus stimultion but when i tried to built the circuit it give me an error..
the differences between simulation and real life are 1) hardware (do you have pullups in the lines?)(other things?) 2) timing, the simulator does not give a s... about timing these are the main differences
A very early step when software doesn't work would normally be to debug.
And debugging is the task of figuring out the difference between what is happening and what was assumed to happen.
You don't seem to have done any comparison between plan and reality.