RTC 12C887 Issue with P89V51RD2

Discussion in 'Embedded Systems and Microcontrollers' started by scintrillating, Feb 6, 2012.

  1. scintrillating

    Thread Starter New Member

    Dec 30, 2011
    5
    0
    I have Interfaced 12C887 with P89V51RD2 but the time update does not occur. However the same code when burned in AT89C51, works perfectly...But due to memory restrictions of 4Kb in the Later, we have to use the former. Please help me out on this issue, ASAP!

    The Code is :

    Code ( (Unknown Language)):
    1.  
    2. #include <p89v51rd2.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^5;
    13.  
    14.  
    15. int hr, min, sec;
    16. unsigned char a[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59};
    17.    
    18. void delay(unsigned int msec) //Time delay function
    19. {
    20. int i,j ;
    21. for(i=0;i<msec;i++)
    22. for(j=0;j<1275;j++);
    23. }
    24.  
    25. void lcdcmd(unsigned char item) //Function to send command to LCD
    26. {
    27. lcd_dataport = item;
    28. rs=0;
    29. rw=0;
    30. en=1;
    31. delay(1);
    32. en=0;
    33. return;
    34. }
    35.  
    36. void lcddata(unsigned char item) //Funtion to send data on LCD
    37. {
    38. lcd_dataport = item;
    39. rs=1;
    40. rw=0;
    41. en=1;
    42. delay(1);
    43. en=0;
    44. }
    45.  
    46. void lcddata_string(unsigned char *str) // Function to send string on LCD
    47. {
    48. int i=0;
    49. while(str[i]!='\0')
    50. {
    51. lcddata(str[i]);
    52. i++;
    53. delay(1);
    54. }
    55. }
    56.  
    57. void lcd(unsigned char str[16])  // Funtion display string on LCD
    58. {
    59. lcdcmd(0x38);
    60. lcdcmd(0x0C);
    61. lcddata_string(str);
    62. }
    63.  
    64. void bcdconv(unsigned char mybyte)
    65. {
    66. unsigned char x,y;
    67. x=mybyte&0x0F;
    68. x=x|0x30;
    69. y=mybyte&0xF0;
    70. y=y>>4;
    71. y=y|0x30;
    72. lcddata(y);
    73. lcddata(x);
    74. }
    75.  
    76. void main()
    77. {
    78. lcdcmd(0x38);
    79. lcdcmd(0x0C);
    80. lcdcmd(0x01);        
    81. delay(220);
    82. XBYTE[10]=0x20;
    83. XBYTE[11]=0x82;
    84. XBYTE[0]=0x15;
    85. XBYTE[2]=0x59;
    86. XBYTE[4]=0x12;
    87. XBYTE[11]=0x02;
    88. while(1)
    89. {
    90. lcdcmd(0x80);
    91. lcd("TIME:");
    92. lcdcmd(0x88);
    93. hr=XBYTE[4];
    94. bcdconv(hr);
    95. lcddata(':');
    96. min=XBYTE[2];
    97. bcdconv(min);
    98. lcddata(':');
    99. sec=XBYTE[0];
    100. bcdconv(sec);
    101. }
    102. }
    103. [/i][/i]
     
    Last edited by a moderator: Feb 7, 2012
  2. madhusuthanan

    New Member

    May 30, 2012
    5
    0


    hi scintrillating,

    try the changed code.

    #include <p89v51rd2.h>
    #include<absacc.h>

    #define port P3
    #define lcd_dataport P2 // lcd_dataport for lcd
    #define keypad P1 // Port for keypadpad
    #define timeport P0 // Port for RTC

    sbit rs = port^0;
    sbit rw = port^1;
    sbit en = port^5;


    int hr, min, sec;
    unsigned char a[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59};

    void delay(unsigned int msec) //Time delay function
    {
    int i,j ;
    for(i=0;i<msec;i++)
    for(j=0;j<1275;j++);
    }

    void lcdcmd(unsigned char item) //Function to send command to LCD
    {
    lcd_dataport = item;
    rs=0;
    rw=0;
    en=1;
    delay(1);
    en=0;
    return;
    }

    void lcddata(unsigned char item) //Funtion to send data on LCD
    {
    lcd_dataport = item;
    rs=1;
    rw=0;
    en=1;
    delay(1);
    en=0;
    }

    void lcddata_string(unsigned char *str) // Function to send string on LCD
    {
    int i=0;
    while(str!='\0')
    {
    lcddata(str);
    i++;
    delay(1);
    }
    }

    void lcd(unsigned char str[16]) // Funtion display string on LCD
    {
    lcddata_string(str);
    }

    void bcdconv(unsigned char mybyte)
    {
    unsigned char x,y;
    x=mybyte&0x0F;
    x=x|0x30;
    y=mybyte&0xF0;
    y=y>>4;
    y=y|0x30;
    lcddata(y);
    lcddata(x);
    }

    void main()
    {
    lcdcmd(0x38);
    lcdcmd(0x01);
    lcdcmd(0x0C);
    lcdcmd(0x06);
    delay(220);
    XBYTE[10]=0x20;
    XBYTE[11]=0x82;
    XBYTE[0]=0x15;
    XBYTE[2]=0x59;
    XBYTE[4]=0x12;
    XBYTE[11]=0x02;
    while(1)
    {
    lcdcmd(0x80);
    lcd("TIME:");
    lcdcmd(0x88);
    hr=XBYTE[4];
    bcdconv(hr);
    lcddata(':');
    min=XBYTE[2];
    bcdconv(min);
    lcddata(':');
    sec=XBYTE[0];
    bcdconv(sec);
    }
    }
     
  3. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    you should really use the code tags to make code more readable.....

    Code ( (Unknown Language)):
    1. #include <p89v51rd2.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^5;
    12.  
    13.  
    14. int hr, min, sec;
    15. unsigned char a[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59};
    16.    
    17. void delay(unsigned int msec) //Time delay function
    18. {
    19. int i,j ;
    20. for(i=0;i<msec;i++)
    21. for(j=0;j<1275;j++);
    22. }
    23.  
    24. void lcdcmd(unsigned char item) //Function to send command to LCD
    25. {
    26. lcd_dataport = item;
    27. rs=0;
    28. rw=0;
    29. en=1;
    30. delay(1);
    31. en=0;
    32. return;
    33. }
    34.  
    35. void lcddata(unsigned char item) //Funtion to send data on LCD
    36. {
    37. lcd_dataport = item;
    38. rs=1;
    39. rw=0;
    40. en=1;
    41. delay(1);
    42. en=0;
    43. }
    44.  
    45. void lcddata_string(unsigned char *str) // Function to send string on LCD
    46. {
    47. int i=0;
    48. while(str[i]!='\0')
    49. {
    50. lcddata(str[i]);
    51. i++;
    52. delay(1);
    53. }
    54. }
    55.  
    56. void lcd(unsigned char str[16])  // Funtion display string on LCD
    57. {
    58. lcddata_string(str);
    59. }
    60.  
    61. void bcdconv(unsigned char mybyte)
    62. {
    63. unsigned char x,y;
    64. x=mybyte&0x0F;
    65. x=x|0x30;
    66. y=mybyte&0xF0;
    67. y=y>>4;
    68. y=y|0x30;
    69. lcddata(y);
    70. lcddata(x);
    71. }
    72.  
    73. void main()
    74. {
    75. lcdcmd(0x38);
    76. lcdcmd(0x01);        
    77. lcdcmd(0x0C);
    78. lcdcmd(0x06);
    79. delay(220);
    80. XBYTE[10]=0x20;
    81. XBYTE[11]=0x82;
    82. XBYTE[0]=0x15;
    83. XBYTE[2]=0x59;
    84. XBYTE[4]=0x12;
    85. XBYTE[11]=0x02;
    86. while(1)
    87. {
    88. lcdcmd(0x80);
    89. lcd("TIME:");
    90. lcdcmd(0x88);
    91. hr=XBYTE[4];
    92. bcdconv(hr);
    93. lcddata(':');
    94. min=XBYTE[2];
    95. bcdconv(min);
    96. lcddata(':');
    97. sec=XBYTE[0];
    98. bcdconv(sec);
    99. }
    100. }[/i][/i]
     
Loading...