📄 lcddis.c
字号:
//////////ds18b20/////////
#include <reg51.h>
#include <INTRINS.h>
unsigned char readdata[2];
sbit DQ=P3^3;
////////////end of ds18b20 variable///////
/////////////lcd variable/////////////////
#include <reg51.h>
#include <absacc.h>
#define REG0 XBYTE[0x0000]
#define REG1 XBYTE[0x0001]
#define REG2 XBYTE[0x0002]
#define REG3 XBYTE[0x0003]
unsigned char bdata busyflag;
unsigned char dat,datn,count;
unsigned char word1[16]={" T= "};
code unsigned char word2[16]={" by LiXueli "};
code unsigned char word3[16]={"www.bitc.edu.cn!"};
code unsigned char word4[16]={"bitclxl@126.com!"};
code unsigned char word5[16]={" Wellcome To "};
code unsigned char word6[16]={" Proteus Tools!"};
code unsigned char word7[16]={"This Programme "};
code unsigned char word8[16]={" by LiXueli "};
sbit busyflag_7=busyflag^7;
sbit p10=P1^0;
sbit p11=P1^1;
sbit p12=P1^2;
/////////////////end of lcd variable////////////
///////////////ds18b20/////////////////////
//延时函数
void delay(unsigned int i)
{
while(i--);
}
//初始化函数
void Init_DS18B20(void)
{
unsigned char x=0;
DQ = 1; //DQ复位
delay(8); //稍做延时
DQ = 0; //单片机将DQ拉低
delay(80); //精确延时 大于 480us
DQ = 1; //拉高总线
delay(14);
x=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
delay(20);
}
//读一个字节
unsigned char ReadOneChar(void)
{
unsigned char i=0;
unsigned char dat = 0;
for (i=8;i>0;i--)
{
DQ = 0; // 给脉冲信号
dat>>=1;
DQ = 1; // 给脉冲信号
if(DQ)
dat|=0x80;
delay(4);
}
return(dat);
}
//写一个字节
void WriteOneChar(unsigned char dat)
{
unsigned char i=0;
for (i=8; i>0; i--)
{
DQ = 0;
DQ = dat&0x01;
delay(5);
DQ = 1;
dat>>=1;
}
delay(4);
}
//读取温度
void ReadTemperature(void)
{
Init_DS18B20();
WriteOneChar(0xCC); // 跳过读序号列号的操作
WriteOneChar(0x44); // 启动温度转换
Init_DS18B20();
WriteOneChar(0xCC); //跳过读序号列号的操作
WriteOneChar(0xBE); //读取温度寄存器等(共可读9个寄存器) 前两个就是温度
readdata[0]=ReadOneChar();
readdata[1]=ReadOneChar();
}
void Tempprocess() //温度转换
{
unsigned int t;
float tt;
unsigned char temp;
if((readdata[1]&0x80)!=0)
{
word1[3]='-';
t=readdata[1];
t<<=8;
t=t|readdata[0];
t=t-1;
t=~t;
t>>=4;
word1[4]=t/100+48;
word1[5]=((t/10)%10)+48;
word1[6]=t%10+48;
temp=readdata[0];
temp=temp-1;
temp=~temp;
temp=temp&0x0f;
tt=temp*0.0625;
word1[7]='.';
word1[8]=(unsigned char )(tt*10);
word1[9]=(unsigned char )(tt*100-word1[8]*10);
word1[10]=(unsigned char )(tt*1000-word1[8]*100-word1[9]*10);
word1[11]=(unsigned char )(tt*10000-word1[8]*1000-word1[9]*100-word1[10]*10);
word1[8]+=48;
word1[9]+=48;
word1[10]+=48;
word1[11]+=48;
word1[12]='C';
}
else
{
word1[3]='+';
t=readdata[1];
t<<=8;
t=t|readdata[0];
t>>=4;
word1[4]=t/100+48;
word1[5]=((t/10)%10)+48;
word1[6]=t%10+48;
temp=readdata[0];
temp=temp&0x0f;
tt=temp*0.0625;
word1[7]='.';
word1[8]=(unsigned char )(tt*10);
word1[9]=(unsigned char )(tt*100-word1[8]*10);
word1[10]=(unsigned char )(tt*1000-word1[8]*100-word1[9]*10);
word1[11]=(unsigned char )(tt*10000-word1[8]*1000-word1[9]*100-word1[10]*10);
word1[8]+=48;
word1[9]+=48;
word1[10]+=48;
word1[11]+=48;
word1[12]='C';
}
}
/////////////////////end of ds18b20//////////////////
///////////////start of lcd 1602/////////////////
void busy()
{
do
{
busyflag=REG1;
}while(busyflag_7);
}
void wrc(unsigned char wcon)
{
busy();
REG0=wcon;
}
void wrd(unsigned char wdat)
{
busy();
REG2=wdat;
}
void rdd()
{
busy();
dat=REG3;
}
void lcdint()
{
wrc(0x38);
wrc(0x01);
wrc(0x06);
wrc(0x0c);
}
void wrn(unsigned char word[])
{
unsigned char i;
for(i=0;i<16;i++)
{
wrd(word[i]);
}
}
//////////////end of lcd 1602///////////////////////
void main()
{
lcdint();//初始化液晶
wrc(0x80);
wrn(word5);
wrc(0xc0);
wrn(word6);
while(1)
{
//if(p10==0) //判断P1.0是否按下
{
ReadTemperature();
Tempprocess();
wrc(0x80);
wrn(word1);
wrc(0xc0);
wrn(word2);
}
if(p11==0)//判断P1.1是否按下
{
wrc(0x80);
wrn(word3);
wrc(0xc0);
wrn(word4);
}
if(p12==0)//判断P1.2是否按下
{
wrc(0x80);
wrn(word7);
wrc(0xc0);
wrn(word8);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -