START EQU 20H.0
INPUT EQU 20H.1
KEY EQU 21H
PWM_ZKB EQU 22H
PWM_CNT EQU 23H
FLAG EQU 30H
U8comdata EQU 31H
U8T_data_H EQU 32H
U8T_data_L EQU 33H
U8RH_data_H EQU 34H
U8RH_data_L EQU 35H
U8checkdata EQU 36H
U8temp EQU 37H
temp EQU 38H
IN1 BIT P1.0
IN2 BIT P1.1
ENA BIT P1.2
RS BIT P2.0
RW BIT P2.1
E BIT P2.2
DQ BIT P2.3
ORG 0000H
AJMP MAIN
ORG 001BH
LJMP T1_ISR
ORG 0100H
MAIN:
MOV SP,#60H
MOV PWM_ZKB,#70
LCALL SETLCD
LCALL LINE1
MOV DPTR,#TAB1
LCALL LCDDISP
LCALL T1_INIT
LOOP:
LCALL KEYSCAN
LCALL KEYPROC
LCALL DHT11
LCALL DISPLAY
JMP LOOP
T1_INIT:
MOV TMOD,#10H
MOV TH1,#0FCH
MOV TL1,#018H
SETB ET1
SETB TR1
SETB EA
RET
T1_ISR:
PUSH ACC
MOV TH1,#0FCH
MOV TL1,#018H
INC PWM_CNT
MOV A,PWM_CNT
CJNE A,#100,T1_0
MOV PWM_CNT,#0
T1_0:
CLR C
MOV B,PWM_ZKB
MOV A,PWM_CNT
SUBB A,B
JNC PWM_0
SETB ENA
JMP T1_END
PWM_0:
CLR ENA
T1_END:
POP ACC
RETI
Read:
MOV temp,#8
MOV U8comdata,#0
LOOP_COM:
MOV FLAG,#0
LOOP3:
INC FLAG
MOV A,FLAG
JB DQ,LOOP3_END
CJNE A,#0,LOOP3
LJMP COM_END
LOOP3_END:
LCALL Delay_10us
LCALL Delay_10us
LCALL Delay_10us
MOV U8temp,#0
JNB DQ,HIGH_END
MOV U8temp,#1
HIGH_END:
MOV FLAG,#0
LOOP4:
INC FLAG
MOV A,FLAG
JNB DQ,LOOP4_END
CJNE A,#0,LOOP4
LJMP COM_END
LOOP4_END:
MOV A,FLAG
CJNE A,#0,NO_FLAG
LJMP COM_END
NO_FLAG:
MOV A,U8comdata
RL A
ORL A,U8temp
MOV U8comdata,A
DJNZ temp,LOOP_COM
COM_END:
RET
DHT11:
CLR EA
CLR DQ
MOV A,#36
LCALL Delay
SETB DQ
LCALL Delay_10us
LCALL Delay_10us
LCALL Delay_10us
LCALL Delay_10us
JB DQ,RH_END
MOV FLAG,#0
LOOP1:
INC FLAG
MOV A,FLAG
JB DQ,LOOP1_END
CJNE A,#0,LOOP1
LJMP RH_END
LOOP1_END:
MOV FLAG,#0
LOOP2:
INC FLAG
MOV A,FLAG
JNB DQ,LOOP2_END
CJNE A,#0,LOOP2
LJMP RH_END
LOOP2_END:
LCALL Read
MOV U8RH_data_H,U8comdata
LCALL Read
MOV U8RH_data_L,U8comdata
LCALL Read
MOV U8T_data_H,U8comdata
LCALL Read
MOV U8T_data_L,U8comdata
LCALL Read
MOV U8checkdata,U8comdata
SETB DQ
RH_END:
SETB EA
RET
KEYSCAN:
SETB F0
MOV KEY,#16H
MOV R3,#0FEH
MOV R1,#00H
L2: MOV A,R3
MOV P3,A
LCALL DELAY1MS
MOV A,P3
SWAP A
SETB C
MOV R5,#4
L3: RRC A
JNC KEY1
INC R1
DJNZ R5,L3
MOV A,R3
SETB C
RLC A
MOV R3,A
JB ACC.4,L2
LJMP KEY_OUT
KEY1:
CLR F0
MOV KEY,R1
T3: MOV A,P3
XRL A,R3
JNZ T3
KEY_OUT:
RET
KEYPROC:
MOV A,KEY
CJNE A,#16H,K_0
RET
K_0:CLR C
SUBB A,#10
JNC G10
L10:MOV A,KEY
ADD A,#'0'
LCALL LCDDAT
JMP KP_END
G10:MOV A,KEY
CJNE A,#0AH,T0B
SETB INPUT
MOV A,#83H
LCALL LCDCMD
MOV DPTR,#M_CL2
LCALL LCDDISP
MOV A,#83H
LCALL LCDCMD
MOV A,#0DH
LCALL LCDCMD
JMP KP_END
T0B:CJNE A,#0BH,T0C
CLR INPUT
MOV A,#0CH
LCALL LCDCMD
JMP KP_END
T0C:CJNE A,#0CH,T0D
JB START,STOP
SETB START
CLR IN1
SETB IN2
JMP KP_END
STOP:
CLR START
SETB IN1
SETB IN2
JMP KP_END
T0D:CJNE A,#0DH,T0E
CPL IN1
CPL IN2
JMP KP_END
T0E:CJNE A,#0EH,T0F
MOV A,PWM_ZKB
CJNE A,#50,DEC_20
JMP KP_END
DEC_20:
SUBB A,#20
MOV PWM_ZKB,A
JMP KP_END
T0F:CJNE A,#0FH,KP_END
MOV A,PWM_ZKB
CJNE A,#90,ADD_20
JMP KP_END
ADD_20:
ADD A,#20
MOV PWM_ZKB,A
KP_END:
RET
DISPLAY:
JB INPUT,DISP_END
CLR EA
PUSH ACC
LCALL LINE2
MOV A,#'T'
LCALL LCDDAT
MOV A,#':'
LCALL LCDDAT
MOV A,U8T_data_H
MOV B,#10
DIV AB
ADD A,#'0'
LCALL LCDDAT
XCH A,B
ADD A,#'0'
LCALL LCDDAT
MOV A,#0DFH
LCALL LCDDAT
MOV A,#'C'
LCALL LCDDAT
MOV A,#' '
LCALL LCDDAT
MOV A,#'R'
LCALL LCDDAT
MOV A,#':'
LCALL LCDDAT
MOV A,U8RH_data_H
MOV B,#10
DIV AB
ADD A,#'0'
LCALL LCDDAT
XCH A,B
ADD A,#'0'
LCALL LCDDAT
MOV A,#'%'
LCALL LCDDAT
POP ACC
SETB EA
DISP_END:
RET
DISP_NUM_2:
MOV B,#10
DIV AB
ADD A,#'0'
LCALL LCDDAT
MOV A,B
ADD A,#'0'
LCALL LCDDAT
RET
DISP_NUM_3:
MOV B,#100
DIV AB
ADD A,#'0'
LCALL LCDDAT
MOV A,B
MOV B,#10
DIV AB
ADD A,#'0'
LCALL LCDDAT
MOV A,B
ADD A,#'0'
LCALL LCDDAT
MOV A,#' '
LCALL LCDDAT
RET
DELAY1MS:
MOV R7,#01H
DL1:MOV R6,#8EH
DL0:MOV R5,#02H
DJNZ R5,$
DJNZ R6,DL0
DJNZ R7,DL1
RET
Delay: MOV R4,A
D1: MOV R5,#0FFH
DJNZ R5,$
DJNZ R4,D1
RET
Delay_10us:
NOP
NOP
NOP
NOP
NOP
NOP
RET
Delay_2S:
MOV A,#250
LCALL Delay
MOV A,#250
LCALL Delay
MOV A,#250
LCALL Delay
MOV A,#250
LCALL Delay
MOV A,#250
LCALL Delay
MOV A,#250
LCALL Delay
MOV A,#250
LCALL Delay
MOV A,#250
LCALL Delay
RET
SETLCD:
MOV A,#01H
ACALL LCDCMD
MOV A,#38H
ACALL LCDCMD
MOV A,#0CH
ACALL LCDCMD
MOV A,#06H
ACALL LCDCMD
ACALL LCDFONT
RET
LCDCMD:
CLR RS
CLR RW
MOV P0,A
CLR E
ACALL WAIT
SETB E
RET
LCDDAT:
SETB RS
CLR RW
MOV P0,A
CLR E
ACALL WAIT
SETB E
RET
WAIT:
MOV P0,#0FFH
CLR RS
SETB RW
CLR E
NOP
SETB E
JB P0.7,WAIT
RET
LINE1:
MOV A,#80H
ACALL LCDCMD
RET
LINE2:
MOV A,#0C0H
ACALL LCDCMD
RET
LCDBSP:
MOV A,#10H
ACALL LCDCMD
MOV A,#' '
ACALL LCDDAT
MOV A,#10H
ACALL LCDCMD
RET
LCDDISP:
MOV R2,#00H
NEXT:
MOV A,R2
MOVC A,@A+DPTR
CJNE A,#10H,DSP
RET
DSP:ACALL LCDDAT
INC R2
AJMP NEXT
RET
LCDFONT:
MOV A,#40H
LCALL LCDCMD
MOV DPTR,#FONT
MOV R1, #00H
LOP2:MOV A,R1
MOVC A, @A+DPTR
ACALL LCDDAT
INC R1
CJNE R1,#10H, LOP2
RET
M_CLS: DB " ",10H
M_CL2: DB " ",10H
FONT:
DB 00H,1FH,04H,1FH,04H,04H,1FH,00H
DB 00H,1FH,00H,0EH,00H,00H,1FH,00H
TAB1: DB 00H,01H," 12345678",10H
END
|