导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→1820读不出来啊?快来救命啊,[deltta]

 *第15563篇: 1820读不出来啊?快来救命啊,

  
楼 主:deltta 2003年8月17日11:11
 1820读不出来啊?快来救命啊,
用2051调DS18B20,就一只单点测温,始终出不来,初始化是MCU拉低500多微秒,按照时序来得啊,手上有十只,都试了,不行,网络上的也都不行(C51或A51),
有谁可不可以拉我一把??
常州 张
03-08-17
  
2楼:hcphs 2003年8月17日22:17
 c51
void init_18b20 (void)
{
  dq=1;
  _nop_();
  dq=0;
  delay(90);            //delay 530 uS
  dq=1;
  delay(6);            //delay 100 uS
  if(dq==0)
     flag=1;            //detect 1820 success!
  else
     flag=0;             //detect 1820 fail!
  delay(20);
  dq=1;
}
//
void write (uchar wr)
{
  uchar i;
  for (i=0;i  <8;i++)
   {
     dq=0;
     _nop_();
     dq=wr&0x01;
     delay(5);            //delay 45 uS
     dq=1;
     wr>  >  =1;
   }
}
//
uint read_word (void)
{
  uchar i;
  uint u=0;
  for(i=0;i  <16;i++)
   {
     dq=0;
     u>  >  =1;
     dq=1;
     if(dq==1)
        u|=0x8000;
     delay (4);
   }
  return(u);
}
/*
uchar read_byte (void)
{
  uchar i,u=0;
  for(i=0;i  <8;i++)
   {
     dq=0;
     u>  >  =1;
     dq=1;
     if(dq==1)
        u|=0x80;
     delay (4);
   }
  return(u);
}
//
void config (void)
{
  if(flag)
   {
     write (0xcc);        //skip rom
     write (0x4e);        //write scratchpad
     write (0x19);        //th=00
     write (0x1a);        //tl=00
     write (0x5f);           //set 11 bit (0.125)
     init_18b20();
     write (0xcc);        //skip rom
     write (0x48);        //copy
     init_18b20();
     write (0xcc);        //skip rom
     write (0xb8);        //recall
     delay (254);
     delay (250);
     init_18b20();
     write (0xcc);
     write (0xbe);
     one=read_word();
     two=read_word();
     three=read_word();
   }   */
}

void get_temp (void)
{
  uint bdata tem;
  init_18b20();
  if (flag)
   {  EA=0;
     write (0xcc);            //skip rom
     write (0x44);            //temp convert
     init_18b20 ();
     write (0xcc);            //skip rom
     write (0xbe);            //read temp
     tem=read_word();             //read
     if(tem  <0x8000)
       temp=tem*0.0625;            //temperature>  =0
     else
       temp=tem*(-0.0625);
        EA=1;           //temperature  < 0
     //write (0xec);               //search alarm
   }
}
//
void delay (uchar us)
{
  while (us--);
}
main()
{
while(1)
{get_temp();
}
}


>>>>>>对该主题发表你的看法

本主题贴数2,分页: [第1页]


[上一篇主题]:我现在想搞一个单片机设计.可是不知道搞什么题目?请大家告诉我有些什么好题目!!

[下一篇主题]:请问哪里有 可用altera/xilinx两种CPLD/FPGA的开发平台[求助]