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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 2316|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

溫度傳感器燒錄進(jìn)去不能正常顯示,有沒(méi)有人可以幫我看看這個(gè)程序有沒(méi)有問(wèn)題啊?

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:389906 發(fā)表于 2018-8-25 12:39 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式

#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();
  }
  }



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:225054 發(fā)表于 2018-8-25 13:22 來(lái)自觸屏版
幫頂,我還沒(méi)學(xué)到這里呢

板凳
ID:386381 發(fā)表于 2018-8-26 01:13 來(lái)自觸屏版 | 只看該作者
什么樣的狀況顯示的,最好能貼圖上來(lái)大家好幫你解決
回復(fù)

使用道具 舉報(bào)

地板
ID:384109 發(fā)表于 2018-8-26 13:43 | 只看該作者
應(yīng)該是數(shù)制轉(zhuǎn)換的問(wèn)題,temp=tp*0.0625*100+0.5;,temp是整型,tp是浮點(diǎn)型,如果tp強(qiáng)制轉(zhuǎn)換給temp的話(huà),不說(shuō)別的,至少小數(shù)部分就沒(méi)有了
回復(fù)

使用道具 舉報(bào)

5#
ID:390187 發(fā)表于 2018-8-26 17:28 | 只看該作者
這幾天正在做18B20溫度控制程序。需要的話(huà)可以給你看看。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表