📄 send.asm
字号:
T2CON data 0C8H
T2MOD data 0C9H
TH2 data 0CDH
TL2 data 0CCH
org 0
LJMP main
org 03h
LJMP p_int0
org 0bh
inc a ;
reti
org 13h
LJMP p_int1
org 23h
LJMP P_S
;TempH data 30h ;DS18B20高字节
;TempL data 31h ; 低字节
danwmax0H data 32h ;单稳态触发器0最大值的高字节
danwmax1H data 34h ;单稳态触发器1最大值的高字节
alerttempe0 data 36h
alerttempe1 data 35h
psecond data 3bh ;10ms * X
sendsymbol bit 00h
danwtrig0 bit p1.2
danwtrig1 bit p1.3
sendenable bit p2.0
key1 bit p3.5 ;调到时间常数最大,并按这个键2S
key2 bit p3.6 ;调到时间常数最小,并按这个键2S
key3 bit p3.7 ;按这个键发送当前上限温度(隔一段时间发另一路)
org 30h
main:
CLR EA
MOV SP,#6FH
ACALL init
main1: jnb key1,setupalert
jnb key3,disptemp
;调用DS18B20测量温度
lcall ReadTemp0
mov b,a
clr c
subb a,alerttempe0
mov a,b
jc testtemp1
lcall fillasciic
sjmp $+5
testtemp1:
lcall fillasciia
mov 51h,#31h
LCALL counttempe
lcall ReadTemp1
mov b,a
clr c
subb a,alerttempe1
mov a,b
jc testtemp2
lcall fillasciic
sjmp $+5
testtemp2:
lcall fillasciia
mov 51h,#32h
LCALL counttempe
LJMP main1
disptemp:
mov th0,#0a6h ;158=256-98 9fh
mov tl0,#0a6h
mov a,#0
clr danwtrig0
setb tr0
setb danwtrig0
jb p3.3,$
clr tr0
LCALL fillasciib
mov 51h,#31h
LCALL counttempe
mov th0,#0a7h ;158=256-98 9fh
mov tl0,#0a7h
mov a,#0
clr danwtrig1
setb tr0
setb danwtrig1
jb p3.2,$
clr tr0
LCALL fillasciib
mov 51h,#32h
LCALL counttempe
LJMP main1
setupalert:
mov th0,#0a6h ;158=256-98 9fh
mov tl0,#0a6h
mov a,#0
clr danwtrig0
setb tr0
setb danwtrig0
jb p3.3,$
clr tr0
mov alerttempe0,a
LCALL fillasciid
mov 51h,#31h
LCALL counttempe
mov th0,#0a7h ;158=256-98 9fh
mov tl0,#0a7h
mov a,#0
clr danwtrig1
setb tr0
setb danwtrig1
jb p3.2,$
clr tr0
mov alerttempe1,a
LCALL fillasciid
mov 51h,#32h
LCALL counttempe
LJMP main1
counttempe:
mov b,a
lcall tempe2ASCII
setb RS0
mov r1,#50h
mov r3,#9
clr RS0
setb sendsymbol
setb TI
jb sendsymbol,$
mov a,#250
LCALL delayms
mov a,#250
LCALL delayms
mov a,#250
LCALL delayms
ret
tempe2ASCII:
mov a,b
mov b,#40
div ab
orl a,#30h
mov 54h,a
mov a,b
mov b,#4
div ab
orl a,#30h
mov 55h,a
mov a,#10
mul ab
mov b,#4
div ab
orl a,#30h
mov 56h,a
ret
;结果在A A=tempetrature*4
ReadTemp0:
clr ea
acall DS18Binit
mov a,#0cch ;skip ROM
acall DS18BWByte
mov a,#44h ;start convert tempetrature
acall DS18BWByte
mov a,#250 ;delay 250ms
acall delayms
mov a,#250 ;delay 250ms
acall delayms
acall DS18Binit
mov a,#0cch ;skip ROM
acall DS18BWByte
mov a,#0beh ;read tempetrature
acall DS18BWByte
acall DS18BRByte
mov r7,a
acall DS18BRByte
setb ea
clr c ;右移一位
rrc a
xch a,r7
rrc a
xch a,r7
clr c ;右移一位
rrc a
xch a,r7
rrc a
RET
;结果在A A=tempetrature*4
ReadTemp1:
clr ea
acall DS18Binit1
mov a,#0cch ;skip ROM
acall DS18BWByte1
mov a,#44h ;start convert tempetrature
acall DS18BWByte1
mov a,#250 ;delay 250ms
acall delayms
mov a,#250 ;delay 250ms
acall delayms
acall DS18Binit1
mov a,#0cch ;skip ROM
acall DS18BWByte1
mov a,#0beh ;read tempetrature
acall DS18BWByte1
acall DS18BRByte1
mov r7,a
acall DS18BRByte1
setb ea
clr c ;右移一位
rrc a
xch a,r7
rrc a
xch a,r7
clr c ;右移一位
rrc a
xch a,r7
rrc a
RET
;--------------------------------
;发送测量结果,和报警信息
;使用寄存器组1 ,sendsymbol=1是发送数据
P_S: push psw
push ACC
setb RS0 ;切换到寄存器组1
JBC TI,P_TI
p_RI: JBC RI,$+2
p_TI: jnb sendsymbol,p_TI_END
mov a,@r1
mov SBUF,a
inc r1
djnz r3,P_TI_END
jnb ti,$ ;发送最后一字节时要等待发送完成,并清除标志
clr ti
clr sendsymbol ;所有数据发送完成后,清除发送标志
p_TI_END:
pop ACC
pop PSW
RETI
init:
mov r0,#20h
mov r2,#50
mov a,#0
init1: mov @r0,a
inc r0
DJNZ r2,init1
clr sendsymbol ;串口发送数据标志位,每次数据准备好,就为1
clr tr1
clr tr0
mov r1,#50h
mov r3,#8
mov TMOD,#022h ;
mov th1,#0fdh ;9600bps
mov tl1,#0fdh
mov PCON,#00h ;波特率no加倍
mov SCON,#50h ;8bit可变速率,mode 1
setb sendenable ;设置485为发送状态
mov th0,#0 ;10ms
mov tl0,#0
mov TCON,#05 ;下降沿触发
setb tr1
mov IE,#0 ;中断全部禁止
setb et0
mov IP,#05h ;外部中断高优先级
setb ES
setb EA
; mov T2CON,#0
; mov TH2,#
; mov TL2,#
; mov T2MOD,#34h ;
RET
delayms:
mov b,#250
nop
nop
DJNZ b,$-2
DJNZ acc,delayms
ret
DS18B20IO bit p1.1
DS18B20IO1 bit p1.0
DS18Binit:
setb c
mov a,#0
clr DS18B20IO
mov B,#250
DJNZ B,$ ;delay 500uS
setb DS18B20IO
nop
jb DS18B20IO,$ ;delay 15-60uS
mov b,#10
DJNZ b,$ ;
jnb DS18B20IO,$
clr c
DS18Binitend:
ret
DS18Binit1:
setb c
mov a,#0
clr DS18B20IO1
mov B,#250
DJNZ B,$ ;delay 500uS
setb DS18B20IO1
nop
jb DS18B20IO1,$ ;delay 15-60uS
mov b,#10
DJNZ b,$ ;
jnb DS18B20IO1,$
clr c
DS18Binitend1:
ret
DS18BWbit:
mov b,#28
clr DS18B20IO
nop
nop
nop
nop
nop
mov DS18B20IO,c
DJNZ b,$
setb DS18B20IO
ret
DS18BWbit1:
mov b,#28
clr DS18B20IO1
nop
nop
nop
nop
nop
mov DS18B20IO1,c
DJNZ b,$
setb DS18B20IO1
ret
;
DS18BWByte:
mov r2,#8
DS18BWByte10:
RRC a
acall DS18BWbit
DJNZ r2,DS18BWByte10
ret
;1
DS18BWByte1:
mov r2,#8
DS18BWByte11:
RRC a
acall DS18BWbit1
DJNZ r2,DS18BWByte11
ret
DS18BRbit:
mov b,#23
clr DS18B20IO
nop
nop
nop
nop
nop
setb DS18B20IO
nop
nop
mov c,DS18B20IO
nop
DJNZ b,$
setb DS18B20IO
ret
DS18BRbit1:
mov b,#23
clr DS18B20IO1
nop
nop
nop
nop
nop
setb DS18B20IO1
nop
nop
mov c,DS18B20IO1
nop
DJNZ b,$
setb DS18B20IO1
ret
;
DS18BRByte:
mov R2,#8
DS18BRByte10:
acall DS18BRbit
RRC a
DJNZ R2,DS18BRByte10
ret
;
DS18BRByte1:
mov R2,#8
DS18BRByte11:
acall DS18BRbit1
RRC a
DJNZ R2,DS18BRByte11
ret
p_int0:
; clr tr0
; mov danwT0H,th0
; mov danwT0L,tl0
reti
p_int1:
; clr tr1
; mov danwT1H,th1
; mov danwT1L,tl1
reti
fillasciia:
mov 50h,#"A"
; mov 51h,#31h
mov 52h,#"="
mov 53h,#"="
mov 57h,#"C"
mov 58h,#0dh ;回车符
ret
fillasciib:
mov 50h,#"B"
; mov 51h,#31h
mov 52h,#"="
mov 53h,#"="
mov 57h,#"C"
mov 58h,#0dh ;回车符
ret
fillasciic:
mov 50h,#"C"
; mov 51h,#31h
mov 52h,#">"
mov 53h,#"P"
mov 57h,#"C"
mov 58h,#0dh ;回车符
ret
fillasciid:
mov 50h,#"D"
; mov 51h,#31h
mov 52h,#"="
mov 53h,#"="
mov 57h,#"C"
mov 58h,#0dh ;回车符
ret
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -