anoop kr
Member level 4
Hai all....after a long time i am joining with you....
For the last four days i was in trouble with one program..It was interfacing the serial memory 24c32 (I2C) with P89V51RD2.The microcontroller P89V51RD2 is based on 8051 architecture...The whole protocol that i wrote in assembly and it worked.But the same thing when i write in C language, it is not working completely.That is in assembly, i can perform both writing and reading to and from the EEPROM(24C32).When the program that wrote in C, only writing to the memeory is happening,the reading couldn't take place..I tried a lot in different ways and when i am searching in internet it shows the same code that i had written...Somebody please help me.. I am giving the code that i wrote and the picture of the proteus simulation..
For the last four days i was in trouble with one program..It was interfacing the serial memory 24c32 (I2C) with P89V51RD2.The microcontroller P89V51RD2 is based on 8051 architecture...The whole protocol that i wrote in assembly and it worked.But the same thing when i write in C language, it is not working completely.That is in assembly, i can perform both writing and reading to and from the EEPROM(24C32).When the program that wrote in C, only writing to the memeory is happening,the reading couldn't take place..I tried a lot in different ways and when i am searching in internet it shows the same code that i had written...Somebody please help me.. I am giving the code that i wrote and the picture of the proteus simulation..
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 #include <REGX51.H> #define SCL P0_0 #define SDA P0_1 void INIT_I2C(); void DELAY(); void SEND_DATA(int); void SEND_DATA1(int); void GET_DATA(); //void ACK(); //void NAK(); //void MACK(); void START(); void STOP(); /************ MAIN PROGRAMME STARTS HERE ***************/ void main() { INIT_I2C(); START(); SEND_DATA(0XA0); SEND_DATA(0X00); SEND_DATA(0X33); STOP(); START(); SEND_DATA(0XA0); SEND_DATA(0X00); START(); SEND_DATA(0XA1); GET_DATA(); STOP(); while(1); } /********************** ******************/ /**** DELAY PGM ****/ void DELAY() { unsigned int p; for(p=0;p<3;p++); } /***** *****/ void INIT_I2C() { SDA=1; SCL=1; } void START() { SDA=1; DELAY(); SCL=1; DELAY(); SDA=0; DELAY(); SCL=0; } void STOP() { SCL=1; DELAY(); SDA=0; //DELAY(); SDA=1; DELAY(); SCL=0; } void SEND_DATA(int x) { int Z,i,k; Z=x; k=x; for(i=0;i<8;i++) { Z&=(0x80); if(Z==0x80) { SDA=1; SCL=1; DELAY(); SCL=0; } else { SDA=0; SCL=1; DELAY(); SCL=0; } k<<=1; Z=k; } while(SDA==1); SCL=1; DELAY(); SCL=0; SDA=0; } void SEND_DATA1(int x) { int Z,i,k; Z=x; k=x; for(i=0;i<8;i++) { Z&=(0x80); if(Z==0x80) { SDA=1; SCL=1; DELAY(); SCL=0; } else { SDA=0; SCL=1; DELAY(); SCL=0; } k<<=1; Z=k; } } void GET_DATA() { unsigned char i,Data=0X00; for(i=0;i<=8;i++) { // SCL = 0; SCL = 1; // DELAY(); Data|=SDA; Data<<=1; SCL=0; // SCL=1; } // SCL = 0; SDA = 1; SCL=1; DELAY(); SCL=0; P2=Data; SDA=0; } /* void ACK() { while(SDA==1); SCL=1; DELAY(); SCL=0; } void NAK() { SCL=1; DELAY(); SDA=1; DELAY(); SCL=1; DELAY(); SCL=0; } void MACK() { SDA=0; SCL=1; DELAY(); SCL=0; } */
Please format your image attachments properly, use gif, png, or jpeg extension instead of BMP to reduce the size of the file.
Image replaced with .png
Last edited by a moderator: