NguyenHai said:Hi,
I have program for read and write data to ds1307. Use keil complier.
Best regard.
Dear Freind..
can u give me that particular code in C...i have similar project based on 8051-XTAl 11.0592,DS1307 and lcd...can u give me ..pls as i m tired up from one week..no code is working provided on the net...i hope ur code will work.,.
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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 #include<reg51.h> #include<intrins.h> sbit rs=P0^0; sbit en=P0^1; sbit sda=P3^6; sbit scl=P3^7; unsigned char rtc_adr[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06}; unsigned char rtc_dat[8]={0x20,0x58,0x23,0x05,0x31,0x12,0x03}; unsigned char dis[7]={0x20,0x20,0x28,0x08,0x0c,0x06,0x80}; unsigned char a,b,c,d; void strt_bt(); void stp_bt(); void dta_wr(); void dta_rd(); void cmdwrt(); void datawrt(); void delay(); void rtc_wr(); void rtc_rd(); void display(); main() { int i; for (i=0;i<7;i++) { a=dis[i]; cmdwrt(); delay(); } P0=0x00; for(i=0;i<8;i++) { b=rtc_adr[i]; c=rtc_dat[i]; rtc_wr(); } while(1) { a=0x80; cmdwrt(); delay(); b=0x04; //date rtc_rd(); display(); a='/'; datawrt(); delay(); b=0x05; //month rtc_rd(); display(); a='/'; datawrt(); delay(); b=0x06; //yr rtc_rd(); display(); a='-'; datawrt(); delay(); b=0x03; //week rtc_rd(); display(); a=0xc0; cmdwrt(); delay(); b=0x02; //hr rtc_rd(); display(); a=':'; datawrt(); delay(); b=0x01; //min rtc_rd(); display(); a=':'; datawrt(); delay(); b=0x00; //sec rtc_rd(); display(); } } void rtc_wr() { strt_bt(); //write a=0xd0; dta_wr(); a=b; dta_wr(); a=c; dta_wr(); stp_bt(); delay(); } void rtc_rd() { strt_bt(); //dummy write a=0xd0; dta_wr(); a=b; dta_wr(); strt_bt(); //read a=0xd1; dta_wr(); dta_rd(); /* sda=1; scl=1; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); scl=0; */ stp_bt(); delay(); } void strt_bt() { sda=1; scl=1; _nop_(); _nop_(); sda=0; _nop_(); _nop_(); _nop_(); _nop_(); scl=0; _nop_(); _nop_(); } void stp_bt() { //scl=0; sda=0; scl=1; _nop_(); _nop_(); //_nop_(); //_nop_(); //_nop_(); sda=1; _nop_(); _nop_(); _nop_(); _nop_(); scl=0; _nop_(); _nop_(); _nop_(); _nop_(); scl=1; } void dta_wr() { int j; char m; m=a; sda=1; for(j=0;j<8;j++) { a=m; a=a & 0x80; if(a==(0x80)) sda=1; else sda=0; scl=1; _nop_(); _nop_(); _nop_(); _nop_(); scl=0; m=m<<1; } sda=1; scl=1; _nop_(); _nop_(); _nop_(); _nop_(); scl=0; delay(); } void dta_rd() { int j; int c=0,b; sda=1; for(j=0;j<8;j++) { a=a<<1; scl=1; c=sda; if(c) b=0x01; else b=0x00; scl=0; a=a|b; } sda=1; //_nop_(); //_nop_(); //_nop_(); //_nop_(); scl=1; _nop_(); _nop_(); _nop_(); scl=0; //datawrt(); delay(); } void display() { d=a; a=(a>>4); a=a & 0x0f; a=a + 0x30; datawrt(); delay(); a=d; a=a & 0x0f; a=a + 0x30; datawrt(); delay(); } void cmdwrt() { unsigned char s=0; s=a; a=a & 0xf0; a=a>>2; rs=0; P0=a; rs=0; en=1; en=0; a=s; a=(a<<4); a=a & 0xf0; a=a>>2; rs=0; P0=a; rs=0; en=1; en=0; delay(); } void datawrt() { unsigned char s=0; s=a; a=a & 0xf0; a=a>>2; rs=1; //mdata(); //delay(); P0=a; rs=1; en=1; en=0; a=s; a=a<<4; a=a & 0xf0; a=a>>2; rs=1; //mdata(); P0=a; rs=1; en=1; en=0; delay(); } void delay() { int i; for(i=0;i<1000;i++); }
first i want to know that the value of RTC where r u displaying in lcd/seven segment.
i have the perfect code of RTC interfacing and display on lcd.
but the code is in c.
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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 #include<reg51.h> #include<intrins.h> sbit rs=P0^0; sbit en=P0^1; sbit sda=P3^6; sbit scl=P3^7; unsigned char rtc_adr[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06}; unsigned char rtc_dat[8]={0x20,0x58,0x23,0x05,0x31,0x12,0x03}; unsigned char dis[7]={0x20,0x20,0x28,0x08,0x0c,0x06,0x80}; unsigned char a,b,c,d; void strt_bt(); void stp_bt(); void dta_wr(); void dta_rd(); void cmdwrt(); void datawrt(); void delay(); void rtc_wr(); void rtc_rd(); void display(); main() { int i; for (i=0;i<7;i++) { a=dis[i]; cmdwrt(); delay(); } P0=0x00; for(i=0;i<8;i++) { b=rtc_adr[i]; c=rtc_dat[i]; rtc_wr(); } while(1) { a=0x80; cmdwrt(); delay(); b=0x04; //date rtc_rd(); display(); a='/'; datawrt(); delay(); b=0x05; //month rtc_rd(); display(); a='/'; datawrt(); delay(); b=0x06; //yr rtc_rd(); display(); a='-'; datawrt(); delay(); b=0x03; //week rtc_rd(); display(); a=0xc0; cmdwrt(); delay(); b=0x02; //hr rtc_rd(); display(); a=':'; datawrt(); delay(); b=0x01; //min rtc_rd(); display(); a=':'; datawrt(); delay(); b=0x00; //sec rtc_rd(); display(); } } void rtc_wr() { strt_bt(); //write a=0xd0; dta_wr(); a=b; dta_wr(); a=c; dta_wr(); stp_bt(); delay(); } void rtc_rd() { strt_bt(); //dummy write a=0xd0; dta_wr(); a=b; dta_wr(); strt_bt(); //read a=0xd1; dta_wr(); dta_rd(); /* sda=1; scl=1; _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); scl=0; */ stp_bt(); delay(); } void strt_bt() { sda=1; scl=1; _nop_(); _nop_(); sda=0; _nop_(); _nop_(); _nop_(); _nop_(); scl=0; _nop_(); _nop_(); } void stp_bt() { //scl=0; sda=0; scl=1; _nop_(); _nop_(); //_nop_(); //_nop_(); //_nop_(); sda=1; _nop_(); _nop_(); _nop_(); _nop_(); scl=0; _nop_(); _nop_(); _nop_(); _nop_(); scl=1; } void dta_wr() { int j; char m; m=a; sda=1; for(j=0;j<8;j++) { a=m; a=a & 0x80; if(a==(0x80)) sda=1; else sda=0; scl=1; _nop_(); _nop_(); _nop_(); _nop_(); scl=0; m=m<<1; } sda=1; scl=1; _nop_(); _nop_(); _nop_(); _nop_(); scl=0; delay(); } void dta_rd() { int j; int c=0,b; sda=1; for(j=0;j<8;j++) { a=a<<1; scl=1; c=sda; if(c) b=0x01; else b=0x00; scl=0; a=a|b; } sda=1; //_nop_(); //_nop_(); //_nop_(); //_nop_(); scl=1; _nop_(); _nop_(); _nop_(); scl=0; //datawrt(); delay(); } void display() { d=a; a=(a>>4); a=a & 0x0f; a=a + 0x30; datawrt(); delay(); a=d; a=a & 0x0f; a=a + 0x30; datawrt(); delay(); } void cmdwrt() { unsigned char s=0; s=a; a=a & 0xf0; a=a>>2; rs=0; P0=a; rs=0; en=1; en=0; a=s; a=(a<<4); a=a & 0xf0; a=a>>2; rs=0; P0=a; rs=0; en=1; en=0; delay(); } void datawrt() { unsigned char s=0; s=a; a=a & 0xf0; a=a>>2; rs=1; //mdata(); //delay(); P0=a; rs=1; en=1; en=0; a=s; a=a<<4; a=a & 0xf0; a=a>>2; rs=1; //mdata(); P0=a; rs=1; en=1; en=0; delay(); } void delay() { int i; for(i=0;i<1000;i++); }
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?