?? 18b20.c
字號(hào):
#include "18b20.h"
#include "delay.h"
bit flag;
void Init_18b20()
{
{
DQ = 1;
delay(48);
DQ = 0;
delay(48);
DQ = 1;
delay(4);
flag = DQ;
delay(10);
DQ = 1;
}while(flag);
}
static void Write_cmd(uchar cmd)
{
uchar i;
for(i=0;i<8;i++)
{
DQ = 0;
DQ = cmd&0x01;
delay(1);
DQ = 1;
cmd>>=1;
}
}
static unsigned char read_char()
{
uchar i,Data;
for(i=0;i<8;i++)
{
DQ = 0;
Data>>=1;
DQ = 1;
if(DQ)
Data |= 0x80;
delay(2) ;
}
return Data;
}
unsigned char read_temperature()
{
uchar tl,th,wendu;
Init_18b20();
Write_cmd(0xcc);
Write_cmd(0x44);
delay(2);
Init_18b20();
Write_cmd(0xcc);
Write_cmd(0xbe);
tl = read_char();
th = read_char();
th=(th&0x0f)<<4;
tl=(tl&0xf0)>>4;
wendu = th|tl;
return wendu;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -