我用DS18B20做了一个温度计,为什么数码管上老是显示00啊,我用P1.0接的DS18B20的输出口,P0,P2口接的数码管,大家帮我看看吧,我实在是找不出哪的错了,我用的晶振是11.0592
#include
#define uchar unsigned char
#define uint unsigned int
sbit DQ=P1^0;
code uchar ledmap[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
0x82,0xf8,0x80,0x90};
#define DS18B20SKIP_ROM 0x0CC //为了与别的程序不冲突名字定义的较长
#define DS18B20SEARCH_ROM 0x0F0
#define DS18B20READ_ROM 0x033
#define DS18B20CONVERT_T_ROM 0x044
#define DS18B20WRITE_S_ROM 0x04E
#define DS18B20READ_S_ROM 0x0BE
sbit deng1=P3^0;
//配置寄存器
#define DS18B20_R1R0 0x07F //配置为9bit结果 R1,R0 结果位数 转换时间
void ds18b20_delay(uchar time)
{
while(--time);
}
bit ds18b20_reset(void)
{
bit b;
DQ=1;
ds18b20_delay(1);
DQ=0;
ds18b20_delay(240);
DQ=1;
ds18b20_delay(60);
b=DQ;
ds18b20_delay(190);
return b;
}
void ds18b20_write_bit(bit bitval)
{
DQ=1;
DQ=0;
ds18b20_delay(2);
DQ=bitval;
ds18b20_delay(39);
DQ=1;
ds18b20_delay(1);
}
bit ds18b20_read_bit(void)
{
bit b;
DQ=1;
DQ=0;
ds18b20_delay(1);
DQ=1;
ds18b20_delay(2);
b=DQ;
ds18b20_delay(25);
return b;
}
void ds18b20_write_byt(uchar bytval)
{
uchar i=8;
while(i--)
{
ds18b20_write_bit(((bytval0)bytval1;
}
return bytval;
}
bit ds18b20_init(void)
{
if(ds18b20_reset())
{
return 0;
}
ds18b20_write_byt ( DS18B20SKIP_ROM ); //忽略ROM匹配操作
ds18b20_write_byt ( DS18B20WRITE_S_ROM ); //设置写模式
ds18b20_write_byt ( 0x64 ); //设置温度上限为100度(最高位为符号位S)
ds18b20_write_byt ( 0x8a ); //设置温度下限为-10度(最高位为符号位S)
ds18b20_write_byt ( DS18B20_R1R0 ); //设置配置寄存器
}
unsigned int ds18b20_get ( void )
{
unsigned int intT;
unsigned char bytTL,bytHL,aa;
ds18b20_reset();
if(ds18b20_reset())
{
deng1=0;
}
ds18b20_write_byt(0xcc);
ds18b20_write_byt(0x44);
ds18b20_delay(3);
ds18b20_reset();
ds18b20_write_byt(0xcc);
ds18b20_write_byt(0xbe);
bytTL=ds18b20_read_byt();
bytHL=ds18b20_read_byt();
bytTL=bytTL4;
bytHL=bytHL