Tarneem
Newbie level 6
- Joined
- Mar 25, 2015
- Messages
- 11
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 264
PIC18F4550 Real time clock using MikroC_Need help PLZ~
Hi to All ,
I have to designe a smart digital clock, I am using PIC18F4550 and ds1307 RTC chip for generating a real time clock. I have the following code which compiles successfully on MikroC compiler. And I test it on proteus it is giving me a good results.
My problem is in real connection , I burn the code by Pickit2 burner , and i made the same connection wich is in proteus program , but the button dose not perform any thing ,, when I prees it nothing is shown , but in protuse the buttons work successfully right.
Now m Here is:
1- the code in C langage --> work fine no errors:thumbsup:
2- CKT connection in protuse --> no problems at all :thumbsup:
3- the real connection --> doeasnot perform right :thumbsdown:
2- proteus connection CKT diagram :
**broken link removed**http://www.up-00.com/
3- Real Connection Picture :
**broken link removed**http://www.up-00.com/
I have tried to change a lot of things and I have tried to research on how to solve this problem but am still facing the same problem. So can someone help me with this...
Please , I m really in trouble ..
Thank u ~
Hi to All ,
I have to designe a smart digital clock, I am using PIC18F4550 and ds1307 RTC chip for generating a real time clock. I have the following code which compiles successfully on MikroC compiler. And I test it on proteus it is giving me a good results.
My problem is in real connection , I burn the code by Pickit2 burner , and i made the same connection wich is in proteus program , but the button dose not perform any thing ,, when I prees it nothing is shown , but in protuse the buttons work successfully right.
Now m Here is:
1- the code in C langage --> work fine no errors:thumbsup:
2- CKT connection in protuse --> no problems at all :thumbsup:
3- the real connection --> doeasnot perform right :thumbsdown:
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 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 // LCD module connections sbit LCD_RS at RB3_bit; sbit LCD_EN at RB2_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB3_bit; sbit LCD_EN_Direction at TRISB2_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections #define set PORTC.F0 #define alarm_set PORTC.F4 #define inc PORTC.F1 #define next PORTC.F2 #define dec PORTC.F5 #define salrm PORTC.F6 //#define buttons set_time(); //time/date/day set function display(); //time/date/day display function alarm(); //alarm set function char day1=1; // Size spaces char date1[]="00"; char mon1[]="00"; char year1[]="00"; char hr1[]="00"; char min11[]="00"; char sec1[]="00"; char k,x; unsigned short date=0,hour=0, mon=0, year=0x00, sec=0,min1=0; unsigned short hr; unsigned short ap; int alarm_min, alarm_hour; unsigned short read_ds1307(unsigned short address) { unsigned short r_data; I2C1_Start(); I2C1_Wr(0xD0); //address 0x68 followed by direction bit (0 for write, 1 for read) 0x68 followed by 0 --> 0xD0 I2C1_Wr(address); I2C1_Repeated_Start(); I2C1_Wr(0xD1); //0x68 followed by 1 --> 0xD1 r_data=I2C1_Rd(0); I2C1_Stop(); return(r_data); } void write_ds1307(unsigned short address,unsigned short w_data) { I2C1_Start(); // issue I2C start signal I2C1_Wr(0xD0); // send byte via I2C (device address + W) I2C1_Wr(address); // send byte (address of DS1307 location) I2C1_Wr(w_data); // send data (data to be written) I2C1_Stop(); // issue I2C stop signal } unsigned char BCD2UpperCh(unsigned char bcd) { return ((bcd >> 4) + '0'); } unsigned char BCD2LowerCh(unsigned char bcd) { return ((bcd & 0x0F) + '0'); } int Binary2BCD(int a) { int t1, t2; t1 = a%10; t1 = t1 & 0x0F; a = a/10; t2 = a%10; t2 = 0x0F & t2; t2 = t2 << 4; t2 = 0xF0 & t2; t1 = t1 | t2; return t1; } int BCD2Binary(int a) { int r,t; t = a & 0x0F; r = t; a = 0xF0 & a; t = a >> 4; t = 0x0F & t; r = t*10 + r; return r; } void day(char d) // Function for display day on LCD { switch(d) { case 0: // print("DAY"); Lcd_Out_Cp("DAY"); break; case 1: //print("SUN"); Lcd_Out_Cp("SUN"); break; case 2: //print("MON"); Lcd_Out_Cp("MON"); break; case 3: //print("TUE"); Lcd_Out_Cp("TUE"); break; case 4: //print("WED"); Lcd_Out_Cp("WED"); break; case 5: //print("THU"); Lcd_Out_Cp("THU"); break; case 6: //print("FRI"); Lcd_Out_Cp("FRI"); break; case 7: //print("SAT"); Lcd_Out_Cp("SAT"); break; } } void main() { I2C1_Init(100000); //DS1307 I2C is running at 100KHz ADCON1 = 0x0F ; CMCON = 0x07 ; TRISD0_bit=0; TRISD1_bit=0; PORTD=0; // LED Off initially Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,2,"Smart Digital"); Lcd_Out(2,6,"Clock"); Delay_ms(1000); Lcd_Cmd(0x01); while(1) { if(set==0) //check alarm set button press { k=1; set_time(); // call time set function write_ds1307(2, hour); write_ds1307(1, min1); write_ds1307(3, day1); write_ds1307(4, date); write_ds1307(5,mon); write_ds1307(6,year ); write_ds1307(0,sec); } if(alarm_set==0) //check alarm set button press { alarm(); //call alarm set function while(alarm_set==0); k=5; } hour= read_ds1307(2); //Read Hour //hr = hour & 0b00011111; if((hour& 0x1F) >= 0x13) { hour = hour & 0b11100001; hour = hour ^ 0x20; } if((hour& 0x1F) <= 0x00) { hour = hour | 0b00000001; //hour = hour ^ 0x20; } min1= read_ds1307(1); //Read minutes sec= read_ds1307(0); //Read seconds day1= read_ds1307(3); //Read The day of the week (sunday to saturday) date= read_ds1307(4); //Read The day of the week (1st to 31st) mon= read_ds1307(5); //Read month year= read_ds1307(6); //Read year Lcd_Cmd(0x0c); if(hour==alarm_hour && min1==alarm_min) // check alarm time with real time { k=7; if((sec>88) ||(salrm==0) ){PORTD=0;k=0; alarm_min=0; } PORTD=1; //alarm output set Delay_ms(350); //1 Second Delay PORTD= 0; //LED OFF } else { PORTD=0; //alarm output reset } display(); //display time/date/day Delay_ms(100); } } set_time() { Lcd_Cmd(0x0e); while(k<7) { while(k==3) //set date { x=year%4; if(inc==0) { date = BCD2Binary(date); date++;while(inc==0); // day = day + set; date = Binary2BCD(date); if(date >= 0x32) date = 1; //if(day <= 0) // day = 0x31; // check for 30 day month if(date==50){date=1;} // check for 31 day month display();} if(dec==0) { date = BCD2Binary(date); date--;while(dec==0); date = Binary2BCD(date); if(date <= 0) date = 0x31; display();} if(next==0){k=4;while(next==0);} //check for next digit Lcd_Cmd(0x81); } while(k==2) //set month { if(inc==0) { mon++;while(inc==0); if(mon==10){mon=mon+6;} if(mon==19){mon=1;} //check for end of year display(); } if(dec==0) { mon = BCD2Binary(mon); mon--;while(dec==0); mon = Binary2BCD(mon); // if(mon > 0x12) // mon = 1; if(mon <= 0) mon = 0x12; display(); } if(next==0){k=3;while(next==0);} Lcd_Cmd(0x84); } while(k==1) //set year { if(inc==0) { year++;while(inc==0); if(year==10){year=year+6;} if(year==26){year=year+6;} if(year==41){year=0;} display(); } if(dec==0) { year = BCD2Binary(year); year--;while(dec==0); year = Binary2BCD(year); if(year <= -1) year = 0x99; if(year >= 0x50) year = 0; display(); } if(next==0){k=2;while(next==0);} Lcd_Cmd(0x89); } while(k==4) //set day { if(inc==0) { day1++;while(inc==0); if(day1==8){day1=1;} display(); } if(dec==0) { day1--;while(dec==0); if(day1<1){day1=7;} display(); } if(next==0){ k=5;while(next==0); } Lcd_Cmd(0x8f); } while(k==5) //set hour { if(inc==0) { hour = BCD2Binary(hour); hour++;while(inc==0); hour = Binary2BCD(hour); if((hour& 0x1F) >= 0x13) { hour = hour & 0b11100001; hour = hour ^ 0x20; } display(); } if(dec==0) { hour = BCD2Binary(hour); hour--;while(dec==0); hour = Binary2BCD(hour); if((hour& 0x1F) <= 0x00) { hour = hour | 0b00010010; hour = hour ^ 0x20; } display(); } if(next==0){ k=6;while(next==0); } Lcd_Cmd(0xc1); } while(k==6) //set min { if(inc==0) { min1 = BCD2Binary(min1); min1++;while(inc==0); if(min1 >= 60) min1 = 0; // if(min1 < 0) // min1 = 59; min1 = Binary2BCD(min1); display();} if(dec==0) { min1 = BCD2Binary(min1); min1--;while(dec==0); // if(min1 >= 60) // min1 = 0; if(min1 < 0) min1 = 59; min1 = Binary2BCD(min1); display();} if(next==0){k=10;while(next==0);} Lcd_Cmd(0xc4); } } } display() { Lcd_Cmd(0x80); date1[0]=BCD2UpperCh(date); date1[1]=BCD2LowerCh(date); Lcd_Out_Cp(date1); Lcd_Cmd(0x82); Lcd_Out_Cp("/"); //print("/"); Lcd_Cmd(0x83); mon1[0]=BCD2UpperCh(mon); mon1[1]=BCD2LowerCh(mon); Lcd_Out_Cp(mon1); //lcdnum(mon); Lcd_Cmd(0x85); Lcd_Out_Cp("/20"); //print("/20"); Lcd_Cmd(0x88); year1[0]=BCD2UpperCh(year); year1[1]=BCD2LowerCh(year); Lcd_Out_Cp(year1); //lcdnum(year); Lcd_Cmd(0x8a); Lcd_Out_Cp(" "); //print(" "); Lcd_Cmd(0x8c); day(day1); Lcd_Cmd(0xc0); hr = hour & 0b00011111; //hr = hour; ap = hour & 0b00100000; hr1[0]=BCD2UpperCh(hr); hr1[1]=BCD2LowerCh(hr); Lcd_Out_Cp(hr1); if(ap) { Lcd_Cmd(0xc8); Lcd_Out_Cp("PM"); } else { Lcd_Cmd(0xc8); Lcd_Out_Cp("AM"); } //lcdnum(hour); Lcd_Cmd(0xc2); Lcd_Out_Cp(":"); // print(":"); Lcd_Cmd(0xc3); min11[0]=BCD2UpperCh(min1); min11[1]=BCD2LowerCh(min1); Lcd_Out_Cp(min11); //lcdnum(min); Lcd_Cmd(0xc5); Lcd_Out_Cp(":"); // print(":"); Lcd_Cmd(0xc6); sec1[0]=BCD2UpperCh(sec); sec1[1]=BCD2LowerCh(sec); Lcd_Out_Cp(sec1); //lcdnum(sec); if(k==7) { if(sec%2==0) { Lcd_Cmd(0xca); // Lcd_Out_Cp("alarm"); // print("ALARM"); } else { //Lcd_Out_Cp(" "); //print(" "); } } else if(k==5) { Lcd_Cmd(0xca); Lcd_Out_Cp(" ");; } else { //Lcd_Cmd(0xca); //Lcd_Out_Cp("alarm"); } } alarm() // set alarm { unsigned int k=1; alarm_hour=0, alarm_min=0; hour=alarm_hour; min1=alarm_min; Lcd_Cmd(0x0e); Lcd_Cmd(0x01); Lcd_Out_Cp("Alarm set :"); Delay_ms(500); display(); while(k<3) //set hour for alarm { while(k==1) { if(inc==0) { alarm_hour = BCD2Binary(alarm_hour); alarm_hour++;while(inc==0); alarm_hour = Binary2BCD(alarm_hour); hour=alarm_hour; if((alarm_hour& 0x1F) >= 0x13) { alarm_hour = alarm_hour & 0b11100001; alarm_hour = alarm_hour ^ 0x20; hour=alarm_hour; } display(); } if(dec==0) { alarm_hour = BCD2Binary(alarm_hour); alarm_hour--;while(dec==0); alarm_hour = Binary2BCD(alarm_hour); hour=alarm_hour; if((alarm_hour& 0x1F) <= 0x00) { alarm_hour = alarm_hour | 0b00010010; alarm_hour = alarm_hour ^ 0x20; hour=alarm_hour; } display(); } if(next==0){ k=2;while(next==0); } Lcd_Cmd(0xc1); } //set min for alarm while(k==2) { if(inc==0) { alarm_min = BCD2Binary(alarm_min); alarm_min++;while(inc==0); if(alarm_min >= 60) alarm_min = 0; // if(min1 < 0) // min1 = 59; alarm_min = Binary2BCD(alarm_min); min1=alarm_min; display();} if(dec==0) { alarm_min = BCD2Binary(alarm_min); alarm_min--;while(dec==0); // if(min1 >= 60) // min1 = 0; if(alarm_min < 0) alarm_min = 59; alarm_min = Binary2BCD(alarm_min); min1=alarm_min; display();} if(next==0){k=3;while(next==0);} Lcd_Cmd(0xc4); } } }
2- proteus connection CKT diagram :
**broken link removed**http://www.up-00.com/
3- Real Connection Picture :
**broken link removed**http://www.up-00.com/
I have tried to change a lot of things and I have tried to research on how to solve this problem but am still facing the same problem. So can someone help me with this...
Please , I m really in trouble ..
Thank u ~