#define CLR_DIR_1WIRE DDRD&=~BIT(4) //只要修改这里的参数就可以了!呵呵!
#define SET_DIR_1WIRE DDRD|=BIT(4) //里面什么都不用该!
#define CLR_OP_1WIRE PORTD&=~BIT(4)
#define SET_OP_1WIRE PORTD|=BIT(4)
#define CHECK_IP_1WIRE (PIND&0x10) //检测
unsigned char wmh,wml;
void init_1820()
{
SET_DIR_1WIRE; //设置PC2 为输出
SET_OP_1WIRE;
CLR_OP_1WIRE;
delay_nus(480); //480us以上
SET_OP_1WIRE;
CLR_DIR_1WIRE;
delay_nus(20); //15~60us
while(CHECK_IP_1WIRE);
SET_DIR_1WIRE;
SET_OP_1WIRE;
delay_nus(140); //60~240us
}
void write_1820(unsigned char x)
{
unsigned char m;
for(m=0;m<8;m++)
{
CLR_OP_1WIRE;
if(x&(1<<m)) //写数据了,先写低位的!
SET_OP_1WIRE;
DS18B20程序
最新推荐文章于 2024-04-16 13:01:33 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)