
新年啦,天冷注意穿衣,锂电池供电数显温度计
简介
新年氛围,锂电池供电数显温度计,带type-C充电。可做电子时钟或日历。
简介:新年氛围,锂电池供电数显温度计,带type-C充电。可做电子时钟或日历。开源协议
:GPL 3.0
描述
视频链接:
https://www.bilibili.com/video/BV1MicuePEGS/?vd_source=9b23d39617208d6bbc9076c6079c4e15
外壳模型下载链接:
https://makerworld.com.cn/zh/models/827980#profileId-810617
项目简介
本项目是基于51单片机的数码管显示温度计,利用DS18B20检测温度。使用锂电池或者TYPE-C供电,包含锂电池充电管理芯片。
项目功能
本项目是基于51单片机的数码管显示温度计,利用DS18B20检测温度。使用锂电池或者TYPE-C供电,包含锂电池充电管理芯片。
设置6个物理按键,可以进行功能扩展。
单片机使用I/O口进行了引出,PCBA未来也可以挪作他用。
项目参数
此处可填写项目的相关功能参数介绍,示例:
- 本设计采用STC89C52RD,工作电压:5.5V-3.3V(5V单片机);
- 本设计采用4位8段共阴数码管显示,带小数点显示,用于显示温度;
- 选用DS18B20数字温度传感器,测温范围 -55℃~+125℃,工作电压: 2.5~5.5V/DC,TO-92封装;
- 选用 TC4058H 作为锂电池充电电源管理 IC;
原理解析(硬件说明)
51单片机么,应该都懂的。
TC4058H 是一款锂电池充电电源管理 IC
软件代码
#include
#define uchar unsigned char
#define uint unsigned int
#define dula P0 //段选信号的锁存器控制
sbit wei1=P2^4;
sbit wei2=P2^5;
sbit wei3=P2^6;
sbit wei4=P2^7;
sbit DS=P2^2; //define interface
uint temp; // variable of temperature
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
0x87,0xff,0xef};
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; //将总线拉低480us~960us
while(i>0)i--;
DS=1; //然后拉高总线,若DS18B20做出反应会将在15us~60us后将总线拉低
i=4; //15us~60us等待
while(i>0)i--;
//while(DS);
}
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); //读出的数据最低位在最前面,这样刚好一个字节在DAT里
}
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
//delay(100);
}
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) //显示程序
{
uchar bai,shi1,shi0,ge;
bai=temp/100;//温度数值上为十位
shi0=temp%100;//温度数值上为几点几
shi1=shi0/10;//温度上为个位,并且显示时需要加小数点
ge=shi0%10;//温度上为小数位,并已经四舍五入
wei1=1; //显示百位
wei2=0;
wei3=0;
wei4=0;
P0=table[bai];
delay(2);
wei1=0; //显示十位
wei2=1;
wei3=0;
wei4=0;
P0=table1[shi1];
delay(2);
wei1=0; //显示个位
wei2=0;
wei3=1;
wei4=0;
P0=table[ge];
delay(2);
}
void main()
{
uchar a;
do
{
tmpchange();//让18b20开始转换温度
for(a=100;a>0;a--)
{
display(tmp());
}
}while(1);
}
注意事项
- 推荐直接使用5V供电
组装流程
相信有手就行
实物图
设计图

BOM


评论