Discussion in "8051 Discussion Forum" started by    rvs    May 9, 2012.
Sun May 13 2012, 12:51 pm
#11
Got some (lots of it) help and made new code, that should activate relay at 27 degrees Celsius. Perhaps someone could check it out and let me know if this code will work or if it will not work.


PS! In code I attach LCD's R/W (pin 5) to P1.4, If this code works, then I will connect these two pins, if not, then I will leave LCD's R/W connected to GND.

org 0h
RAM_ADDR EQU 30H
COUNT EQU 3

hundreds equ 30h
tens equ 31h
ones equ 32h


ACALL DELAY_200M
ACALL ONETIME_LCDINIT

STT:
ACALL ADC
ACALL Bin2Dec
ACALL DEC_ASCI_CONVRT
ACALL DELAY_200M
ACALL DELAY_200M
ACALL DELAY_200M
sjmp STT

;=================================================
;this subroutine is used to take data from ADC and
;keep to Accumulator
;=================================================
ADC:
mov A,P0 // ACD output to P.0
nop
nop
ret
Bin2Dec:
mov b,#100d
div ab
mov hundreds,a
mov a,b
mov b,#10d
div ab
mov tens,a
mov ones,b
ret

DEC_ASCI_CONVRT:
MOV R0,#RAM_ADDR
MOV R2,#3
BACKk: MOV A,@R0
ORL A,#30H
ACALL DATA_DISPLAY
INC R0
DJNZ R2,BACKk
RET

ONETIME_LCDINIT:
MOV A,#38H
ACALL COMMAND
MOV A,#0EH
ACALL COMMAND
MOV A,#01H
ACALL COMMAND
MOV A,#06H
ACALL COMMAND
MOV A,#86H
ACALL COMMAND
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
COMMAND:
ACALL READY
MOV P2,A // LCD D0 to D7 connected to P2
CLR P3.4 // LCD RS (pin4) to P3.4
CLR P1.4 // LCD R/W (pin5) to P1.4 (I took unused port for this)
SETB P3.5 // LCD E (pin6) to P3.5
CLR P3.5
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DATA_DISPLAY: // I changed port numbres here
ACALL READY
MOV P2,A
SETB P3.4
CLR P1.4
SETB P3.5
ACALL DELAY
CLR P3.5
RET
READY: SETB P2.7
CLR P3.4
SETB P1.4
BACK: CLR P3.5
ACALL DELAY
SETB P3.5
JB P2.7,BACK
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ACALL ADC // added relay control correctly??
CJNE A,#27, TRIPP
SETB P1.3 // pin connected to relay
TRIPP:
ACALL Bin2Dec
RET // is this necessary??
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY_200M:
MOV R7,#30H
L1_DELAY:
MOV TMOD,#10
MOV TH1,#3CH
MOV TL1,#0B0H
SETB TR1
AGAIN: JNB TF1,AGAIN
CLR TR1
CLR TF1
DJNZ R7,L1_DELAY
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY: MOV R3,#50
HERE3: MOV R4,#255
HERE2: DJNZ R4,HERE2
DJNZ R3,HERE3
RET
END
Sun May 13 2012, 09:29 pm
#12


Got some (lots of it) help and made new code, that should activate relay at 27 degrees Celsius.

rvs


Does that mean activate relay at exactly 27 degrees Celsius..
or 27 degrees and above or 27 degrees and below ?
Sun May 13 2012, 11:11 pm
#13
27 and above relay should be active...for example if in theory it is connected to a fan, fan would lower temperature (in environment where it is reading temperature) until it is under 27 degrees again and then it would switch off.
Mon May 14 2012, 12:47 am
#14


ACALL ADC // added relay control correctly??
CJNE A,#27, TRIPP
SETB P1.3 // pin connected to relay
TRIPP:
ACALL Bin2Dec
RET // is this necessary??

rvs






This should do it.
Add a call to TestTemperature to the main loop.
TestTemperature:
	ACALL ADC  ;read temperature
	CJNE A,#27,CheckFurther   ;jmp if not exactly 27 deg
			;is 27 so turn on
RelayOn:
	SETB P1.3   ;set pin connected to relay high
        ret
CheckFurther:
	jnc RelayOn  ;jmp if greater than 27
                      ;less than 27 so turn off
	CLR P1.3  ;set pin connected to relay low
        ret




