课程设计说明书 第14页
附录1 程序
1.BIN_BCD:
MOV DPTR,#TEMP_TAB MOV A,TEMPER_NUM MOVC
A,@A+DPTR
MOV TEMPER_NUM,A RET
TEMP_TAB:
DB 00H,01H,02H,03H,04H,05H,06H,07H DB 08H,09H,10H,11H,12H,13H,14H,15H DB 16H,17H,18H,19H,20H,21H,22H,23H DB 24H,25H,26H,27H,28H,29H,30H,31H DB 32H,33H,34H,35H,36H,37H,38H,39H DB 40H,41H,42H,43H,44H,45H,46H,47H DB 48H,49H,50H,51H,52H,53H,54H,55H DB 56H,57H,58H,59H,60H,61H,62H,63H DB 64H,65H,66H,67H,68H,69H,70H,71H DB 72H,73H,74H,75H,76H,77H,78H,79H DB 80H,81H,82H,83H,84H,85H,86H,87H DB 88H,89H,90H,91H,92H,93H,94H,95H DB 96H,97H,98H,99H
TSR1: DJNZ R0,TSR1 ; 延时512微秒
SETB DQ
MOV R0,#25H ;延时60微秒,判断18B20返回信号
TSR2: JNB DQ,TSR3 DJNZ R0,TSR2
LJMP TSR4 ; 延时
; 置标志位,表示DS18B20存在
TSR3: SETB FLAG1
课程设计说明书 第15页
LJMP TSR5
; 清标志位,表示DS18B20不存在
TSR4: CLR FLAG1
LJMP TSR7
TSR5: MOV R0,#0FFH ;512US TSR6: DJNZ R0,TSR6 ; 延时 TSR7: SETB DQ
RET
DELAY:
MOV R7,#00H
DJNZ R7,YS500
MIN:
RET
YS500US
YS500: LCALL
LJMP MIN
YS500US:MOV
DJNZ R6,$ RET
R6,#00H
DELAY1: MOV R7,#20H
DJNZ R7,$ RET END
2.VB程序: Public d As String
Private Sub Command1_Click() End End Sub
Private Sub Command2_Click() MSComm1.Output = \ Text2.Text = \下位机1信息\End Sub
课程设计说明书 第16页
Private Sub Command3_Click() MSComm1.Output = \Text2.Text = \下位机2信息\End Sub
Private Sub Command4_Click() Timer1.Interval = 1000 Timer1.Enabled = True End Sub
Private Sub Command5_Click() Timer1.Enabled = False End Sub
Private Sub Form_Load() d = \
MSComm1.CommPort = 1 MSComm1.InputLen = 0
MSComm1.Settings = \MSComm1.InBufferSize = 512 MSComm1.InBufferCount = 0 MSComm1.OutBufferSize = 512 MSComm1.OutBufferCount = 0 MSComm1.RThreshold = 1 MSComm1.SThreshold = 1 MSComm1.PortOpen = True End Sub
Private Sub MSComm1_OnComm() Dim Buf$
Select Case MSComm1.CommEvent Case comEvReceive Buf = MSComm1.Input
课程设计说明书 第17页
a = Mid(Buf, 1, 1) b = Asc(a)
Text1.Text = Hex(b) c = Mid(Buf, 2, 1) If c = \ Shape1.FillColor = vbRed Else
Shape1.FillColor = vbGreen End If Case Else End Select End Sub
Private Sub Timer1_Timer() MSComm1.Output = d If d = \
Text2.Text = \下位机1信息\ e = d + 1 d = e Else
Text2.Text = \下位机2信息\ d = \ End If End Sub