#include <device.h>
#include "DS18B20.h"
#include <intrins.h>
/***************************************************************/
/****************DS18B20?????******************************/
unsigned int t,flag;
void delay_18B20(unsigned int i)
{
while(i--);
}
unsigned char time;
Init_DS18B20(void)
{
unsigned char x=0;
Pin_1_Write(1); //DQ??
delay_18B20(8);
Pin_1_Write(0); //????DQ??
delay_18B20(100);
Pin_1_Write(1); //????
delay_18B20(40);
x=Pin_1_Read();
//????? ??x=0?????? x=1??????
CyDelay(200);
return(x);
}
/***************************************************************/
/****************??????***********************************/
unsigned char ReadOneChar(void)
{
unsigned char i=0;
unsigned char dat=0;
for(i=8;i>0;i--)
{
Pin_1_Write(0);
dat>>=1; //?????
Pin_1_Write(1);
if(Pin_1_Read())
dat|=0x80;
delay_18B20(20);
}
return(dat);
}
/***************************************************************/
/****************??????***********************************/
void WriteOneChar(unsigned char dat)
{
unsigned char i=0;
for(i=8;i>0;i--)
{
Pin_1_Write(0);
dat&=0x01;//?????
Pin_1_Write(dat); //??? ?0x01 ????? ??????
delay_18B20(20);
Pin_1_Write(1); //????
dat>>=1; //????????wdata
}
delay_18B20(20);
}
/***************************************************************/
/****************??????***********************************/
unsigned int ReadTemperature(void)
{
unsigned char TL;
unsigned char TH;
Init_DS18B20();
WriteOneChar(0xcc); // ??????????
WriteOneChar(0x44); // ??????
Init_DS18B20();
WriteOneChar(0xcc); //??????????
WriteOneChar(0xbe); //????????????9????? ???????
TL=ReadOneChar();
TH=ReadOneChar();
t=TH;
t<<=8;
t|=TL;
return(t);
}
请问这个程序有错吗?PIN引脚这样用对吗 |