#include<msp430x14x.h>
#define DQ1 P5OUT|=BIT0
#define DQ0 P5OUT&=~BIT0
#define DQ_out P5DIR|=BIT0
#define DQ_in P5DIR&=~BIT0
#define DQ_volt (P5IN&BIT0)
typedef unsigned char uchar;
typedef unsigned int uint;
void Delay_us(uint time)
{
CCR0=time;
TACTL|=MC_1;
while(!(TACTL&TAIFG));
TACTL&=~MC_1;
TACTL&=~TAIFG;
}
uchar Resetds18b20()
{
uchar Error;
_DINT();
DQ_out;
DQ0;
Delay_us(700);
DQ1;
Delay_us(40);
DQ_in;
_NOP();
if(DQ_in) Error=1;
else Error=0;
DQ_out;
DQ1;
_EINT();
Delay_us(400);
return(Error);
}
void Writedata(uchar temp)
{
uchar i;
_DINT();
for(i=0;i<8;i++)
{
DQ0;
Delay_us(6);
if(temp&0x01) DQ1;
else DQ0;
Delay_us(40);
temp>>=1;
DQ1; //为下次拉低做准备
Delay_us(10);
}
_EINT();
}