Heart rate monitor using 8051.

Discussion in 'Embedded Systems and Microcontrollers' started by zachary, Jul 1, 2014.

  1. zachary

    Thread Starter New Member

    Jan 8, 2013
    6
    0
    I am new in microcontroller. I want to use 8051 to monitor the heart rate. After going through some tutorials and online materials i wrote the following code but could not identify the errors in the code.

    Code ( (Unknown Language)):
    1.  
    2. ORG 000H                    // origin
    3.  
    4. MOV DPTR,#LUT             // moves starting address of LUT to DPTR
    5.  
    6. MOV P1,#00000000B             // sets P1 as output port
    7.  
    8. MOV P0,#00000000B           // sets P0 as output port
    9.  
    10. MAIN: MOV R6,#230D            // loads register R6 with 230D
    11.  
    12. SETB P3.5                         // sets P3.5 as input port
    13.  
    14. MOV TMOD,#01100001B           // Sets Timer1 as Mode2 counter &Timer0 as Mode1 timer
    15.  
    16. MOV TL1,#00000000B                  // loads TL1 with initial value
    17.  
    18. MOV TH1,#00000000B                     // loads TH1 with initial value
    19.  
    20. SETB TR1                                      // starts timer(counter) 1
    21.  
    22. BACK: MOV TH0,#00000000B              // loads initial value to TH0
    23.  
    24. MOV TL0,#00000000B                       // loads initial value to TL0
    25.  
    26. SETB TR0                                                  // starts timer 0
    27.  
    28. HERE: JNB TF0,HERE                       // checks for Timer 0 roll over
    29.  
    30. CLR TR0                                              // stops Timer0
    31.  
    32. CLR TF0                                                // clears Timer Flag 0
    33.  
    34. DJNZ R6,BACK
    35.  
    36. CLR TR1                                                   // stops Timer(counter)1
    37.  
    38. CLR TF0                                                        // clears Timer Flag 0
    39.  
    40. CLR TF1                                                           // clears Timer Flag 1
    41.  
    42. ACALL DLOOP              // Calls subroutine DLOOP for displaying the count
    43.  
    44. SJMP MAIN                       // jumps back to the main loop
    45.  
    46. DLOOP: MOV R5,#252D
    47.  
    48. BACK1: MOV A,TL1              // loads the current count to the accumulator
    49.  
    50. MOV B,#4D                                // loads register B with 4D
    51.  
    52. MUL AB                                   // Multiplies the TL1 count with 4
    53.  
    54. MOV B,#100D                       // loads register B with 100D
    55.  
    56. DIV AB                                   // isolates first digit of the count
    57.  
    58. SETB P1.0                              // display driver transistor Q1 ON
    59.  
    60. ACALL DISPLAY                          // converts 1st digit to 7seg pattern
    61.  
    62. MOV P0,A                                  // puts the pattern to port 0
    63.  
    64. ACALL DELAY
    65.  
    66. ACALL DELAY
    67.  
    68. MOV A,B
    69.  
    70. MOV B,#10D
    71.  
    72. DIV AB                                   // isolates the second digit of the count
    73.  
    74. CLR P1.0                                // display driver transistor Q1 OFF
    75.  
    76. SETB P1.1                              // display driver transistor Q2 ON
    77.  
    78. ACALL DISPLAY                      // converts the 2nd digit to 7seg pattern
    79.  
    80. MOV P0,A
    81.  
    82. ACALL DELAY
    83.  
    84. ACALL DELAY
    85.  
    86. MOV A,B                   // moves the last digit of the count to accumulator
    87.  
    88. CLR P1.1                    // display driver transistor Q2 OFF
    89.  
    90. SETB P1.2                   // display driver transistor Q3 ON
    91.  
    92. ACALL DISPLAY                  // converts 3rd digit to 7seg pattern
    93.  
    94. MOV P0,A                        // puts the pattern to port 0
    95.  
    96. ACALL DELAY                      // calls 1ms delay
    97.  
    98. ACALL DELAY
    99.  
    100. CLR P1.2
    101.  
    102. DJNZ R5,BACK1                  // repeats the subroutine DLOOP 100 times
    103.  
    104. MOV P0,#11111111B
    105.  
    106. RET
    107.  
    108. DELAY: MOV R7,#250D                   // 1ms delay
    109.  
    110. DEL1: DJNZ R7,DEL1
    111.  
    112. RET
    113.  
    114. DISPLAY: MOVC A,@A+DPTR     // gets 7seg digit drive pattern for current
    115.  
    116. value in A
    117.  
    118. CPL A
    119.  
    120. RET
    121.  
    122. LUT: DB 3FH                                 // LUT starts here
    123.  
    124. DB 06H
    125.  
    126. DB 5BH
    127.  
    128. DB 4FH
    129.  
    130. DB 66H
    131.  
    132. DB 6DH
    133.  
    134. DB 7DH
    135.  
    136. DB 07H
    137.  
    138. DB 7FH
    139.  
    140. DB 6FH
    141.  
    142. END
    143.  
    Can someone help me sort out the problem or give and alternative code please?
    The circuit diagram is as seen on the attachment bellow
     
    Last edited by a moderator: Jul 1, 2014
  2. absf

    Senior Member

    Dec 29, 2010
    1,490
    371
    Your code seems to work fine. I gave it a 3 Hz pulse at P3.5 and it displayed 180 after 60 seconds.

    What is your complaint about the project? Hardware or software?

    Allen
     
    zachary likes this.
  3. zachary

    Thread Starter New Member

    Jan 8, 2013
    6
    0
    Thank you for your reply. I don't understand how you represented S1 reset from your simulation diagram. Could you please tell me how to represent S1 reset button?
     
  4. absf

    Senior Member

    Dec 29, 2010
    1,490
    371
    C4 and R1 forms what we called power-up reset circuit. On power-up C4 is like a short-circuit which would bring logic high to the RST pin. When C4 is slowly charged up by R1, RST would drop to logic low.

    You can put a switch across C4 if you need a manual reset. It's also a good idea to put a diode across C4 to make sure that it is fully discharged during powered down.

    Allen
     
    zachary likes this.
  5. zachary

    Thread Starter New Member

    Jan 8, 2013
    6
    0
    I tried to build the hex file in M-IDE studio for MCS-51 but the program keeps loading forever. What might be the problem? There is no error in the program.
     
Loading...