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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2291|回復: 5
打印 上一主題 下一主題
收起左側

做51單片機18B20 數碼管一直閃爍 不知道該怎么弄 求大佬

[復制鏈接]
跳轉到指定樓層
樓主
ID:811924 發表于 2020-9-7 16:42 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include "reg52.h"  
#include"18B20ZHONGJI.H"
typedef unsigned int u16;  
typedef unsigned char u8;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;

char num=0;
u8 DisplayData[8];
u8 code smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
/*******************************************************************************
* ?? ?? ??         : delay
* ????????     : ?????????i=1?????????10us
*******************************************************************************/
void delay(u16 i)
{
while(i--);
}

/*******************************************************************************
* ?? ?? ??         : datapros()
* ????????     : ????????????????
* ??    ??         : temp
* ??    ??         : ??
*******************************************************************************/
void datapros(int temp)   
{
    float tp;  
if(temp< 0)    //???????????
   {
  DisplayData[0] = 0x40;    //   -
  //????????????????????????????1?????????????
  temp=temp-1;
  temp=~temp;
  tp=temp;
  temp=tp*0.0625*100+0.5;
  //??????С?????*100??+0.5?????????????C??????????????????????С????
  //????????????????????????0.5????+0.5??????0.5??????1???С??0.5???
  //?????0.5????????С??????檔

   }
  else
   {   
  DisplayData[0] = 0x00;
  tp=temp;//????????????С???????????????????????????
  //?????????????????????????????????????????
  temp=tp*0.0625*100+0.5;
  //??????С?????*100??+0.5?????????????C??????????????????????С????
  //????????????????????????0.5????+0.5??????0.5??????1???С??0.5???
  //?????0.5????????С??????檔
}



void DigDisplay()
{
u8 i;
for(i=0;i<6;i++)
{
  switch(i)  //λ?????????????????
  {
   case(0):
    LSA=1;LSB=1;LSC=1; break;//?????0λ
   case(1):
    LSA=0;LSB=1;LSC=1; break;//?????1λ
   case(2):
    LSA=1;LSB=0;LSC=1; break;//?????2λ
   case(3):
    LSA=0;LSB=0;LSC=1; break;//?????3λ
   case(4):
    LSA=1;LSB=1;LSC=0; break;//?????4λ
   case(5):
    LSA=0;LSB=1;LSC=0; break;//?????5λ
    delay(100);
  }
  P0=DisplayData[i];//????????
  delay(1); //????????????
  P0=0xFF;//????
}  
}


void main()
{
while(1)
{
  datapros(Ds18b20ReadTemp());  //??????????
  DigDisplay();//????????????  
}  
}#include"18b20zhongji.h"


void Delay1ms(uint y)
{
uint x;
for( ; y>0; y--)
{
  for(x=110; x>0; x--);
}
}


uchar Ds18b20Init()
{
uchar i;
DSPORT = 0;    //??????????480us~960us
i = 70;
while(i--);//???642us
DSPORT = 1;   //???????????????DS18B20???????????15us~60us??????????
i = 0;
while(DSPORT) //???DS18B20????????
{
  Delay1ms(1);
  i++;
  if(i>5)//???>5MS
  {
   return 0;//????????
  }

}
return 1;//????????
}


void Ds18b20WriteByte(uchar dat)
{
uint i, j;
for(j=0; j<8; j++)
{
  DSPORT = 0;         //?д???λ?????????????????1us
  i++;
  DSPORT = dat & 0x01;  //???д???????????????λ???
  i=6;
  while(i--); //???68us?????????????60us
  DSPORT = 1; //???????????????1us?????????????????д?????????
  dat >>= 1;
}
}



uchar Ds18b20ReadByte()
{
uchar byte, bi;
uint i, j;
for(j=8; j>0; j--)
{
  DSPORT = 0;//???????????1us
  i++;
  DSPORT = 1;//??????????
  i++;
  i++;//???6us??????????
  bi = DSPORT;  //?????????????λ??????
  /*??byte?????λ?????????????7λ???bi????????????????λ??0??*/
  byte = (byte >> 1) | (bi << 7);        
  i = 4;  //??????????48us??????????????
  while(i--);
}   
return byte;
}


void  Ds18b20ChangTemp()
{
Ds18b20Init();
Delay1ms(1);
Ds18b20WriteByte(0xcc);  //????ROM????????   
Ds18b20WriteByte(0x44);     //??????????
//Delay1ms(100); //??????????????????????????????????????????
   
}


void  Ds18b20ReadTempCom()
{
Ds18b20Init();
Delay1ms(1);
Ds18b20WriteByte(0xcc);  //????ROM????????
Ds18b20WriteByte(0xbe);  //?????????????
}


int Ds18b20ReadTemp()
{
int temp = 0;
uchar tmh, tml;
Ds18b20ChangTemp();     //??д?????????
Ds18b20ReadTempCom();   //??????????????????????
tml = Ds18b20ReadByte();  //?????????16λ??????????
tmh = Ds18b20ReadByte();  //????????
temp = tmh;
temp <<= 8;
temp |= tml;
return temp;
}
#ifndef __18b20zhongji_H_
#define __18b20zhongji_H_
#include<reg52.h>
//---?????????---//
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef uint
#define uint unsigned int
#endif
//--????????IO??--//
sbit DSPORT=P3^7;
//--??????????--//
void Delay1ms(uint );
uchar Ds18b20Init();
void Ds18b20WriteByte(uchar com);
uchar Ds18b20ReadByte();
void  Ds18b20ChangTemp();
void  Ds18b20ReadTempCom();
int Ds18b20ReadTemp();
#endif
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:213173 發表于 2020-9-7 19:42 | 只看該作者
參見類似現象的回帖http://m.raoushi.com/bbs/dpj-194698-1.html
回復

使用道具 舉報

板凳
ID:420836 發表于 2020-9-8 01:29 | 只看該作者
樓上的鏈接很有幫助。 該帖子為這個問題提供了正確的原因。
回復

使用道具 舉報

地板
ID:691028 發表于 2020-9-10 13:09 | 只看該作者
你的Ds18b20ReadTemp()占用了太多時間導致LED刷新率太低。
你需要一個定時器做刷新。
回復

使用道具 舉報

5#
ID:806634 發表于 2020-10-9 17:35 | 只看該作者
先把數碼管是共陰極還是共陽極搞清楚
回復

使用道具 舉報

6#
ID:708637 發表于 2020-10-9 18:00 | 只看該作者
1、消隱問題注意
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表