Thehieu

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

$include(reg51.

inc)
irh equ 20h
drh equ 21h
itemp equ 23h
dtemp equ 24h
temp equ 25h
kq equ 50h
dht11 bit p2.0
rs bit p1.0
en bit p1.1
quat bit p3.1
bom bit p3.2
clr en
call khoitao_lcd
mov p0,#0
mov p1,#0
mov p3,#0
mov temp,#0
main:
mov p1,temp
call request
call response
call receive
mov irh,kq
call receive
mov drh,kq
call receive
mov itemp,kq
call receive
mov dtemp,kq
call lcd
mov a,itemp
cjne a,#27,nhietdo
doam:
mov a,temp
jnz doam3
mov a,irh
cjne a,#41,doam2
doam2:
jnc main
mov temp,#1
jmp main
doam3:
mov a,irh
cjne a,#60,doam4
doam4:
jnc lon2
setb bom
jmp main
lon2:
clr bom
mov temp,#0
jmp main
nhietdo:
jnc lon
clr quat
jmp doam
lon:
setb quat
setb temp
jmp doam
;--------------------------------
delay20ms:
mov tmod,#1
mov th0,#0b1h
mov tl0,#0dfh
setb tr0
jnb tf0,$
clr tr0
clr tf0
ret
;-------------------------
delay30us:
mov tmod,#1
mov th0,#0ffh
mov tl0,#0e1h
setb tr0
jnb tf0,$
clr tr0
clr tf0
ret
;---------------------------
request:
clr dht11
call delay20ms
setb dht11
ret
;---------------------------
response:
jb dht11,$
jnb dht11,$
jb dht11,$
ret
;------------------------
receive:
mov r1,#0
mov r2,#0
x3:
jnb dht11,$
call delay30us
jnb dht11,x1
mov a,r1
rl a
mov b,#1
add a,b
mov r1,a
jmp x2
x1:
mov a,r1
rl a
mov r1,a
x2:
jb dht11,$
inc r2
cjne r2,#8,x3
mov kq,r1
ret
;-------------------------------
lcd:
mov a,#80h
call write_command
mov r0,#0
mov dptr,#string1
loop1:
mov a,r0
movc a,@a+dptr
call write_data
inc r0
cjne r0,#10,loop1
mov a,itemp
mov dptr,#string2
;-------------------------
mov b,#10
div ab
movc a,@a+dptr
call write_data
mov a,b
movc a,@a+dptr
call write_data
mov a,#223
call write_data
mov a,#67
call write_data
;----------------------------
mov a,#0c0h
call write_command
mov r0,#0
mov dptr,#string3
loop2:
mov a,r0
movc a,@a+dptr
call write_data
inc r0
cjne r0,#10,loop2
;----------------------------------
mov a,irh
mov dptr,#string2
mov b,#10
div ab
movc a,@a+dptr
call write_data
mov a,b
movc a,@a+dptr
call write_data
mov a,#25h
call write_data
ret
;*************************************************
khoitao_lcd:
mov a,#38h
call write_command
mov a,#38h
call write_command
mov a,#0ch
call write_command
mov a,#01h
call write_command
ret
;*************************************************
write_command:
mov p0,a
clr rs
setb en
clr en
call delay_41ms
ret
;*************************************************
write_data:
mov p0,a
setb rs
setb en
clr en
call delay_100us
ret
;*************************************************
delay_41ms:
mov 50h,#205
del:
mov 51h,#100
djnz 51h,$
djnz 50h,del
ret
;*************************************************
delay_100us:
mov 50h,#100
djnz 50h,$
ret
;************************************************
string1: db 'nhiet do: '
string2: db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h
string3: db 'do am: '
end

You might also like