[ Edited Mon May 14 2012, 12:54 am ]
Mon May 14 2012, 01:01 am
#15
org 0h
RAM_ADDR EQU 30H
COUNT EQU 3

hundreds equ 30h
tens equ 31h
ones equ 32h


ACALL DELAY_200M
ACALL ONETIME_LCDINIT

STT:
ACALL ADC
ACALL Bin2Dec
ACALL DEC_ASCI_CONVRT
ACALL DELAY_200M
ACALL DELAY_200M
ACALL DELAY_200M
sjmp STT

;=================================================
;this subroutine is used to take data from ADC and
;keep to Accumulator
;=================================================
ADC:
mov A,P0 // ACD output to P.0
nop
nop
ret
Bin2Dec:
mov b,#100d
div ab
mov hundreds,a
mov a,b
mov b,#10d
div ab
mov tens,a
mov ones,b
ret

DEC_ASCI_CONVRT:
MOV R0,#RAM_ADDR
MOV R2,#3
BACKk: MOV A,@R0
ORL A,#30H
ACALL DATA_DISPLAY
INC R0
DJNZ R2,BACKk
RET

ONETIME_LCDINIT:
MOV A,#38H
ACALL COMMAND
MOV A,#0EH
ACALL COMMAND
MOV A,#01H
ACALL COMMAND
MOV A,#06H
ACALL COMMAND
MOV A,#86H
ACALL COMMAND
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
COMMAND:
ACALL READY
MOV P2,A // LCD D0 to D7 connected to P2
CLR P3.4 // LCD RS (pin4) to P3.4
CLR P1.4 // LCD R/W (pin5) to P1.4 (I took unused port for this)
SETB P3.5 // LCD E (pin6) to P3.5
CLR P3.5
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DATA_DISPLAY: // I changed port numbres here
ACALL READY
MOV P2,A
SETB P3.4
CLR P1.4
SETB P3.5
ACALL DELAY
CLR P3.5
RET
READY: SETB P2.7
CLR P3.4
SETB P1.4
BACK: CLR P3.5
ACALL DELAY
SETB P3.5
JB P2.7,BACK
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ACALL ADC // added relay control correctly??
CJNE A,#27, TRIPP
SETB P1.3 // pin connected to relay
TRIPP:
ACALL Bin2Dec
RET // is this necessary??
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TestTemperature:
ACALL ADC ;read temperature
CJNE A,#27,CheckFurther ;jmp if not exactly 27 deg
;is 27 so turn on
RelayOn:
SETB P1.3 ;set pin connected to relay high
ret
CheckFurther:
jnc RelayOn ;jmp if greater than 27
;less than 27 so turn off
CLR P1.3 ;set pin connected to relay low
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY_200M:
MOV R7,#30H
L1_DELAY:
MOV TMOD,#10
MOV TH1,#3CH
MOV TL1,#0B0H
SETB TR1
AGAIN: JNB TF1,AGAIN
CLR TR1
CLR TF1
DJNZ R7,L1_DELAY
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY: MOV R3,#50
HERE3: MOV R4,#255
HERE2: DJNZ R4,HERE2
DJNZ R3,HERE3
RET
END


Did I put it in correct place? So this should be the code, with what my device should work correctly?
Mon May 14 2012, 01:30 am
#16
Remove this old code...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ACALL ADC // added relay control correctly??
CJNE A,#27, TRIPP
SETB P1.3 // pin connected to relay
TRIPP:
ACALL Bin2Dec
RET // is this necessary??
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

You have a routine called ADC.
;=================================================
;this subroutine is used to take data from ADC and
;keep to Accumulator
;=================================================
ADC:
mov A,P0 // ACD output to P.0

Change it to Read_ADC: as the name will cause confusion

so it becomes...

;=================================================
;this subroutine is used to take data from ADC and
;keep to Accumulator
;=================================================
Read_ADC:
mov A,P0 // ACD output to P.0

Change the new code I gave you to
TestTemperature:
         ACALL Read_ADC ;read temperature



change the main loop to

STT:
ACALL Read_ADC
ACALL Bin2Dec
ACALL DEC_ASCI_CONVRT
ACALL DELAY_200M
ACALL DELAY_200M
ACALL DELAY_200M
ACALL TestTemperature ;test temperature
sjmp STT  


