Urgent help 8051 ASM CODE

Thread Starter

@android

Joined Dec 15, 2011
178
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 :(.

Rich (BB code):
THRESHOLD EQU 40H
RDT EQU P2.7
WRT EQU P2.6
INTR EQU P2.5
ADC_DATA EQU P0
RS EQU P3.2
RW EQU P3.3
EN EQU P3.4
LCD_DATA EQU P1
LED EQU P2.3
FAN EQU P2.2
BUZZER EQU P2.4

ORG 0000H
MOV SP,#90H

LCALL LCD_INITIALISE
MOV THRESHOLD,#65
MOV P0,#0FFH
MOV P1,#00H
SETB INTR
CLR BUZZER
CLR FAN
CLR LED
LCALL TEMP

MAIN:
CLR BUZZER
CLR FAN
CLR LED
LCALL READ_ADC
MOV R6,A
LCALL CONVERT
LCALL DISPLAY_TEMP
MOV A,R6
CLR C
SUBB A,THRESHOLD
JC FON
JMP MAIN

FON:
LCALL DISPLAY
SETB LED
SETB FAN
SETB BUZZER
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY

SETB INTR
SETB RDT
NOP
CLR WRT
NOP
SETB WRT
BACK: 
JNB INTR,BACK
CLR RDT
NOP
NOP
NOP
MOV A,ADC_DATA
NOP
SETB RDT
NOP

CLR C
SUBB A,THRESHOLD
JNC FON
CLR BUZZER
CLR FAN
CLR LED
LCALL DELAY
JMP MAIN

LCD_INITIALISE:
MOV A,#38H
LCALL COMM
MOV A,#0CH
LCALL COMM
MOV A,#01H
LCALL COMM
MOV A,#06H
LCALL COMM
MOV A,#84H
LCALL COMM
MOV A,#'W'
LCALL DAT
MOV A,#'E'
LCALL DAT
MOV A,#'L'
LCALL DAT
MOV A,#'C'
LCALL DAT
MOV A,#'O'
LCALL DAT
MOV A,#'M'
LCALL DAT
MOV A,#'E'
LCALL DAT
MOV A,#'!'
LCALL DAT
MOV A,#'!'
LCALL DAT
LCALL DELAY
LCALL DELAY
LCALL DELAY
RET

TEMP:
MOV A,#01H
LCALL COMM
MOV A,#80H
LCALL COMM
MOV A,#'T'
LCALL DAT
MOV A,#'E'
LCALL DAT
MOV A,#'M'
LCALL DAT
MOV A,#'P'
LCALL DAT
MOV A,#'E'
LCALL DAT
MOV A,#'R'
LCALL DAT
MOV A,#'A'
LCALL DAT
MOV A,#'T'
LCALL DAT
MOV A,#'U'
LCALL DAT
MOV A,#'R'
LCALL DAT
MOV A,#'E'
LCALL DAT
RET

READ_ADC:
SETB RDT
NOP
CLR WRT
NOP
SETB WRT

HERE: 
JB INTR,HERE
CLR RDT
NOP
NOP
NOP
MOV A,ADC_DATA
NOP
SETB RDT
NOP
RET

CONVERT:
MOV B,#10
DIV AB
MOV R0,B
MOV B,#10
DIV AB
MOV R1,B

MOV A,R1
ORL A,#30H
MOV R4,A
MOV A,R0
ORL A,#30H
MOV R5,A
RET

DISPLAY_TEMP:
MOV A,#8CH
LCALL COMM
MOV A,R4
LCALL DAT
MOV A,R5
LCALL DAT
MOV A,#' '
LCALL DAT
MOV A,#'C'
LCALL DAT
RET


DISPLAY:
MOV A,#01H
LCALL COMM
MOV A,#82H
LCALL COMM

MOV A,#'T'
LCALL DAT
MOV A,#'E'
LCALL DAT
MOV A,#'M'
LCALL DAT
MOV A,#'P'
LCALL DAT
MOV A,#'E'
LCALL DAT
MOV A,#'R'
LCALL DAT
MOV A,#'A'
LCALL DAT
MOV A,#'T'
LCALL DAT
MOV A,#'U'
LCALL DAT
MOV A,#'R'
LCALL DAT
MOV A,#'E'
LCALL DAT

MOV A,#01H
LCALL COMM
MOV A,#82H
LCALL COMM

MOV A,#'E'
LCALL DAT
MOV A,#'X'
LCALL DAT
MOV A,#'C'
LCALL DAT
MOV A,#'E'
LCALL DAT
MOV A,#'E'
LCALL DAT
MOV A,#'D'
LCALL DAT
MOV A,#'E'
LCALL DAT
MOV A,#'D'
LCALL DAT
MOV A,#'!'
LCALL DAT
MOV A,#'!'
LCALL DAT
MOV A,#'!'
LCALL DAT
RET

COMM:
MOV LCD_DATA,A
CLR RS
CLR RW
SETB EN
NOP
CLR EN
LCALL DELAY
RET

DAT:
MOV LCD_DATA,A
SETB RS
CLR RW
SETB EN
NOP
CLR EN
LCALL DELAY
RET

DELAY:
MOV R2,#255

HERE2:
MOV R3,#250
HERE1:
DJNZ R3,HERE1
DJNZ R2,HERE2
RET

END
FYI Chip select pin is connected to VCC
 
Last edited:

Ian Rogers

Joined Dec 12, 2012
1,136
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:

Thread Starter

@android

Joined Dec 15, 2011
178
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:
 

Thread Starter

@android

Joined Dec 15, 2011
178
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
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:
 

Ian Rogers

Joined Dec 12, 2012
1,136
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..
 

Thread Starter

@android

Joined Dec 15, 2011
178
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??
 

Thread Starter

@android

Joined Dec 15, 2011
178
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.
 

Thread Starter

@android

Joined Dec 15, 2011
178
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..
Why do you want to display 65 as 67?? :confused:People generaly opt for accurate reading. :rolleyes:
 
Top