I have interfaced P3.3to scl & sda to p3.4......... #include<REGX51.H> #include<stdio.h> #define LCD_DELAY=56 void acknowlg(); void start(); void stop(); void read(); void write(unsigned char p); void delay(unsigned int ms); int a,b,c,d,i; void main()//operate eeprom. { stop(); start(); write(0xA0); acknowlg(); write(0xAA); acknowlg(); P1_2=0; //write(0xFF); acknowlg(); stop(); delay(1); start(); write(0xA1); acknowlg(); read(); stop(); P3=d; P1=d; while(1); } void delay(unsigned int ms)//1 ms delay(variable). { unsigned int n; unsigned int i;
for (n=0; n<=ms; n++) { for (i=0;i<LCD_DELAY;i++); }
} void start()//start the communication (h to L) { P3=0x00; P3_4=1; P3_3=1; delay(1); P3_4=0; delay(1); P3_3=0; } void stop()//stop the communication(L to h) { P3_4=0; P3_3=1; delay(1); P3_4=1; delay(1); P3_3=0; } void write(unsigned char p)//write in serial order { P3=0x00; P2=p; for(a=0;a<8;a++) { P3_3=1; delay(1); P3_4=P2_7; delay(1); P2=P2<<1; P3_3=0; } P3=1; delay(2); P3=0;
BUT UNABLE TO DO IT PLS TELL ABT ACKNOWLEDGE FUNCTION AND CODE FOR ME IF POSSIBLE.............. } void acknowlg()//seek acknowledgement from memory { //P3=0xFF; P3_3=1; delay(1); while(P3_4==0) { } delay(1); P3_3=0; } void read()//to read byte from eeprom. {
for(b=0;b<3;b++) { i=P3_4; P3_3=1;//set as input. delay(2); P3_3=0; P3=P3<<1; } P3_3=1; delay(2); P3_3=0;
for(b=0;b<4;b++) { //P3_3=1;//set as input. delay(2); P3_3=0; P3=P3>>1; } acknowlg(); P3_3=1; delay(2); P3_3=0; }
Do you thing your code looks readable? Did you check what it looked like in the preview? Repost the code, but this time following the posting instructions for code!
Second: Don't you think you should expand a bit on your question?
BUT UNABLE TO DO IT PLS TELL ABT ACKNOWLEDGE FUNCTION AND CODE FOR ME IF POSSIBLE..............
Unable to do what? What do you expect should happen? What happens? What steps have you taken to figure out the problem?
Please read the instructions on how to post source code: www.danlhenry.com/.../keil_code.png
Note that TABs don't work (well) - use spaces instead,
and don't forget to check it in the 'Preview'...
i am interfacing atmel eeprom with 8051 .....in my program i have made all dfferent functions for start ,stop,acknowledge read & write functions.....................then i have called simply called 1.start & 2 written serially 0xA0(default address for 16A eeprom). 3.asked for acknowledge from slave (eeprom)by checking low on SDA. 4.then written data say, 0xaa then again gone for ack. 5 then i done reading after which ihave put the same byte in P2 to which i have connected leds .........but iam not geting anything i have written..... (please relook my code now)
yourcodeisvirtuallyunreadable.
ifyouseriouslywantareplyisuggestyoureenteritsothatitcanbereadbyothers.
understand??
It hasn't changed - it's still illegible!