欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
做51單片機18B20 數(shù)碼管一直閃爍 不知道該怎么弄 求大佬
[打印本頁]
作者:
zzk15963
時間:
2020-9-7 16:42
標題:
做51單片機18B20 數(shù)碼管一直閃爍 不知道該怎么弄 求大佬
#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
作者:
wulin
時間:
2020-9-7 19:42
參見類似現(xiàn)象的回帖
http://m.raoushi.com/bbs/dpj-194698-1.html
作者:
TTQ001
時間:
2020-9-8 01:29
樓上的鏈接很有幫助。 該帖子為這個問題提供了正確的原因。
作者:
0x00000000
時間:
2020-9-10 13:09
你的Ds18b20ReadTemp()占用了太多時間導致LED刷新率太低。
你需要一個定時器做刷新。
作者:
wocjisji
時間:
2020-10-9 17:35
先把數(shù)碼管是共陰極還是共陽極搞清楚
作者:
小炒肉111
時間:
2020-10-9 18:00
1、消隱問題注意
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1