欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 溫度傳感器燒錄進去不能正常顯示,有沒有人可以幫我看看這個程序有沒有問題。 [打印本頁]

作者: ldhlll    時間: 2018-8-25 12:39
標題: 溫度傳感器燒錄進去不能正常顯示,有沒有人可以幫我看看這個程序有沒有問題啊?

#ifndef _TEMP_H_
#define _TEMP_H_
#include<reg51.h>
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef uint
#define uint unsigned int
#endif

sbit DSPORT=P3^7;
  
void Delay1ms(uint y);
uchar DS18B20Init();
void DS18B20WriteByte(uchar dat);
uchar DS18B20ReadByte();
void changetemp();
void  readtempcom();
int readtemp();
#endif

#include"temp.h"
void Delay1ms(uint y)
{
  uint x;
  for(;y>0;y--)
   {
     for(x=110;x>0;x--);
   }
}
uchar DS18B20Init()
{
   uchar i;
   DSPORT=0;
   i=70;
   while(i--);
   DSPORT=1;
   i=0;
   while(DSPORT)
   {
   Delay1ms(1);
   i++;
   if(i>5)
   {
   return 0;
   }
   }
   return 1;
}
void DS18B20WriteByte(uchar dat)
{
   uint i,j;
   for(j=0;j<8;j++)
   {
   DSPORT=0;
   i++;
   dat=dat|0x01;
   i=6;
   while(i--);
   DSPORT=1;
   dat>>=1;
   }
}
uchar DS18B20ReadByte()
{
   uchar byte,bi;
   uint i,j;
   for(j=0;j<8;j++)
   {
      DSPORT=0;
   i++;
   DSPORT=1;
   i++;
   i++;
    bi = DSPORT;  
  byte = (byte >> 1) | (bi << 7);        
  i = 4;
  while(i--);
}   
   
   return byte;
}

void changetemp()
{
   DS18B20Init();
   Delay1ms(1);
   DS18B20WriteByte(0xcc);
   DS18B20WriteByte(0x44);
}
void  readtempcom()
{
   DS18B20Init();
   Delay1ms(1);
   DS18B20WriteByte(0xcc);
   DS18B20WriteByte(0xbe);
}
int readtemp()
{
  int temp=0;
  uchar tmh,tml;
  changetemp();
  readtempcom();
  tmh=DS18B20ReadByte();
  tml=DS18B20ReadByte();
  temp=tmh;
  temp<<=8;
  temp|=tml;
  return temp;
}


#include<reg51.h>
#include<temp.h>
typedef unsigned char u8;
typedef unsigned int u16;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
char num=0;
u8 Date[8];
u8 code shuzu[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

void delay(u16 i)
{
  while(i--);
}
void datprocess(int temp)
{
   float tp;
   if(temp<0)
   {
       Date[0]=0x40;
  temp=temp-1;
  temp=~temp;
  tp=temp;
  temp=tp*0.0625*100+0.5;
   }
   else
   {
        Date[0]=0x00;
  tp=temp;
  temp=tp*0.0625*100+0.5;
   }
        Date[1]=shuzu[temp/10000];
  Date[2]=shuzu[temp%10000/1000];
  Date[3]=shuzu[temp%1000/100]|0x80;
  Date[4]=shuzu[temp%100/10];
  Date[5]=shuzu[temp%10];
}

void showprocess()
{
      u8 i;
    for(i=0;i<6;i++)
    {
       switch(i)
    {
   case 0:LSA=0;LSB=0;LSC=0;break;
   case 1:LSA=1;LSB=0;LSC=0;break;
   case 2:LSA=0;LSB=1;LSC=0;break;
   case 3:LSA=1;LSB=1;LSC=0;break;
   case 4:LSA=0;LSB=0;LSC=1;break;
   case 5:LSA=1;LSB=0;LSC=1;break;
          }
    P0=Date[5-i];
    delay(100);
    P0=0x00;
  }
     
}


void main()
{
  while(1)
  {
    datprocess(readtemp());
showprocess();
  }
  }




作者: 文鳳軒    時間: 2018-8-26 01:13
什么樣的狀況顯示的,最好能貼圖上來大家好幫你解決
作者: 人中狼    時間: 2018-8-26 13:43
應該是數制轉換的問題,temp=tp*0.0625*100+0.5;,temp是整型,tp是浮點型,如果tp強制轉換給temp的話,不說別的,至少小數部分就沒有了
作者: xs345854310    時間: 2018-8-26 17:28
這幾天正在做18B20溫度控制程序。需要的話可以給你看看。




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1