专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
51单片机
多个DS18B20并联,求指导!
2020-02-04 09:12
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
51单片机
16281
51
51
哪位大侠做过多个DS18B20并联?希望能给予指导,不会走太多弯路。
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
50条回答
zhxzhx
1楼-- · 2020-02-09 10:45
DFH, 00H, 00H, 03H, AAH, 84H, C4H, 28H
你的顺序反了,应该是
28H,C4H,84H,AAH,03H,00H,00H,DFH
还应该有一个CRC的校验
加载中...
lvwenjie
2楼-- · 2020-02-09 11:12
精彩回答 2 元偷偷看……
加载中...
zhxzhx
3楼-- · 2020-02-09 14:46
你的程序成功了吗?
我给你个搜索程序吧
/*搜索过程的程序代码*/
#define FALSE 0
#define TRUE 1
//bit OWFirst(unsigned char select);
bit OWSearch(unsigned char select);
unsigned char docrc8(unsigned char value);
idata char LastDiscrepancy;
bit LastDeviceFlag;
idata unsigned char crc8;
//--------------------------------------------------------------------------
// Perform the 1-Wire Search Algorithm on the 1-Wire bus using the existing
// search state.
// Return TRUE : device found, ROM number in ROM_NO buffer
// FALSE : device not found, end of search
//
bit OWSearch(unsigned char select)
{
idata unsigned char id_bit_number;
idata unsigned char last_zero, rom_byte_number;
bit search_result;
bit id_bit, cmp_id_bit;
idata unsigned char rom_byte_mask;
bit search_direction;
id_bit_number = 1;
last_zero = 0;
rom_byte_number = 0;
rom_byte_mask = 1;
search_result = 0;
crc8 = 0;
if (!LastDeviceFlag)
{
OWInit(select);
if (!flag)
{
LastDiscrepancy = 0;
LastDeviceFlag = FALSE;
return FALSE;
}
OWWriteByte(0xF0,select);
do
{
id_bit = OWReadBit(select,0); //0
cmp_id_bit = OWReadBit(select,0); //0
if ((id_bit == 1) && (cmp_id_bit == 1)) //11
{_nop_();
break;
}
else
{
if (id_bit != cmp_id_bit) //10 01
search_direction = id_bit; // bit write value for search
else
{ //00
if (id_bit_number < LastDiscrepancy)
search_direction = ((temp_buff[rom_byte_number] & rom_byte_mask) > 0);
else
search_direction = (id_bit_number == LastDiscrepancy);
if (search_direction == 0)
{last_zero = id_bit_number;
}
}
if (search_direction == 1)
temp_buff[rom_byte_number] |= rom_byte_mask;
else
temp_buff[rom_byte_number] &= ~rom_byte_mask;
OWWriteBit(search_direction,select);
id_bit_number++;
rom_byte_mask <<= 1;
if (rom_byte_mask == 0)
{docrc8(temp_buff[rom_byte_number]); // accumulate the OWCRC
rom_byte_number++;
rom_byte_mask = 1;
}
}
}
while(rom_byte_number < 8); // loop until through all ROM bytes 0-7
if (!((id_bit_number < 65) || (crc8 != 0)))
{LastDiscrepancy = last_zero;
if (LastDiscrepancy == 0)
LastDeviceFlag = TRUE;
search_result = TRUE;
}
}
if (!search_result || !temp_buff[0])
{LastDiscrepancy = 0;
LastDeviceFlag = FALSE;
search_result = FALSE;
}
return search_result;
}
unsigned char docrc8(unsigned char value)
{
crc8 = CrcTable[crc8 ^ value];
return crc8;
}
加载中...
zhxzhx
4楼-- · 2020-02-09 15:11
这是使用方法
没有的部分你自己过滤吧,
我这个程序是可以选择多个IO口的,SElect定义的,你不要理它,具体的DS18b20读写,你应该知道的
void scan1820(unsigned char select)
{bit rslt;
idata unsigned char i,cnt;
float idata ls;
unsigned int idata lsi;
cnt = 0;
LastDiscrepancy = 0;
LastDeviceFlag = FALSE;
rslt=OWSearch(select);
PTT=0;
while (rslt)
{
cnt++;
putbyte('0');
putbyte('x');
puthex(select);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[0]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[1]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[2]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[3]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[4]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[5]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[6]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[7]);
putbyte(',');
putbyte('/');
putbyte('/');
putbyte(' ');
putbyte('=');
putbyte(' ');
DOG=~DOG;
ls=0;
if (temp_buff[0]==0x28) //DS18B20
{OWInit (select);
OWWriteByte(0xcc,select); //skip rom
OWWriteByte(0x44,select); //Temperature convert
ls=gettemp(select);
}
if (temp_buff[0]==0xA6) //DS2438
{inid=0;
OWInit (select);
OWWriteByte(0xcc,select); //skip rom
OWWriteByte(0x4E,select);
OWWriteByte(0x00,select);
OWWriteByte(0x00,select);
OWInit (select);
OWWriteByte(0xcc,select); //skip rom
OWWriteByte(0x48,select);
OWWriteByte(0x00,select);
delay(250);
OWInit (select);
OWWriteByte(0xcc,select); //skip rom
OWWriteByte(0xB4,select); //Temperature convert
ls=getvol(select);
}
ls*=10;
lsi=ls;
putint(lsi);
putbyte(' ');
putbyte(':');
putbyte(' ');
putint(inid/256);
putbyte(' ');
putint(inid & 0xFF);
putbyte(' ');
putint(cnt);
putbyte(0x0d);
putbyte(0x0a);
rslt = OWSearch(select);
}
PTT=1;
}
加载中...
zhxzhx
5楼-- · 2020-02-09 15:42
putbyte 是串口发送,PTT是485的收发控制,可以不理他
?带行号的程序是怎么出来的?
加载中...
lvwenjie
6楼-- · 2020-02-09 16:04
zhxzhx 发表于 2012-4-16 15:38
你的程序成功了吗?
我给你个搜索程序吧
/*搜索过程的程序代码*/
成功了,不过时间挺长的
加载中...
首页
上一页
2
3
4
5
6
7
8
9
下一页
一周热门
更多
>
相关问题
【东软载波ESF0654 PDS开发板活动】开箱
1 个回答
东软载波ESF0654 PDS开发板外部中断
1 个回答
东软载波ESF0654 PDS开发板高级控制定时器AD16C4T
1 个回答
用串口调试助手为什么只能在hex模式接收发送而在文本模式不行
9 个回答
触摸芯片SC02B/SC04B在地砖灯的设计方案
1 个回答
东软载波ESF0654 PDS开发板串口USART0代码分享
1 个回答
普通32位单片机使用linux的应用代码
5 个回答
东软载波ESF0654 PDS开发板AT24C04的调试
9 个回答
相关文章
51单片机与蓝牙模块连接
0个评论
51单片机的硬件结构
0个评论
基于51单片机的无线遥控器制作
0个评论
51单片机 AD转换
0个评论
51单片机数码管递增显示
0个评论
如何实现对单片机寄存器的访问
0个评论
基于51单片机的指纹密码锁
0个评论
×
关闭
采纳回答
向帮助了您的网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
51单片机
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
关闭
您已邀请
15
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
你的顺序反了,应该是
28H,C4H,84H,AAH,03H,00H,00H,DFH
还应该有一个CRC的校验
我给你个搜索程序吧
/*搜索过程的程序代码*/
#define FALSE 0
#define TRUE 1
//bit OWFirst(unsigned char select);
bit OWSearch(unsigned char select);
unsigned char docrc8(unsigned char value);
idata char LastDiscrepancy;
bit LastDeviceFlag;
idata unsigned char crc8;
//--------------------------------------------------------------------------
// Perform the 1-Wire Search Algorithm on the 1-Wire bus using the existing
// search state.
// Return TRUE : device found, ROM number in ROM_NO buffer
// FALSE : device not found, end of search
//
bit OWSearch(unsigned char select)
{
idata unsigned char id_bit_number;
idata unsigned char last_zero, rom_byte_number;
bit search_result;
bit id_bit, cmp_id_bit;
idata unsigned char rom_byte_mask;
bit search_direction;
id_bit_number = 1;
last_zero = 0;
rom_byte_number = 0;
rom_byte_mask = 1;
search_result = 0;
crc8 = 0;
if (!LastDeviceFlag)
{
OWInit(select);
if (!flag)
{
LastDiscrepancy = 0;
LastDeviceFlag = FALSE;
return FALSE;
}
OWWriteByte(0xF0,select);
do
{
id_bit = OWReadBit(select,0); //0
cmp_id_bit = OWReadBit(select,0); //0
if ((id_bit == 1) && (cmp_id_bit == 1)) //11
{_nop_();
break;
}
else
{
if (id_bit != cmp_id_bit) //10 01
search_direction = id_bit; // bit write value for search
else
{ //00
if (id_bit_number < LastDiscrepancy)
search_direction = ((temp_buff[rom_byte_number] & rom_byte_mask) > 0);
else
search_direction = (id_bit_number == LastDiscrepancy);
if (search_direction == 0)
{last_zero = id_bit_number;
}
}
if (search_direction == 1)
temp_buff[rom_byte_number] |= rom_byte_mask;
else
temp_buff[rom_byte_number] &= ~rom_byte_mask;
OWWriteBit(search_direction,select);
id_bit_number++;
rom_byte_mask <<= 1;
if (rom_byte_mask == 0)
{docrc8(temp_buff[rom_byte_number]); // accumulate the OWCRC
rom_byte_number++;
rom_byte_mask = 1;
}
}
}
while(rom_byte_number < 8); // loop until through all ROM bytes 0-7
if (!((id_bit_number < 65) || (crc8 != 0)))
{LastDiscrepancy = last_zero;
if (LastDiscrepancy == 0)
LastDeviceFlag = TRUE;
search_result = TRUE;
}
}
if (!search_result || !temp_buff[0])
{LastDiscrepancy = 0;
LastDeviceFlag = FALSE;
search_result = FALSE;
}
return search_result;
}
unsigned char docrc8(unsigned char value)
{
crc8 = CrcTable[crc8 ^ value];
return crc8;
}
没有的部分你自己过滤吧,
我这个程序是可以选择多个IO口的,SElect定义的,你不要理它,具体的DS18b20读写,你应该知道的
void scan1820(unsigned char select)
{bit rslt;
idata unsigned char i,cnt;
float idata ls;
unsigned int idata lsi;
cnt = 0;
LastDiscrepancy = 0;
LastDeviceFlag = FALSE;
rslt=OWSearch(select);
PTT=0;
while (rslt)
{
cnt++;
putbyte('0');
putbyte('x');
puthex(select);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[0]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[1]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[2]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[3]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[4]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[5]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[6]);
putbyte(',');
putbyte('0');
putbyte('x');
puthex(temp_buff[7]);
putbyte(',');
putbyte('/');
putbyte('/');
putbyte(' ');
putbyte('=');
putbyte(' ');
DOG=~DOG;
ls=0;
if (temp_buff[0]==0x28) //DS18B20
{OWInit (select);
OWWriteByte(0xcc,select); //skip rom
OWWriteByte(0x44,select); //Temperature convert
ls=gettemp(select);
}
if (temp_buff[0]==0xA6) //DS2438
{inid=0;
OWInit (select);
OWWriteByte(0xcc,select); //skip rom
OWWriteByte(0x4E,select);
OWWriteByte(0x00,select);
OWWriteByte(0x00,select);
OWInit (select);
OWWriteByte(0xcc,select); //skip rom
OWWriteByte(0x48,select);
OWWriteByte(0x00,select);
delay(250);
OWInit (select);
OWWriteByte(0xcc,select); //skip rom
OWWriteByte(0xB4,select); //Temperature convert
ls=getvol(select);
}
ls*=10;
lsi=ls;
putint(lsi);
putbyte(' ');
putbyte(':');
putbyte(' ');
putint(inid/256);
putbyte(' ');
putint(inid & 0xFF);
putbyte(' ');
putint(cnt);
putbyte(0x0d);
putbyte(0x0a);
rslt = OWSearch(select);
}
PTT=1;
}
?带行号的程序是怎么出来的?
成功了,不过时间挺长的
一周热门 更多>