anboli
Full Member level 2
- Joined
- Mar 9, 2012
- Messages
- 144
- Helped
- 4
- Reputation
- 8
- Reaction score
- 4
- Trophy points
- 1,298
- Activity points
- 2,513
i had interfaced the DS1307 for the EEPROM memory with 89s52,
im giving the direct value to the specified memory address and its no problem while writing, same way while reading also no problem,
but when im passing an argument to the specified memory address, and then i dono whether it write the same data or not and im reading the value from that address means i giving a wrong data.
and i having the doubt, whether we can pass argument?
i posted my program here, could you help me please?:-(
im giving the direct value to the specified memory address and its no problem while writing, same way while reading also no problem,
but when im passing an argument to the specified memory address, and then i dono whether it write the same data or not and im reading the value from that address means i giving a wrong data.
and i having the doubt, whether we can pass argument?
i posted my program here, could you help me please?:-(
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 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 ************************************************************************** #include <at89x52.h> #include "i2c_rtc.h" sbit str = P3^0; sbit stp = P3^1; sbit set = P3^2; sbit up = P3^3; sbit down = P3^4; sbit ok = P3^5; sbit buzzer = P1^5; unsigned char count, count1; void hex2dec_sc(unsigned int l); void hex2dec_mn(unsigned int k); void monitor(); void sc_set(); void delay(); void start_count(); void stop_count(); void store_data(); void stop_count_set(); void write_init(int wr_value,wr_value1); void read_init(); void write_run(); void read_run(); /////***********************************************************************************///// void delay(unsigned int count) { int i,j; for(i=0;i<count;i++) // 100 ====> 1.5s && 1000 ====> 15s for(j=0;j<1275;j++); } ////////************************************************************************************** void hex2dec_mn(unsigned int k) { int x,x1,x2; x = k/10; //quotient x1 = k%10; //remainder x2 = x1<<4; P0 = (x2|x); //displaying the counting value in P0 } ////******************************************************************************************* void hex2dec_sc(unsigned int l) { int x,x1,x3; x = l/10; //quotient x1 = l%10; //remainder x3 = x<<4; P2 = (x3|x1); } //********************************************************************************************* void start_count() { while(1) { monitor(); stop_count(); read_init(); if(count1==0xffff) { count1=59; if(count==0) { count=10; stop_count(); } count = count-1; } count1= count1-1; write_init(count,count1); delay(130); } } ////******************************************************************************************* void monitor() { unsigned int set_data=00; if(set==0) { while(1) { hex2dec_mn(set_data); if(up==0) { set_data = set_data+1; if(set_data==60)set_data=0; count = set_data; hex2dec_mn(count); delay(30); } if(down==0) { set_data = set_data-1; if(set_data==0xffff)set_data=59; count = set_data; hex2dec_mn(count); delay(30); } if(ok==0) { delay(100); sc_set(); } } } } ////***************************************************************************************** void sc_set() { unsigned int set_data1=00; while(1) { hex2dec_sc(set_data1); if(up==0) { set_data1 = set_data1+1; if(set_data1==60)set_data1=0; count1 = set_data1; hex2dec_sc(count1); delay(30); } if(down==0) { set_data1 = set_data1-1; if(set_data1==0xffff)set_data1=59; count1 = set_data1; hex2dec_sc(count1); delay(30); } if(ok==0) { hex2dec_mn(count); hex2dec_sc(count1); delay(20); while(str==1); start_count(); } } } ////***************************************************************************************** void stop_count() { if(stp==0) { while(str==1); { start_count(); } } } ////***************************************************************************************** void write_init(unsigned char wr_value, wr_value1) /// receiving the arguement { start(); send_byte(0xd0); aknowledge(); send_byte(0x08); aknowledge(); send_byte(wr_value); aknowledge(); send_byte(wr_value1); aknowledge(); stop(); } ////***************************************************************************************** void read_init() { unsigned char romvalue,romvalue1; start(); send_byte(0xd0); aknowledge(); send_byte(0x08); aknowledge(); start(); send_byte(0xd1); aknowledge(); romvalue = read_byte(); aknowledge(); romvalue1 = read_byte(); aknowledge(); stop(); count = romvalue; count1 = romvalue1; hex2dec_mn(count); hex2dec_sc(count1); } ////***************************************************************************************** void main() { P0 = 0x00; P2 = 0x00; P3 = 0xff; str = 1; stp = 1; set = 1; up = 1; down = 1; ok = 1; buzzer = 0; count = 10; count1 = 45; write_init(count,count1); ////argument passing here while(1) { read_init(); monitor(); while(str==0) { start_count(); } } } *************************************************************************
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 *******************************I2C program********************************* #include "intrins.h" sbit sda = P1^7; //sbit sda=P2^0; sbit scl = P1^6; //sbit scl=P2^1; bit ack; unsigned char reead,Day; 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 }
Last edited by a moderator: