基于DS18B20和上位机显示的数字温度计设计汇编语言
时间: 2024-01-21 14:19:02 浏览: 103
51单片机DS18B20+单片机设计数字温度计
这里提供基于AT89C51单片机的DS18B20数字温度计设计汇编语言的代码,使用串口通信将温度数据发送至上位机进行显示。
```
$mod51
ORG 0H
MOV P1,#00H
MOV P2,#01H
AGAIN: SETB P1.0
ACALL DELAY5US
CLR P1.0
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
CLR P1.0
ACALL DELAY5US
MOV A,P1.1
INC R0
MOV R1,A
MOV A,R0
CJNE A,#09H,AGAIN
SETB P1.0
ACALL DELAY5US
CLR P1.0
ACALL DELAY5US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,P1.1
MOV P2.0,A
ACALL DELAY60US
MOV A,R1
MOV R2,A
MOV A,#0
MOV R3,#0
MOV A,R2
ANL A,#0FH
MOV R4,A
MOV A,R2
SWAP A
ANL A,#0FH
MOV R2,A
MOV A,R2
ADD A,R4
MOV R2,A
MOV A,R2
MOV R3,A
MOV A,#0
CLR C
SUBB A,#32H
MOV R4,A
MOV A,R3
ADD A,R4
MOV R3,A
SEND: MOV A,R3
MOV SBUF,A
ACALL DELAY100MS
MOV A,R2
MOV SBUF,A
ACALL DELAY100MS
SJMP AGAIN
DELAY5US:
NOP
NOP
NOP
NOP
RET
DELAY60US:
MOV R6,#1
WAIT: DJNZ R6,WAIT
RET
DELAY100MS:
MOV R5,#10
WAIT1: MOV R7,#250
WAIT2: DJNZ R7,WAIT2
DJNZ R5,WAIT1
RET
END
```
这里使用了AT89C51单片机进行编程,通过P1口向DS18B20发送指令并接收温度数据,最后使用串口通信将温度数据发送至上位机进行显示。请注意,代码中的延时函数(DELAY5US、DELAY60US和DELAY100MS)需要根据实际情况进行调整。
阅读全文