调试环境:
MPLAB 7.5
PICC 8.05 PL1
PIC16F88,DS18B20 两颗,晶振4MHz(如换其它晶振,需要更改WriteBit和ReadBit中的等待操作以及延时函数)
我只有两颗18B20,没有验证过SearchROM是否还有Bug
以下函数使用时均需关掉中断,
主要函数说明:
//Reset 18B28 and Detect the reply,检测是否有18B20在线上
//if succes return 1, over time return 0
unsigned char DetectB20();
//Read One Byte from 18B20 从18B20上读取一字节数据
//return the byte just read
unsigned char ReadB20Byte();
//Write one byte to 18B20 写一字节到18B20
void WriteB20Byte(unsigned char);
//Read 18B20 ROM value, 当只有一个18B20时,读取其ROM值
// **return values** **Explain**
// ZERO success
// CRCError CRC Error
// OverTime Detect over time
unsigned char ReadB20ROM(unsigned char *ROM);
//Read EERAM, Skip ROM 读取EERAM的值,跳过ROM检测
// **return values** **Explain**
// ZERO success,
// CRCError CRC Error
// OverTime Detect over time
unsigned char ReadEERAM(unsigned char *RAM);
//Search devices on the bus //1-Wire 器件查询命令,结果返回到B20ROMTemp中,
注意:如果在查找下一个命令前更改B20ROMTemp中的值,将会造成无法遍历总线上的器件
// Arguments: 输入参数说明
//FirstNext: FindFirst find device from the 1st one 查找第一个器件
// otherwise from last one 根据上一次结果,查找下一个器件
//
// **return values** **Explain**
// SearchFinish All devices are found
// OverTime Detect over time
// ZERO Success, but still have other device unknow
unsigned char SearchDevice(unsigned char FirstNext);
//Start temprature //开始温度转换
// **return values** **Explain**
// ZERO success
// OverTime Detect over time
unsigned char StartConvertTp();
The bus master learns the unique ID number (ROM data pattern) of one 1-Wire device on each ROM
Search operation. The time required to derive the part’s unique ROM code is:
960 μs + (8 + 3 x 64) 61 μs = 13.16 ms
The bus master is therefore capable of identifying 75 different 1-Wire devices per second.
呵呵,官方的能找75个,我用C写的是20.8ms,最多不到50个
源代码如下
用户430926 2013-3-15 19:49
用户1428533 2012-5-16 15:10
谢谢分享!
用户236990 2009-12-30 12:22
用户233292 2009-12-25 16:36
用户236990 2009-12-25 11:42
用户236990 2009-12-25 00:03
用户233292 2009-12-24 23:39
用户236990 2009-12-24 23:09
用户233292 2009-12-24 20:36
用户236990 2009-12-24 07:31