Will it work ?
I don't know ....
I haven't been through every line, (and am not going to ).
Try it, either in hardware or in a simulator such as Proteus.



[ Edited Mon May 14 2012, 01:40 am ]
Mon May 14 2012, 01:54 am
#17
What is the command mov b,#100d suposed to do? And mov b,#10d??

Bin2Dec:
mov b,#100d
div ab
mov hundreds,a
mov a,b
mov b,#10d
div ab
mov tens,a
mov ones,b
ret

Tried the code in edsim51, shows error when these two lines are in code. If I delete these two lines, edsim runs without problems.
Mon May 14 2012, 03:39 am
#18


What is the command mov b,#100d suposed to do? And mov b,#10d??

rvs


mov b,#100d is supposed to load 100 into the b register, probably
the 'd' is an error

try using
mov b,#100 and mov b,#10
or
mov b,#0x64h and mov b,#0x0ah
instead.
Mon May 14 2012, 12:02 pm
#19
I used code

org 0h
RAM_ADDR EQU 30H
COUNT EQU 3

hundreds equ 30h
tens equ 31h
ones equ 32h


ACALL DELAY_200M
ACALL ONETIME_LCDINIT

STT:
ACALL Read_ADC
ACALL Bin2Dec
ACALL DEC_ASCI_CONVRT
ACALL DELAY_200M
ACALL DELAY_200M
ACALL DELAY_200M
ACALL TestTemperature
sjmp STT

;=================================================
;this subroutine is used to take data from ADC and
;keep to Accumulator
;=================================================
Read_ADC:
mov A,P0
nop
nop
ret
Bin2Dec:
mov b,#100d
div ab
mov hundreds,a
mov a,b
mov b,#10d
div ab
mov tens,a
mov ones,b
ret

DEC_ASCI_CONVRT:
MOV R0,#RAM_ADDR
MOV R2,#3
BACKk: MOV A,@R0
ORL A,#30H
ACALL DATA_DISPLAY
INC R0
DJNZ R2,BACKk
RET

ONETIME_LCDINIT:
MOV A,#38H
ACALL COMMAND
MOV A,#0EH
ACALL COMMAND
MOV A,#01H
ACALL COMMAND
MOV A,#06H
ACALL COMMAND
MOV A,#86H
ACALL COMMAND
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
COMMAND:
ACALL READY
MOV P2,A
CLR P3.4
CLR P1.4
SETB P3.5
CLR P3.5
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DATA_DISPLAY:
ACALL READY
MOV P2,A
SETB P3.4
CLR P1.4
SETB P3.5
ACALL DELAY
CLR P3.5
RET
READY: SETB P2.7
CLR P3.4
SETB P1.4
BACK: CLR P3.5
ACALL DELAY
SETB P3.5
JB P2.7,BACK
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TestTemperature:
ACALL Read_ADC
CJNE A,#27,CheckFurther
RelayOn:
SETB P1.3
ret
CheckFurther:
jnc RelayOn
CLR P1.3
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY_200M:
MOV R7,#30H
L1_DELAY:
MOV TMOD,#10
MOV TH1,#3CH
MOV TL1,#0B0H
SETB TR1
AGAIN: JNB TF1,AGAIN
CLR TR1
CLR TF1
DJNZ R7,L1_DELAY
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY: MOV R3,#50
HERE3: MOV R4,#255
HERE2: DJNZ R4,HERE2
DJNZ R3,HERE3
RET
END


and it shows 255
and numbers don't start from left side on lcd, but from middle...and it shoes 255->255255->255255255....

If I tried mov b,#100 then it was the same, if I tried mov b,#0x64h numbers doubeled (it showd sth 5XX->5XX5XX....

What did I do wrong?
Mon May 14 2012, 09:01 pm
#20


Thank you! Got it working! It isn't still on on room temperature, it shows abooud +- 1 degree, but that is not a big deal at the moment.

Now second part of my problem. I need to get relay to switch (for example) at 27 degrees Celsius. Could someone please write me the code for it (so I could copy-paste it to my original code).

rvs


You said here that the display was working.
Did it stop working when you added my relay code ?

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

KevinTab
Sun Apr 28 2024, 05:35 am
Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am