RTC12C887 Interfacing Error

Discussion in 'The Projects Forum' started by scintrillating, Dec 30, 2011.

  1. scintrillating

    Thread Starter New Member

    Dec 30, 2011
    5
    0
    Guys...I am making a Real Time Clock using DS12c887 and 16X2 LCD...
    I following code works great to display seconds extracted from the RTC on the LCD but hours and minutes are not displayed in the way it should. They take any random value...Please find out the solution to it and suggest some debugging techniques...

    Try to simulate this using Proteus and you will see the error!

    Code ( (Unknown Language)):
    1.  
    2. #include <REGX51.H>
    3. #include<ABSACC.h>
    4.  
    5. #define port P3
    6. #define lcd_dataport P2  // lcd_dataport for lcd
    7. #define keypad P1  // Port for keypadpad
    8. #define timeport P0 // Port for RTC
    9.  
    10. sbit rs = port^0;
    11. sbit rw = port^1;
    12. sbit en = port^2;
    13.  
    14. sbit key0=keypad^0;
    15. sbit key1=keypad^1;
    16. sbit key2=keypad^2;
    17. sbit key3=keypad^3;
    18. sbit key4=keypad^4;
    19. sbit key5=keypad^5;
    20. sbit key6=keypad^6;
    21. sbit key7=keypad^7;
    22.  
    23. int hr, min, sec;
    24.  
    25. void delay(unsigned int msec) //Time delay function
    26. {
    27. int i,j ;
    28. for(i=0;i<msec;i++)
    29. for(j=0;j<1275;j++);
    30. }
    31.  
    32. void lcdcmd(unsigned char item) //Function to send command to LCD
    33. {
    34. lcd_dataport = item;
    35. rs= 0;
    36. rw=0;
    37. en=1;
    38. delay(1);
    39. en=0;
    40. return;
    41. }
    42.  
    43. void lcddata(unsigned char item) //Funtion to send data on LCD
    44. {
    45. lcd_dataport = item;
    46. rs= 1;
    47. rw=0;
    48. en=1;
    49. delay(1);
    50. en=0;
    51. }
    52.  
    53. void lcddata_string(unsigned char *str) // Function to send string on LCD
    54. {
    55. int i=0;
    56. while(str[i]!='\0')
    57. {
    58. lcddata(str[i]);
    59. i++;
    60. delay(1);
    61. }
    62. }
    63.  
    64. void lcd(unsigned char str[10])  // Funtion to Initialize LCD
    65. {
    66. lcdcmd(0x38);
    67. lcdcmd(0x0C);
    68. lcdcmd(0x01);
    69. lcdcmd(0x80);
    70. lcddata_string(str);
    71. }
    72.  
    73. void check_key()
    74. {
    75. if(key0==0)
    76. lcd("SET TIME");
    77. if(key1==0)
    78. lcd("Increment");
    79. if(key2==0)
    80. lcd("Decrement");
    81. if(key3==0)
    82. lcd("SET A");
    83. if(key4==0)
    84. lcd("SET B");
    85. if(key5==0)
    86. lcd("SET C");
    87. if(key6==0)
    88. lcd("SET BANGS");
    89. if(key7==0)
    90. lcd("SET GROUPS");
    91. }
    92.  
    93. void bcdconv(unsigned char mybyte)
    94. {
    95. unsigned char x,y;
    96. x=mybyte&0x0F;
    97. x=x|0x30;
    98. y=mybyte&0xF0;
    99. y=y>>4;
    100. y=y|0x30;
    101. lcddata(y);
    102. lcddata(x);
    103. }
    104.  
    105. void main()
    106. {
    107.         delay(220);
    108.         XBYTE[10]=0x20;
    109.         XBYTE[11]=0x82;
    110.         XBYTE[4]=0x16;
    111.         XBYTE[2]=0x56;
    112.         XBYTE[0]=0x41;
    113.         XBYTE[11]=0x02;
    114.         lcd("TIME:");
    115.         while(1)
    116.         {
    117.         lcdcmd(0x88);
    118.         hr=XBYTE[4];
    119.         bcdconv(hr);
    120.         lcddata(':');
    121.         min=XBYTE[2];
    122.         bcdconv(min);
    123.         lcddata(':');
    124.         sec=XBYTE[0];
    125.         bcdconv(sec);
    126.         }
    127. }
    128.  
    129. [/i][/i]


    Here is the screenshot of the Proteus simulated circuit

    123.JPG
     
    Last edited by a moderator: Dec 31, 2011
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    You know, I don't see anyplace else but the #defines where you reference either timeport or P0. Since you are not reading from or writing to the time port, why did you think you might get some time data in your program?

    [eta]
    I have gone to the trouble to re-indent your C code the way it should be. If you don't keep your code indented properly, you may omit a curly brace somewhere.

    Code ( (Unknown Language)):
    1. #include <REGX51.H>
    2. #include<ABSACC.h>
    3.  
    4. #define port P3
    5. #define lcd_dataport P2  // lcd_dataport for lcd
    6. #define keypad P1        // Port for keypadpad
    7. #define timeport P0      // Port for RTC
    8.  
    9. sbit rs = port^0;
    10. sbit rw = port^1;
    11. sbit en = port^2;
    12.  
    13. sbit key0=keypad^0;
    14. sbit key1=keypad^1;
    15. sbit key2=keypad^2;
    16. sbit key3=keypad^3;
    17. sbit key4=keypad^4;
    18. sbit key5=keypad^5;
    19. sbit key6=keypad^6;
    20. sbit key7=keypad^7;
    21.  
    22. int hr, min, sec;
    23.  
    24. void delay(unsigned int msec) //Time delay function
    25. {
    26.    int i,j ;
    27.    for(i=0;i<msec;i++)
    28.    for(j=0;j<1275;j++);
    29. }
    30.  
    31. void lcdcmd(unsigned char item) //Function to send command to LCD
    32. {
    33.    lcd_dataport = item;
    34.    rs= 0;
    35.    rw=0;
    36.    en=1;
    37.    delay(1);
    38.    en=0;
    39.    return;
    40. }
    41.  
    42. void lcddata(unsigned char item) //Funtion to send data on LCD
    43. {
    44.    lcd_dataport = item;
    45.    rs= 1;
    46.    rw=0;
    47.    en=1;
    48.    delay(1);
    49.    en=0;
    50. }
    51.  
    52. void lcddata_string(unsigned char *str) // Function to send string on LCD
    53. {
    54.    int i=0;
    55.    while(str[i]!='\0')
    56.    {
    57.       lcddata(str[i]);
    58.       i++;
    59.       delay(1);
    60.    }
    61. }
    62.  
    63. void lcd(unsigned char str[10])  // Funtion to Initialize LCD
    64. {
    65.    lcdcmd(0x38);
    66.    lcdcmd(0x0C);
    67.    lcdcmd(0x01);
    68.    lcdcmd(0x80);
    69.    lcddata_string(str);
    70. }
    71.  
    72. void check_key()
    73. {
    74.    if(key0==0)
    75.    lcd("SET TIME");
    76.    if(key1==0)
    77.    lcd("Increment");
    78.    if(key2==0)
    79.    lcd("Decrement");
    80.    if(key3==0)
    81.    lcd("SET A");
    82.    if(key4==0)
    83.    lcd("SET B");
    84.    if(key5==0)
    85.    lcd("SET C");
    86.    if(key6==0)
    87.    lcd("SET BANGS");
    88.    if(key7==0)
    89.    lcd("SET GROUPS");
    90. }
    91.  
    92. void bcdconv(unsigned char mybyte)
    93. {
    94.    unsigned char x,y;
    95.    x=mybyte&0x0F;
    96.    x=x|0x30;
    97.    y=mybyte&0xF0;
    98.    y=y>>4;
    99.    y=y|0x30;
    100.    lcddata(y);
    101.    lcddata(x);
    102. }
    103.  
    104. void main()
    105. {
    106.    delay(220);
    107.    XBYTE[10]=0x20;
    108.    XBYTE[11]=0x82;
    109.    XBYTE[4]=0x16;
    110.    XBYTE[2]=0x56;
    111.    XBYTE[0]=0x41;
    112.    XBYTE[11]=0x02;
    113.    lcd("TIME:");
    114.    while(1)
    115.    {
    116.       lcdcmd(0x88);
    117.       hr=XBYTE[4];
    118.       bcdconv(hr);
    119.       lcddata(':');
    120.       min=XBYTE[2];
    121.       bcdconv(min);
    122.       lcddata(':');
    123.       sec=XBYTE[0];
    124.       bcdconv(sec);
    125.    }
    126. }
    127. [/i][/i]
     
    Last edited: Dec 31, 2011
  3. Santosh_16k

    New Member

    Aug 19, 2011
    19
    0
    Shrimohan Jhawar, I have the same problem! :p
     
  4. scintrillating

    Thread Starter New Member

    Dec 30, 2011
    5
    0
    SgtWookie

    m NOT GETTING how to get through it..can u please modify the code !
     
Loading...