CRC校验正确,换过多个DS18B20,部分数据如下(水银温度计读数为15.1度).
两个DS18B20的ROM数据
序列号1:28h,0d6h,0dah,0a6h,01h,00h,00h,80h
序列号2:28h,70h,0fah,61h,01h,00h,00h,29h
序列号为1的DS18B20所读RAM数据:
9位分辨率:18h,01h,00h,00h,1fh,0ffh,08h,10h,0d8h
10位分辨率:18h,01h,00h,00h,3fh,0ffh,08h,10h,0a8h
11位分辨率:1ch,01h,00h,00h,5fh,0ffh,04h,10h,60h
11位分辨率:18h,01h,00h,00h,5fh,0ffh,08h,10h,38h
12位分辨率:1ah,01h,00h,00h,7fh,0ffh,06h,10h,12h
温度数据转换子程序(12位分辨率,不考虑符号位,因温度恒为正)
mov a,temp_h
anl a,#07h
swap a
mov temp_h,a
mov a,temp_l
anl a,#0f0h
swap a
orl a,temp_h
mov b,#10
div ab
mov led_1,a ;十位数存入
mov led_2,b ;个位数存入
mov a,temp_l
anl a,#0fh
mov dptr,#tab_2
movc a,@a+dptr
mov led_3,a ;小数位存入
mov r1,#led_1
mov r2,#3
mov dptr,#tab_1
chang1:mov a,@r1 ;缓存转换为数码管段码
movc a,@a+dptr
mov @r1,a
inc r1
djnz r2,chang1
mov a,led_2
anl a,#0efh ;显示小数点
mov led_2,a
ret
tab_1: ;段码数据表
db 14h,3fh,98h,1ah,33h,52h,50h,3eh,10h,12h
tab_2: ;温度小数位四舍五入转换
db 00h,01h,01h,02h,03h,03h,04h,04h,05h,06h,06h,07h,08h,08h,09h,09h |