digital watch using 8051 timer

Discussion in 'Embedded Systems and Microcontrollers' started by khangul, Feb 15, 2015.

  1. khangul

    Thread Starter New Member

    Jan 31, 2015
    12
    0
    Code (Text):
    1.  
    2. I want to update my LCD after every 1 second delay. how to send values 1,2,3......upto 60  to micro controller and update each and every time after 1 second delay
    3.  
    4.  
    5.  
    6.  
    7.  
    8. #include<stdio.h>
    9. #include<reg51.h>
    10.  
    11. sbit rs= P1^0;
    12. sbit rw= P1^1;
    13. sbit en= P1^2;
    14.  
    15. void second();
    16. //void mint();
    17. void tdelay();
    18.  
    19. char lcddat[30]= {"Hour:mint:second"};
    20. char cmd[6]={0x38,0x0E,0x01,0x80};
    21. int tim[30]={"1,2,3,4,5,6,7,8,9,10,11,12,13"};
    22.  
    23. char i,j; //veriable decleration
    24. int o;
    25. char p=0;
    26. int x=0;
    27. int y=0x30;
    28.  
    29.  
    30. void main()
    31. {
    32.  
    33.  
    34. rs=0;
    35. rw=0;
    36. en=0;
    37.  
    38. for (i=0;i<=5;i++)
    39. {
    40. P2=cmd[i]; //lcd initialization
    41. en=1;
    42. tdelay();
    43. en=0;
    44.  
    45. }
    46.  
    47.  
    48. P2=0x80;
    49. en=1;
    50. tdelay();
    51. en=0;
    52.  
    53. rs=1;
    54. for (j=0;j<=15;j++)// Lcd data
    55. {
    56.  
    57. P2=lcddat[j];
    58. en=1;
    59. tdelay();
    60. en=0;
    61.  
    62. }
    63.  
    64. while(1)
    65. {
    66.  
    67. do{
    68.  
    69.  
    70. rs=0;
    71. P2=0xC0;
    72. y++;
    73. en=1;
    74. tdelay();
    75. en=0;
    76.  
    77.  
    78. rs=1;
    79.  
    80. second();
    81.  
    82. P2=tim[x];
    83. en=1;
    84. tdelay();
    85. en=0;
    86. x++;
    87. }
    88. while(x<60);
    89.  
    90. }
    91. }
    92. void tdelay() // delay of 25ms using 8051 timer
    93. {
    94.   TMOD=0x01;
    95.   TL0=0xFE;
    96.   TH0=0xA5;
    97.   TR0=1;
    98. while (TF0==0);
    99. TR0=0;
    100. TF0=0;
    101. }
    102.  
    103. void second() // second delay
    104. {
    105. int p;
    106. for (p=0;p<40;p++)
    107. {
    108. tdelay();
    109. }
    110. }
    111. /*void mint()
    112. {
    113. int o;
    114. for (o=0;o<2400;o++){
    115. tdelay();
    116. }
    117.  
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    Your code looks strangely similar to ueb-ners's. Project time again and not paying attention in school?

    No one is going to write your program for you. You will need to do that. The first thing you need to do is get something written to the LCD.

    You didn't even bother to mention the LCD. Assuming a HDM08216 there are plenty of libraries out there for them. The enclosed is for the Pic but you should be able to adapt the code fairly easily.
     
    • LCD.zip
      File size:
      2.8 KB
      Views:
      15
  3. khangul

    Thread Starter New Member

    Jan 31, 2015
    12
    0
    Sir, i did it successfully. if any one need the code i can favour on him
     
Loading...