📄 ds18b20.lis
字号:
00B0 .dbline 85
00B0 ; ds_delay(6); //14.92us
00B0 06E0 ldi R16,6
00B2 0E940000 xcall _ds_delay
00B6 .dbline 88
00B6 ; //SET_DS18B20; //释放总线
00B6 ; //delay_nus(16); //14.92us
00B6 ; temp=wb>>i;
00B6 0A2D mov R16,R10
00B8 162F mov R17,R22
00BA 0E940000 xcall lsr8
00BE 402F mov R20,R16
00C0 .dbline 89
00C0 ; temp&=0x01;
00C0 4170 andi R20,1
00C2 .dbline 90
00C2 ; if(temp)
00C2 11F0 breq L24
00C4 .dbline 91
00C4 ; SET_DS18B20; //释放总线
00C4 A99A sbi 0x15,1
00C6 01C0 xjmp L25
00C8 L24:
00C8 .dbline 93
00C8 ; else
00C8 ; CLR_DS18B20; //强制拉低
00C8 A998 cbi 0x15,1
00CA L25:
00CA .dbline 94
00CA 02E3 ldi R16,50
00CC 0E940000 xcall _ds_delay
00D0 .dbline 96
00D0 A99A sbi 0x15,1
00D2 .dbline 97
00D2 05E0 ldi R16,5
00D4 0E940000 xcall _ds_delay
00D8 .dbline 98
00D8 L21:
00D8 .dbline 81
00D8 6395 inc R22
00DA L23:
00DA .dbline 81
00DA 6830 cpi R22,8
00DC 38F3 brlo L20
00DE .dbline -2
00DE .dbline 99
00DE ; ds_delay(50); //30.38us
00DE ; //RLS_DS18B20; //释放总线
00DE ; SET_DS18B20; //释放总线
00DE ; ds_delay(5); //2.71us(大于1us就行了)
00DE ; }
00DE ; }
00DE L19:
00DE 0E940000 xcall pop_gset3
00E2 .dbline 0 ; func end
00E2 0895 ret
00E4 .dbsym r temp 20 c
00E4 .dbsym r i 22 c
00E4 .dbsym r wb 10 c
00E4 .dbend
00E4 .dbfunc e readTempDS18B20 _readTempDS18B20 fi
00E4 ; x -> R20,R21
00E4 ; tempH -> R20
00E4 ; tempL -> R22
.even
00E4 _readTempDS18B20::
00E4 0E940000 xcall push_gset2
00E8 .dbline -1
00E8 .dbline 106
00E8 ;
00E8 ; /**********************************************************************
00E8 ; functionName: unsigned int readTempDS18B20(void)
00E8 ; description :读DS18B20温度
00E8 ; **********************************************************************/
00E8 ; unsigned int readTempDS18B20(void)
00E8 ; {
00E8 .dbline 112
00E8 ; unsigned char tempL,tempH;
00E8 ; unsigned int x;
00E8 ; //resetDS18B20();
00E8 ; //writeByteDS18B20(0xcc); //跳过ROM
00E8 ; //writeByteDS18B20(0x44); //启动温度转换
00E8 ; delay_nms(1); //等待1ms
00E8 01E0 ldi R16,1
00EA 10E0 ldi R17,0
00EC 0E940000 xcall _delay_nms
00F0 .dbline 113
00F0 ; resetDS18B20();
00F0 87DF xcall _resetDS18B20
00F2 .dbline 114
00F2 ; writeByteDS18B20(0xcc); //跳过ROM
00F2 0CEC ldi R16,204
00F4 D5DF xcall _writeByteDS18B20
00F6 .dbline 115
00F6 ; writeByteDS18B20(0xbe); //读数据
00F6 0EEB ldi R16,190
00F8 D3DF xcall _writeByteDS18B20
00FA .dbline 116
00FA ; tempL=readByteDS18B20();
00FA B1DF xcall _readByteDS18B20
00FC 602F mov R22,R16
00FE .dbline 117
00FE ; tempH=readByteDS18B20();
00FE AFDF xcall _readByteDS18B20
0100 402F mov R20,R16
0102 .dbline 118
0102 ; x=(tempH<<8)|tempL;
0102 542F mov R21,R20
0104 462F mov R20,R22
0106 .dbline 119
0106 ; resetDS18B20();
0106 7CDF xcall _resetDS18B20
0108 .dbline 120
0108 ; writeByteDS18B20(0xcc); //跳过ROM
0108 0CEC ldi R16,204
010A CADF xcall _writeByteDS18B20
010C .dbline 121
010C ; writeByteDS18B20(0x44); //启动温度转换
010C 04E4 ldi R16,68
010E C8DF xcall _writeByteDS18B20
0110 .dbline 122
0110 ; return(x);
0110 8A01 movw R16,R20
0112 .dbline -2
0112 L26:
0112 0E940000 xcall pop_gset2
0116 .dbline 0 ; func end
0116 0895 ret
0118 .dbsym r x 20 i
0118 .dbsym r tempH 20 c
0118 .dbsym r tempL 22 c
0118 .dbend
0118 .dbfunc e BCDtoASCII _BCDtoASCII fV
0118 ; j -> R20
0118 ; i -> R22
0118 ; pstr -> R18,R19
0118 ; cBCD -> R16
.even
0118 _BCDtoASCII::
0118 0E940000 xcall push_gset2
011C .dbline -1
011C .dbline 126
011C ; }
011C ; //压缩BCD码转换成ASCII码
011C ; void BCDtoASCII(unsigned char cBCD,unsigned char *pstr)
011C ; {
011C .dbline 128
011C ; unsigned char i,j;
011C ; i=cBCD>>4;
011C 602F mov R22,R16
011E 6295 swap R22
0120 6F70 andi R22,#0x0F
0122 .dbline 129
0122 ; j=cBCD&0x0F;
0122 402F mov R20,R16
0124 4F70 andi R20,15
0126 .dbline 130
0126 ; *pstr++=i+0x30;
0126 862F mov R24,R22
0128 805D subi R24,208 ; addi 48
012A F901 movw R30,R18
012C 8193 st Z+,R24
012E 9F01 movw R18,R30
0130 .dbline 131
0130 ; *pstr=j+0x30;
0130 842F mov R24,R20
0132 805D subi R24,208 ; addi 48
0134 8083 std z+0,R24
0136 .dbline -2
0136 .dbline 132
0136 ; }
0136 L27:
0136 0E940000 xcall pop_gset2
013A .dbline 0 ; func end
013A 0895 ret
013C .dbsym r j 20 c
013C .dbsym r i 22 c
013C .dbsym r pstr 18 pc
013C .dbsym r cBCD 16 c
013C .dbend
013C .dbfunc e Read_Temp _Read_Temp fV
013C ; temp -> R20,R21
.even
013C _Read_Temp::
013C 0E940000 xcall push_gset1
0140 .dbline -1
0140 .dbline 135
0140 ; //读取当前温度并解释
0140 ; void Read_Temp(void)
0140 ; {
0140 .dbline 136
0140 ; unsigned int temp=0;
0140 4427 clr R20
0142 5527 clr R21
0144 .dbline 137
0144 ; temp=readTempDS18B20();
0144 CFDF xcall _readTempDS18B20
0146 A801 movw R20,R16
0148 .dbline 138
0148 ; BCDtoASCII((temp>>8)&0x0F,&temp_buf[0]);
0148 20E0 ldi R18,<_temp_buf
014A 30E0 ldi R19,>_temp_buf
014C 012F mov R16,R17
014E 1127 clr R17
0150 0F70 andi R16,15
0152 1070 andi R17,0
0154 E1DF xcall _BCDtoASCII
0156 .dbline 139
0156 ; BCDtoASCII((temp>>8)&0x0F,&temp_buf[1]);
0156 20E0 ldi R18,<_temp_buf+1
0158 30E0 ldi R19,>_temp_buf+1
015A 8A01 movw R16,R20
015C 012F mov R16,R17
015E 1127 clr R17
0160 0F70 andi R16,15
0162 1070 andi R17,0
0164 D9DF xcall _BCDtoASCII
0166 .dbline 140
0166 ; BCDtoASCII((temp>>4)&0x0F,&temp_buf[2]);
0166 20E0 ldi R18,<_temp_buf+2
0168 30E0 ldi R19,>_temp_buf+2
016A 8A01 movw R16,R20
016C 1695 lsr R17
016E 0795 ror R16
0170 1695 lsr R17
0172 0795 ror R16
0174 1695 lsr R17
0176 0795 ror R16
0178 1695 lsr R17
017A 0795 ror R16
017C 0F70 andi R16,15
017E 1070 andi R17,0
0180 CBDF xcall _BCDtoASCII
0182 .dbline 141
0182 ; BCDtoASCII(temp&0x0F,&temp_buf[3]);
0182 20E0 ldi R18,<_temp_buf+3
0184 30E0 ldi R19,>_temp_buf+3
0186 042F mov R16,R20
0188 0F70 andi R16,15
018A 1070 andi R17,0
018C C5DF xcall _BCDtoASCII
018E .dbline -2
018E .dbline 142
018E ; }
018E L28:
018E 0E940000 xcall pop_gset1
0192 .dbline 0 ; func end
0192 0895 ret
0194 .dbsym r temp 20 i
0194 .dbend
.area bss(ram, con, rel)
0000 .dbfile D:\NEW\ECHO\ds18b20.c
0000 _temp_buf::
0000 .blkb 4
0004 .dbsym e temp_buf _temp_buf A[4:4]c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -