欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
怎么樣將使用獨(dú)立鍵盤(pán)前三個(gè)按鍵去調(diào)整 ds18b20的TH,TL,并且使用LCD1602 去顯示...
[打印本頁(yè)]
作者:
小萌新太難了
時(shí)間:
2020-4-30 21:42
標(biāo)題:
怎么樣將使用獨(dú)立鍵盤(pán)前三個(gè)按鍵去調(diào)整 ds18b20的TH,TL,并且使用LCD1602 去顯示...
怎么樣用代 使用獨(dú)立鍵盤(pán)前三個(gè)按鍵去調(diào)整
ds18b20的TH,TL,并且使用LCD1602
去顯示每次按鍵的變化
以下代碼只實(shí)現(xiàn)了測(cè)出溫度
代碼:#include <reg52.H>#include <intrins.H>
#include <math.H>
#define uchar unsigned char
#define uint unsigned int
sbit dula = P2^6;
sbit wela = P2^7;
sbit rw = P3^6;
sbit RS = P3^5;
sbit LCDEN = P3^4;
void delayUs() //us級(jí)延時(shí)
{
_nop_(); //匯編語(yǔ)句 空語(yǔ)句,用來(lái)產(chǎn)生短暫的延時(shí)效果,
//對(duì)于延時(shí)很短的,要求在us級(jí)的,采用“_nop_”函數(shù),對(duì)于12M晶振,延時(shí)1uS。
}
void delayMs(uint a) //ms級(jí)延時(shí)
{
uint i, j;
for(i = a; i > 0; i--)
for(j = 100; j > 0; j--);
}
void writeComm(uchar comm) //寫(xiě)LCD1602指令
{
RS = 0;
P0 = comm;
LCDEN = 1;
delayUs();
LCDEN = 0;
delayMs(1);
}
//寫(xiě)數(shù)據(jù):RS=1, RW=0; 可以選擇想要寫(xiě)入的數(shù)據(jù)
void writeData(uchar dat) //從 writeString()函數(shù)中逐一寫(xiě)入數(shù)據(jù)
{
RS = 1;
P0 = dat;
LCDEN = 1; //讀取數(shù)據(jù)并寫(xiě)入1602內(nèi)
delayUs();
LCDEN = 0; //釋放總線
delayMs(1);
}
void init() //初始化函數(shù)
{
rw = 0;
dula = wela = 0;
writeComm(0x38); // 顯示模式設(shè)置指令碼00111000 16*2顯示
writeComm(0x0c); //顯示開(kāi)/關(guān)及光標(biāo)設(shè)置 00001DCB D=1 開(kāi)顯示 C=1顯示光標(biāo) B=1光標(biāo)閃爍
writeComm(0x06); //顯示指針指向000001NS N=1 當(dāng)讀或?qū)懸粋(gè)字符后地址指針加一,且光標(biāo)加一
writeComm(0x01); //顯示清屏:1.數(shù)據(jù)指針清零,2.所有顯示清零
}
void writeString(uchar * str, uchar length) //寫(xiě)入字符串
{
uchar i;
for(i = 0; i < length; i++)
{
writeData(str[i]);
}
}
/**//*****************************DS18B20*******************************/
sbit ds = P2^2;
void dsInit() //單總線初始化時(shí)序
{
unsigned int i;
ds = 0;
i = 100;
while(i>0) i--; //猜測(cè)是為了使傳感器復(fù)位,即拉低單總線480us以上
ds = 1; //釋放總線
i = 4;
while(i>0) i--; //拉低總線15-60us,即可讀取18B20的存在信號(hào)
}
void dsWait()
{
unsigned int i;
while(ds);
while(~ds);
i = 4;
while(i > 0) i--;
}
bit readBit() //采樣總線上的數(shù)據(jù)
{
unsigned int i;
bit b;
ds = 0;
i++;
ds = 1;
i++; i++;
b = ds;
i = 8;
while(i>0) i--;
return b;
}
unsigned char readByte() //讀時(shí)序 讀字節(jié)每次一位
{
unsigned int i;
unsigned char j, dat;
dat = 0;
for(i=0; i<8; i++)
{
j = readBit();
dat = (j << 7) | (dat >> 1);//把字節(jié)每次移動(dòng)一位,直到移動(dòng)8次,數(shù)據(jù)寫(xiě)入dat中
}
return dat;
}
void writeByte(unsigned char dat) //寫(xiě)時(shí)序
{
unsigned int i;
unsigned char j;
bit b;
for(j = 0; j < 8; j++) //每次寫(xiě)入一個(gè)字節(jié),寫(xiě)入8次
{
b = dat & 0x01;
dat >>= 1;
if(b)
{
ds = 0; i++; i++;
ds = 1;
i = 8; while(i>0) i--;
}
else
{
ds = 0;
i = 8; while(i>0) i--;
ds = 1;
i++; i++;
}
}
}
void sendChangeCmd() //溫度轉(zhuǎn)換指令
{
dsInit();
dsWait();
delayMs(1);
writeByte(0xcc);
writeByte(0x44); //發(fā)送溫度轉(zhuǎn)換指令
/* 設(shè)置EEPROM中的TH TL 及精度程序
writeByte(0x4e); //發(fā)送寫(xiě)暫存器指令
writeByte(0x依據(jù)需要); //設(shè)置TH指令
writeByte(0x依據(jù)需要); //設(shè)置TL指令
writeByte(0x依據(jù)需要); //配置工作在哪一位的模式下 如0 R1 R2 1 1 1 1 1 R1=R2=0 為9位精度
writeByte(0x48); //把高速暫存器的值拷貝到EEPROM中
PS:每次使用時(shí)都需要初始化
dsInit();
dsWait();
writeByte(0xcc); //發(fā)送跳躍ROM指令
*/
}
void sendReadCmd()
{
dsInit();
dsWait();
delayMs(1);
writeByte(0xcc); //發(fā)送跳躍ROM指令
writeByte(0xbe); //讀取高速暫存器中的內(nèi)容
}
int getTmpValue()
{
unsigned int tmpvalue;
int value;
float t;
unsigned char low, high;
sendReadCmd();
low = readByte(); //讀取高速暫存器中的第一個(gè)字節(jié) ,即LSB
high = readByte(); //讀取高速暫存器中的第2個(gè)字節(jié) ,即MSB
tmpvalue = high; //將高字節(jié)的溫度數(shù)據(jù)換算成十進(jìn)制
tmpvalue <<= 8;
tmpvalue |= low;
value = tmpvalue;
\
t = value * 0.0625;//換算成實(shí)際溫度
\
value = t * 100 + (value > 0 ? 0.5 : -0.5); //大于0加0.5, 小于0減0.5 四舍五入
return value;
}
void display(int v) //顯示函數(shù)
{
unsigned char count;
unsigned char datas[] = {0, 0, 0, 0, 0};
unsigned int tmp = abs(v);
datas[0] = tmp / 10000;
datas[1] = tmp % 10000 / 1000;
datas[2] = tmp % 1000 / 100;
datas[3] = tmp % 100 / 10;
datas[4] = tmp % 10;
writeComm(0xc0+3);
if(v < 0)
{
writeString("- ", 2);
}
else
{
writeString("+ ", 2);
}
if(datas[0] != 0)
{
writeData('0'+datas[0]);
}
for(count = 1; count != 5; count++)
{
writeData('0'+datas[count]);
if(count == 2)
{
writeData('.');
}
}
}
/**//*****************************DS18B20*******************************/
void main()
{
uchar table[] = " xianzaiwendu: ";
sendChangeCmd();
init();
writeComm(0x80);
writeString(table, 16);
while(1)
{
delayMs(1000); //溫度轉(zhuǎn)換時(shí)間需要750ms以上
writeComm(0xc0);//第二行地址 顯示溫度
display(getTmpValue());
sendChangeCmd(); //再次初始化DS總線
}
}
無(wú)標(biāo)題.png
(79.24 KB, 下載次數(shù): 56)
下載附件
2020-4-30 21:39 上傳
作者:
xxpp2011
時(shí)間:
2020-5-1 09:59
TH、TL是溫度報(bào)警的上下限嗎,設(shè)置兩個(gè)變量,一個(gè)·按鍵選擇調(diào)節(jié)上限或下限、一個(gè)按鍵加、一個(gè)按鍵減就好了。
作者:
f556
時(shí)間:
2020-5-1 13:52
設(shè)三個(gè)按鍵,+ - S,S時(shí)可以選TH、TL,并閃爍,+時(shí)選中++,-時(shí)選中--,最后按S時(shí)保存。OK。
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1