以下是主函数 和18B20的主要部分
请问还有什么问题?
void main()
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR|=BIT2+BIT3+BIT4+BIT5+BIT6;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
lcdreset();
clear_gcrom();
while(1)
{
uint i;
display_pos(0,0);
for(i=0;i<10;i++)
write_com(table1[i],0);
Temper=ReadTemp();
tableTemper(Temper);
display_pos(0,5);
for(uint i=0;i<4;i++)
write_com(table_Temper[i],0);
}
}
void Skip(void)
{
Write_18B20(0xcc);
}
//----------------------------------
void Convert (void)
{
Write_18B20(0x44);
}
//----------------------------------
void ReadDo (void)
{
Write_18B20(0xbe);
}
//----------------------------------
int ReadTemp (void)
{
char temp_low,temp_high,k; //温度值
Init();
Skip();
Convert();
delayus(60000);delayus(60000);//延时1s以上
Init();
Skip();
ReadDo();
temp_low=Read_18B20(); //读低位
temp_high=Read_18B20(); //读高位
temperature=(temp_high&0x0f);
temperature<<=8;
temperature|=temp_low;
k=temp_high&0xf8;
if(k==0xf8) //温度为负值
{
temperature=~temperature|1;
Temper=temperature*625;
}
else
{
// Temper=temperature*0.0625*100; //温度为正值
Temper=temperature*625; //0.0625*10000
}
return Temper;
}
void tableTemper(uint Temper)
{
table_Temper[0]=(Temper/10000)%10;
table_Temper[1]=(Temper/1000)%10;
table_Temper[2]=(Temper/100)%10;
table_Temper[3]=(Temper/10)%10;
} |