Urgent help 8051 ASM CODE

Discussion in 'Embedded Systems and Microcontrollers' started by @android, Mar 17, 2013.

  1. @android

    Thread Starter Member

    Dec 15, 2011
    178
    9
    Hi, I'm doing temperature meter project.
    Main components: 89V51RD2, ADC0804, LM35

    I have written below code in assembly language. LCD is working fine. But I'm unable to get correct temperature display. Please check below code and help me finding error asap :(.

    Code ( (Unknown Language)):
    1.  
    2. THRESHOLD EQU 40H
    3. RDT EQU P2.7
    4. WRT EQU P2.6
    5. INTR EQU P2.5
    6. ADC_DATA EQU P0
    7. RS EQU P3.2
    8. RW EQU P3.3
    9. EN EQU P3.4
    10. LCD_DATA EQU P1
    11. LED EQU P2.3
    12. FAN EQU P2.2
    13. BUZZER EQU P2.4
    14.  
    15. ORG 0000H
    16. MOV SP,#90H
    17.  
    18. LCALL LCD_INITIALISE
    19. MOV THRESHOLD,#65
    20. MOV P0,#0FFH
    21. MOV P1,#00H
    22. SETB INTR
    23. CLR BUZZER
    24. CLR FAN
    25. CLR LED
    26. LCALL TEMP
    27.  
    28. MAIN:
    29. CLR BUZZER
    30. CLR FAN
    31. CLR LED
    32. LCALL READ_ADC
    33. MOV R6,A
    34. LCALL CONVERT
    35. LCALL DISPLAY_TEMP
    36. MOV A,R6
    37. CLR C
    38. SUBB A,THRESHOLD
    39. JC FON
    40. JMP MAIN
    41.  
    42. FON:
    43. LCALL DISPLAY
    44. SETB LED
    45. SETB FAN
    46. SETB BUZZER
    47. LCALL DELAY
    48. LCALL DELAY
    49. LCALL DELAY
    50. LCALL DELAY
    51.  
    52. SETB INTR
    53. SETB RDT
    54. NOP
    55. CLR WRT
    56. NOP
    57. SETB WRT
    58. BACK:
    59. JNB INTR,BACK
    60. CLR RDT
    61. NOP
    62. NOP
    63. NOP
    64. MOV A,ADC_DATA
    65. NOP
    66. SETB RDT
    67. NOP
    68.  
    69. CLR C
    70. SUBB A,THRESHOLD
    71. JNC FON
    72. CLR BUZZER
    73. CLR FAN
    74. CLR LED
    75. LCALL DELAY
    76. JMP MAIN
    77.  
    78. LCD_INITIALISE:
    79. MOV A,#38H
    80. LCALL COMM
    81. MOV A,#0CH
    82. LCALL COMM
    83. MOV A,#01H
    84. LCALL COMM
    85. MOV A,#06H
    86. LCALL COMM
    87. MOV A,#84H
    88. LCALL COMM
    89. MOV A,#'W'
    90. LCALL DAT
    91. MOV A,#'E'
    92. LCALL DAT
    93. MOV A,#'L'
    94. LCALL DAT
    95. MOV A,#'C'
    96. LCALL DAT
    97. MOV A,#'O'
    98. LCALL DAT
    99. MOV A,#'M'
    100. LCALL DAT
    101. MOV A,#'E'
    102. LCALL DAT
    103. MOV A,#'!'
    104. LCALL DAT
    105. MOV A,#'!'
    106. LCALL DAT
    107. LCALL DELAY
    108. LCALL DELAY
    109. LCALL DELAY
    110. RET
    111.  
    112. TEMP:
    113. MOV A,#01H
    114. LCALL COMM
    115. MOV A,#80H
    116. LCALL COMM
    117. MOV A,#'T'
    118. LCALL DAT
    119. MOV A,#'E'
    120. LCALL DAT
    121. MOV A,#'M'
    122. LCALL DAT
    123. MOV A,#'P'
    124. LCALL DAT
    125. MOV A,#'E'
    126. LCALL DAT
    127. MOV A,#'R'
    128. LCALL DAT
    129. MOV A,#'A'
    130. LCALL DAT
    131. MOV A,#'T'
    132. LCALL DAT
    133. MOV A,#'U'
    134. LCALL DAT
    135. MOV A,#'R'
    136. LCALL DAT
    137. MOV A,#'E'
    138. LCALL DAT
    139. RET
    140.  
    141. READ_ADC:
    142. SETB RDT
    143. NOP
    144. CLR WRT
    145. NOP
    146. SETB WRT
    147.  
    148. HERE:
    149. JB INTR,HERE
    150. CLR RDT
    151. NOP
    152. NOP
    153. NOP
    154. MOV A,ADC_DATA
    155. NOP
    156. SETB RDT
    157. NOP
    158. RET
    159.  
    160. CONVERT:
    161. MOV B,#10
    162. DIV AB
    163. MOV R0,B
    164. MOV B,#10
    165. DIV AB
    166. MOV R1,B
    167.  
    168. MOV A,R1
    169. ORL A,#30H
    170. MOV R4,A
    171. MOV A,R0
    172. ORL A,#30H
    173. MOV R5,A
    174. RET
    175.  
    176. DISPLAY_TEMP:
    177. MOV A,#8CH
    178. LCALL COMM
    179. MOV A,R4
    180. LCALL DAT
    181. MOV A,R5
    182. LCALL DAT
    183. MOV A,#' '
    184. LCALL DAT
    185. MOV A,#'C'
    186. LCALL DAT
    187. RET
    188.  
    189.  
    190. DISPLAY:
    191. MOV A,#01H
    192. LCALL COMM
    193. MOV A,#82H
    194. LCALL COMM
    195.  
    196. MOV A,#'T'
    197. LCALL DAT
    198. MOV A,#'E'
    199. LCALL DAT
    200. MOV A,#'M'
    201. LCALL DAT
    202. MOV A,#'P'
    203. LCALL DAT
    204. MOV A,#'E'
    205. LCALL DAT
    206. MOV A,#'R'
    207. LCALL DAT
    208. MOV A,#'A'
    209. LCALL DAT
    210. MOV A,#'T'
    211. LCALL DAT
    212. MOV A,#'U'
    213. LCALL DAT
    214. MOV A,#'R'
    215. LCALL DAT
    216. MOV A,#'E'
    217. LCALL DAT
    218.  
    219. MOV A,#01H
    220. LCALL COMM
    221. MOV A,#82H
    222. LCALL COMM
    223.  
    224. MOV A,#'E'
    225. LCALL DAT
    226. MOV A,#'X'
    227. LCALL DAT
    228. MOV A,#'C'
    229. LCALL DAT
    230. MOV A,#'E'
    231. LCALL DAT
    232. MOV A,#'E'
    233. LCALL DAT
    234. MOV A,#'D'
    235. LCALL DAT
    236. MOV A,#'E'
    237. LCALL DAT
    238. MOV A,#'D'
    239. LCALL DAT
    240. MOV A,#'!'
    241. LCALL DAT
    242. MOV A,#'!'
    243. LCALL DAT
    244. MOV A,#'!'
    245. LCALL DAT
    246. RET
    247.  
    248. COMM:
    249. MOV LCD_DATA,A
    250. CLR RS
    251. CLR RW
    252. SETB EN
    253. NOP
    254. CLR EN
    255. LCALL DELAY
    256. RET
    257.  
    258. DAT:
    259. MOV LCD_DATA,A
    260. SETB RS
    261. CLR RW
    262. SETB EN
    263. NOP
    264. CLR EN
    265. LCALL DELAY
    266. RET
    267.  
    268. DELAY:
    269. MOV R2,#255
    270.  
    271. HERE2:
    272. MOV R3,#250
    273. HERE1:
    274. DJNZ R3,HERE1
    275. DJNZ R2,HERE2
    276. RET
    277.  
    278. END
    279.  
    FYI Chip select pin is connected to VCC
     
    Last edited: Mar 18, 2013
  2. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    Works ok for me... What have you set your Vref/2 to?

    What clock speed have you got on Clkin?

    Your temperature calculations don't add up!!! I have to stick Vref/2 at 1.25volts
     
    Last edited: Mar 17, 2013
  3. @android

    Thread Starter Member

    Dec 15, 2011
    178
    9
    I did bunch of iterations and figured that when I do "HERE: JNB INTR HERE" in the ADC routine it displays "55H" constantly. If I do "HERE: JB INTR HERE" that is the correct way to monitor end of conversion the loop stucks there only and does nothing further.

    I'm suspecting my ADC isn't working! :confused:
     
  4. @android

    Thread Starter Member

    Dec 15, 2011
    178
    9
    LM35 is giving me 10mV/deg.C so I have set Vref/2 to 1.28V so as to get 10mV step size.

    I'm using ADC internal clock.

    What do you mean by "Your temperature calculations don't add up!!!"? :confused:
     
  5. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    No its fine... I have set the vref/2 to 1.25 so that 65 deg displayed 67deg.... Its fine now

    The call to display the word temperature (call just before your main loop) needs to to be at the end of the exceeded temperature loop as well.

    I didn't think there was an internal clock.. You need to output a clock from the 51..
     
  6. @android

    Thread Starter Member

    Dec 15, 2011
    178
    9
    hussh! turned out to be bad adc after all!

    yesterday replaced with new one now working fine after I debugged entire code and made it working properly. anyone wants final code??
     
  7. @android

    Thread Starter Member

    Dec 15, 2011
    178
    9
    I have learned one thing from my experience with projects. 'A project is not a project if it works out at first go'. :) heh he.
     
  8. @android

    Thread Starter Member

    Dec 15, 2011
    178
    9
    Why do you want to display 65 as 67?? :confused:People generaly opt for accurate reading. :rolleyes:
     
  9. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    I made a small mistake as I didn't have the benefit of YOUR circuit... I made it correct now...
     
  10. PY01A0080

    Member

    Mar 7, 2013
    42
    3
    Hi,
    can you please post the circuit?
    thx
     
  11. @android

    Thread Starter Member

    Dec 15, 2011
    178
    9
    Hi. Sorry I don't have schematic right now. But here is one which is quite similar to mine only replace 7-SEG with LCD.
     
    absf likes this.
Loading...