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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8470|回復(fù): 17
收起左側(cè)

關(guān)于ds18b20 程序問題求大神解答,為何數(shù)碼管顯示一直是959

  [復(fù)制鏈接]
ID:323005 發(fā)表于 2019-3-4 01:06 | 顯示全部樓層 |閱讀模式
100黑幣
程序功能:檢車DS18B20并顯示數(shù)碼管上;奈何數(shù)碼管一直顯示A959;
#include<STC8.h>
#include<intrins.h>
#define uchar unsigned char
#define uint  unsigned int
#define FOSC  12000000L
sbit w1=P1^0;
sbit w2=P1^1;
sbit w3=P1^2;
sbit w4=P1^3;//數(shù)碼管位選
sbit k1=P1^4;
sbit k2=P1^5;
sbit k3=P1^6;
sbit k4=P1^7;
sbit DS=P5^4;數(shù)據(jù)口
sbit g=P5^5;
           //define interface
uint temp;             // variable of temperature
uchar flag1;            // sign of the result positive or negative
uchar code SM[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code SM5[]={
0xbf,0x86,0xdb,0xcf,
0xe6,0xed,0xfd,0x87,
0xff,0xef,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void nb(uint z)   //??
{
uint x,y;
     x=z;
for(x;x>0;x--)
   for(y=110;y>0;y--);
}

void delay(uint count)      //delay
{
  uint i;
  while(count)
  {
    i=200;
    while(i>0)
    i--;
    count--;
  }
}
void dsreset(void)       //send reset and initialization command
{
  uint i;
  DS=0;
  i=103;
  while(i>0)i--;
  DS=1;
  i=4;
  while(i>0)i--;
}
bit tmpreadbit(void)       //read a bit
{
   uint i;
   bit dat;
   DS=0;i++;          //i++ for delay
   DS=1;i++;i++;
   dat=DS;
   i=8;while(i>0)i--;
   return (dat);
}
uchar tmpread(void)   //read a byte date
{
  uchar i,j,dat;
  dat=0;
  for(i=1;i<=8;i++)
  {
    j=tmpreadbit();
    dat=(j<<7)|(dat>>1);  
  }
  return(dat);
}
void tmpwritebyte(uchar dat)   //write a byte to ds18b20
{
  uint i;
  uchar j;
  bit testb;
  for(j=1;j<=8;j++)
  {
    testb=dat&0x01;
    dat=dat>>1;
    if(testb)     //write 1
    {
      DS=0;
      i++;i++;
      DS=1;
      i=8;while(i>0)i--;
    }
    else
    {
      DS=0;       //write 0
      i=8;while(i>0)i--;
      DS=1;
      i++;i++;
    }
  }
}
void tmpchange(void)  //DS18B20 begin change
{
  dsreset();
  delay(1);
  tmpwritebyte(0xcc);  // address all drivers on bus
  tmpwritebyte(0x44);  //  initiates a single temperature conversion
}
uint tmp()               //get the temperature
{
  float tt;
  uchar a,b;
  dsreset();
  delay(1);
  tmpwritebyte(0xcc);
  tmpwritebyte(0xbe);
  a=tmpread();
  b=tmpread();
  temp=b;
  temp<<=8;             //two byte  compose a int variable
  temp=temp|a;
  tt=temp*0.0625;
  temp=tt*10+0.5;
  return temp;
}
void display(uint temp)   //&Iuml;&Ocirc;&Ecirc;&frac34;&sup3;&Igrave;&ETH;ò
{
   uchar A1,A2,A2t,A3;
      A1=temp%10;
     A2=temp/10%10;
    A3=temp/100%10;
    w1=0;
    P3=SM[A1];
    nb(50);
    w1=1;
    w2=0;
    P3=SM[A2];
    nb(50);
    w2=1;
    w3=0;
    P3=SM[A3];
    nb(50);
    w3=1;
    w4=0;
    P3=0x77;nb(50);
    w4=1;
}

void main()
{
uchar a;
    tmpchange();  
    display(tmp());
   
   while(1)
  {tmpchange();  
  display(tmp());
  }
}


回復(fù)

使用道具 舉報

ID:158375 發(fā)表于 2019-3-4 08:28 | 顯示全部樓層
程序要分開調(diào)試:
先別管ds18b20 程序,你的數(shù)碼管顯示對嗎?是不是想顯示什么都無問題?
18b20讀出數(shù)據(jù)后要轉(zhuǎn)換,轉(zhuǎn)換對嗎?給一個讀出數(shù)據(jù),,能顯示正確否?
以上全對了,再研究DS18B20程序。。。。。。
回復(fù)

使用道具 舉報

ID:466578 發(fā)表于 2019-3-4 08:34 | 顯示全部樓層
已經(jīng)定義了一個全局變量
uint temp;             // variable of temperature
然而,又定義了這個
void display(uint temp)   //&Iuml;&Ocirc;&Ecirc;&frac34;&sup3;&Igrave;&ETH;ò
回復(fù)

使用道具 舉報

ID:323005 發(fā)表于 2019-3-4 15:19 | 顯示全部樓層
笨笨兔 發(fā)表于 2019-3-4 08:28
程序要分開調(diào)試:
先別管ds18b20 程序,你的數(shù)碼管顯示對嗎?是不是想顯示什么都無問題?
18b20讀出數(shù)據(jù) ...

謝謝回答 ;數(shù)碼管顯示沒問題的
回復(fù)

使用道具 舉報

ID:323005 發(fā)表于 2019-3-4 15:33 | 顯示全部樓層
佛云 發(fā)表于 2019-3-4 08:34
已經(jīng)定義了一個全局變量
uint temp;             // variable of temperature
然而,又定義了這個

謝謝 ,但是不是這個問題
回復(fù)

使用道具 舉報

ID:323005 發(fā)表于 2019-3-4 15:34 | 顯示全部樓層
通電直接就顯示A959好像沒有檢測
回復(fù)

使用道具 舉報

ID:323005 發(fā)表于 2019-3-4 17:49 | 顯示全部樓層
求解答
回復(fù)

使用道具 舉報

ID:466164 發(fā)表于 2019-3-4 21:34 | 顯示全部樓層
1.單從顯示看A959,A百位錯誤," A3=temp/100%10;"最高位直接求模A3=temp/100;
2.溫度轉(zhuǎn)換有問題,沒考慮負(fù)溫度,當(dāng)時溫度低于0度你處理的是補(bǔ)碼。
3.        temp=temp-1;
        temp=~temp;
        tp=temp;
        temp=tp*0.0625*10+0.5;       
4.你英語太好注釋看不太明白,所以水平有限只能看怎么多。
回復(fù)

使用道具 舉報

ID:348627 發(fā)表于 2019-3-4 21:35 | 顯示全部樓層
temp 是全局變量就別再返回temp   你可以把temp定義在uint tmp()  這里面就行了。  樓主可以嘗試一下
回復(fù)

使用道具 舉報

ID:346616 發(fā)表于 2019-3-4 22:21 | 顯示全部樓層
P3=0x77;這個顯示A,
tmpread()返回0xFF,
tmp()函數(shù)中經(jīng)過計算返回temp的值是0x9FFF,
A1=temp%10;
A2=temp/10%10;
A3=temp/100%10;
這三個值是0x09.0x05,0x09,對應(yīng)的是SM數(shù)組中的位置,第九個,第五個,第九個,即959。
調(diào)試的時候可以從temp往上回溯,注意char和int的長度。
回復(fù)

使用道具 舉報

ID:323005 發(fā)表于 2019-3-5 00:11 | 顯示全部樓層
菜鳥來了 發(fā)表于 2019-3-4 22:21
P3=0x77;這個顯示A,
tmpread()返回0xFF,
tmp()函數(shù)中經(jīng)過計算返回temp的值是0x9FFF,

貌似是初始化的問題 12晶振 不知道哪里出問題了
回復(fù)

使用道具 舉報

ID:346616 發(fā)表于 2019-3-5 00:37 | 顯示全部樓層
sssssdffs 發(fā)表于 2019-3-5 00:11
貌似是初始化的問題 12晶振 不知道哪里出問題了

有這個意思,建議完整的接上傳感器看看。
如果有問題先在tmp()里下個斷點調(diào)試,看一下tmpread()的返回值。
回復(fù)

使用道具 舉報

ID:323005 發(fā)表于 2019-3-5 00:40 | 顯示全部樓層
菜鳥來了 發(fā)表于 2019-3-5 00:37
有這個意思,建議完整的接上傳感器看看。
如果有問題先在tmp()里下個斷點調(diào)試,看一下tmpread()的返回值 ...

初始化失敗了應(yīng)該,發(fā)圖發(fā)不上去
回復(fù)

使用道具 舉報

ID:478073 發(fā)表于 2019-3-5 07:54 | 顯示全部樓層
壇子里有案例,找一下看看

評分

參與人數(shù) 4黑幣 +44 收起 理由
微小苛 + 10
yoxi + 10
shuisheng60 + 10
Trump1438 + 14

查看全部評分

回復(fù)

使用道具 舉報

ID:481641 發(fā)表于 2019-4-5 16:36 | 顯示全部樓層
數(shù)碼管和溫度分開試試
回復(fù)

使用道具 舉報

ID:382454 發(fā)表于 2019-4-5 22:54 來自觸屏版 | 顯示全部樓層
要單個單個模塊調(diào)試,才對。調(diào)好了再整合
回復(fù)

使用道具 舉報

ID:481641 發(fā)表于 2019-4-6 08:27 | 顯示全部樓層
轉(zhuǎn)換或者數(shù)碼管有問題
回復(fù)

使用道具 舉報

ID:315110 發(fā)表于 2023-6-11 03:29 | 顯示全部樓層
菜鳥來了 發(fā)表于 2019-3-4 22:21
P3=0x77;這個顯示A,
tmpread()返回0xFF,
tmp()函數(shù)中經(jīng)過計算返回temp的值是0x9FFF,

感謝,說白了就是時序問題,導(dǎo)致初始化失敗,或者讀出的數(shù)據(jù)錯誤,全部為0xFF。
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

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

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

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