基于STM32F107的电子温度计Word格式.docx
- 文档编号:19171676
- 上传时间:2023-01-04
- 格式:DOCX
- 页数:16
- 大小:92.94KB
基于STM32F107的电子温度计Word格式.docx
《基于STM32F107的电子温度计Word格式.docx》由会员分享,可在线阅读,更多相关《基于STM32F107的电子温度计Word格式.docx(16页珍藏版)》请在冰豆网上搜索。
该产品除应用于移动电话外,也可广泛应用于各类便携式设备的显示系统。
与其它类型的产品相比,该模块具有以下特点:
●84x48的点阵LCD,可以显示4行汉字,
●采用串行接口与主处理器进行通信,接口信号线数量大幅度减少,包括电源和地在内的信号线仅有9条。
支持多种串行通信协议(如AVR单片机的SPI、MCS51的串口模式0等),传输速率高达4Mbps,可全速写入显示数据,无等待时间。
●可通过导电胶连接模块与印制版,而不用连接电缆,用模块上的金属钩可将模块固定到印制板上,因而非常便于安装和更换。
●LCD控制器/驱动器芯片已绑定到LCD晶片上,模块的体积很小。
●采用低电压供电,正常显示时的工作电流在200μA以下,且具有掉电模式。
LPH7366的这些特点非常适合于电池供电的便携式通信设备和测试设备中
(3)软件设计流程
四、测试结果
开机上电后显示“TAOJING”图标,同时自动进入温度显示模式;
温度可以精确到1位小数。
五、总结
本设计完全基于STM32F107开发板,利用开发板上的DS18B20、LED等资源实现了测温,显示温度等功能。
在测温精度方面也已经达到了预期要求。
附录一:
主函数
#include"
stm32f10x.h"
delay.c"
//包含delay_us(--);
delay_ms(--);
这两个延时函数哦!
lcd.c"
//5110液晶驱动文件
GPIO_InitTypeDefGPIO_InitStructure;
u16i;
//初始化时间计数器
voidGPIO_PP()
{
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;
//配置管脚
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
//最大输出速度为50MHz
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
//通用推挽输出
GPIO_Init(GPIOE,&
GPIO_InitStructure);
//配置以上三句
}
voidGPIO_IPU()
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
u8DS18B20_Read_Bit(void)//readonebit
u8data;
GPIO_PP();
//SETPA0OUTPUT
GPIO_ResetBits(GPIOE,GPIO_Pin_3);
delay_us
(2);
GPIO_SetBits(GPIOE,GPIO_Pin_3);
GPIO_IPU();
//SETPA0INPUT
delay_us(12);
if(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_3))data=1;
elsedata=0;
delay_us(50);
returndata;
u8ReadOneChar(void)//readonebyte
u8i,j,dat;
dat=0;
for(i=1;
i<
=8;
i++)
j=DS18B20_Read_Bit();
dat=(j<
<
7)|(dat>
>
1);
returndat;
voidWriteOneChar(unsignedchardat)
u8j;
u8testb;
//SETPA0OUTPUT;
for(j=1;
j<
j++)
testb=dat&
0x01;
dat=dat>
1;
if(testb)
//Write1
GPIO_SetBits(GPIOE,GPIO_Pin_3);
delay_us(60);
else
//Write0
//----------------------------------------------------
voidInit_DS18B20(void)
GPIO_PP();
//稍做延时
GPIO_ResetBits(GPIOE,GPIO_Pin_3);
//单片机将DQ拉低
delay_us(750);
//精确延时大于480us
GPIO_SetBits(GPIOE,GPIO_Pin_3);
//DQ复位
delay_us(15);
GPIO_IPU();
while(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_3)==1)i++;
//计算传感器应答时间
unsignedintReadTemperature(void)
unsignedchara=0;
unsignedintb=0;
unsignedintt=0;
Init_DS18B20();
delay_ms
(1);
WriteOneChar(0xCC);
//跳过读序号列号的操作
WriteOneChar(0x44);
//启动温度转换
delay_ms(300);
//跳过读序号列号的操作
WriteOneChar(0xBE);
//读取温度寄存器等(共可读9个寄存器)前两个就是温度
a=ReadOneChar();
//低位
b=ReadOneChar();
//高位
b<
t=a+b;
return(t);
intmain()
unsignedinttemp;
unsignedcharTempH,TempL;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_11;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_14;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_15;
//配置以上三
Init_DS18B20();
Init_5110();
while
(1)
{
i=0;
if(i>
100)GPIO_SetBits(GPIOE,GPIO_Pin_4);
//传感器反应时间过长,亮灯,表示没有传感器
temp=ReadTemperature();
if(temp&
0x8000)
temp=~temp;
//取反加1
temp+=1;
}
else
TempH=temp>
4;
TempL=temp&
0x0F;
TempL=TempL*6/10;
//小数近似处理
//----------------显示温度-----------------------
Set_R_C_5110(0,12);
Write_Char_5110('
0'
+(TempH/10));
Set_R_C_5110(0,18);
+(TempH%10));
Set_R_C_5110(0,24);
.'
);
Set_R_C_5110(0,30);
+(TempL));
//------------------------------------显示传感器应答时间
Set_R_C_5110(0,42);
+(i/1000));
Set_R_C_5110(0,48);
+(i%1000/100));
Set_R_C_5110(0,54);
+(i%100/10));
Set_R_C_5110(0,60);
+(i%10));
delay_ms(30);
}
附录二:
LCD5110程序
#include<
string.h>
#defineucharunsignedchar
#defineuintunsignedint
#defineDATA1
#defineCMD0
#defineCLKGPIO_Pin_11
#defineDinGPIO_Pin_12
#defineDCGPIO_Pin_13
#defineCEGPIO_Pin_14
#defineRSTGPIO_Pin_15
unsignedcharasc2[][6]=
{0x00,0x00,0x00,0x00,0x00,0x00},//sp
{0x00,0x00,0x00,0x2f,0x00,0x00},//!
{0x00,0x00,0x07,0x00,0x07,0x00},//"
{0x00,0x14,0x7f,0x14,0x7f,0x14},//#
{0x00,0x24,0x2a,0x7f,0x2a,0x12},//$
{0x00,0x62,0x64,0x08,0x13,0x23},//%
{0x00,0x36,0x49,0x55,0x22,0x50},//&
{0x00,0x00,0x05,0x03,0x00,0x00},//'
{0x00,0x00,0x1c,0x22,0x41,0x00},//(
{0x00,0x00,0x41,0x22,0x1c,0x00},//)
{0x00,0x14,0x08,0x3E,0x08,0x14},//*
{0x00,0x08,0x08,0x3E,0x08,0x08},//+
{0x00,0x00,0x00,0xA0,0x60,0x00},//,
{0x00,0x08,0x08,0x08,0x08,0x08},//-
{0x00,0x00,0x60,0x60,0x00,0x00},//.
{0x00,0x20,0x10,0x08,0x04,0x02},///
{0x00,0x3E,0x51,0x49,0x45,0x3E},//0
{0x00,0x00,0x42,0x7F,0x40,0x00},//1
{0x00,0x42,0x61,0x51,0x49,0x46},//2
{0x00,0x21,0x41,0x45,0x4B,0x31},//3
{0x00,0x18,0x14,0x12,0x7F,0x10},//4
{0x00,0x27,0x45,0x45,0x45,0x39},//5
{0x00,0x3C,0x4A,0x49,0x49,0x30},//6
{0x00,0x01,0x71,0x09,0x05,0x03},//7
{0x00,0x36,0x49,0x49,0x49,0x36},//8
{0x00,0x06,0x49,0x49,0x29,0x1E},//9
{0x00,0x00,0x36,0x36,0x00,0x00},//:
{0x00,0x00,0x56,0x36,0x00,0x00},//;
{0x00,0x08,0x14,0x22,0x41,0x00},//<
{0x00,0x14,0x14,0x14,0x14,0x14},//=
{0x00,0x00,0x41,0x22,0x14,0x08},//>
{0x00,0x02,0x01,0x51,0x09,0x06},//?
{0x00,0x32,0x49,0x59,0x51,0x3E},//@
{0x00,0x7C,0x12,0x11,0x12,0x7C},//A
{0x00,0x7F,0x49,0x49,0x49,0x36},//B
{0x00,0x3E,0x41,0x41,0x41,0x22},//C
{0x00,0x7F,0x41,0x41,0x22,0x1C},//D
{0x00,0x7F,0x49,0x49,0x49,0x41},//E
{0x00,0x7F,0x09,0x09,0x09,0x01},//F
{0x00,0x3E,0x41,0x49,0x49,0x7A},//G
{0x00,0x7F,0x08,0x08,0x08,0x7F},//H
{0x00,0x00,0x41,0x7F,0x41,0x00},//I
{0x00,0x20,0x40,0x41,0x3F,0x01},//J
{0x00,0x7F,0x08,0x14,0x22,0x41},//K
{0x00,0x7F,0x40,0x40,0x40,0x40},//L
{0x00,0x7F,0x02,0x0C,0x02,0x7F},//M
{0x00,0x7F,0x04,0x08,0x10,0x7F},//N
{0x00,0x3E,0x41,0x41,0x41,0x3E},//O
{0x00,0x7F,0x09,0x09,0x09,0x06},//P
{0x00,0x3E,0x41,0x51,0x21,0x5E},//Q
{0x00,0x7F,0x09,0x19,0x29,0x46},//R
{0x00,0x46,0x49,0x49,0x49,0x31},//S
{0x00,0x01,0x01,0x7F,0x01,0x01},//T
{0x00,0x3F,0x40,0x40,0x40,0x3F},//U
{0x00,0x1F,0x20,0x40,0x20,0x1F},//V
{0x00,0x3F,0x40,0x38,0x40,0x3F},//W
{0x00,0x63,0x14,0x08,0x14,0x63},//X
{0x00,0x07,0x08,0x70,0x08,0x07},//Y
{0x00,0x61,0x51,0x49,0x45,0x43},//Z
{0x00,0x00,0x7F,0x41,0x41,0x00},//[
{0x00,0x55,0x2A,0x55,0x2A,0x55},//55
{0x00,0x00,0x41,0x41,0x7F,0x00},//]
{0x00,0x04,0x02,0x01,0x02,0x04},//^
{0x00,0x40,0x40,0x40,0x40,0x40},//_
{0x00,0x00,0x01,0x02,0x04,0x00},//'
{0x00,0x20,0x54,0x54,0x54,0x78},//a
{0x00,0x7F,0x48,0x44,0x44,0x38},//b
{0x00,0x38,0x44,0x44,0x44,0x20},//c
{0x00,0x38,0x44,0x44,0x48,0x7F},//d
{0x00,0x38,0x54,0x54,0x54,0x18,},//e
{0x00,0x08,0x7E,0x09,0x01,0x02},//f
{0x00,0x18,0xA4,0xA4,0xA4,0x7C},//g
{0x00,0x7F,0x08,0x04,0x04,0x78},//h
{0x00,0x00,0x44,0x7D,0x40,0x00},//i
{0x00,0x40,0x80,0x84,0x7D,0x00},//j
{0x00,0x7F,0x10,0x28,0x44,0x00},//k
{0x00,0x00,0x41,0x7F,0x40,0x00},//l
{0x00,0x7C,0x04,0x18,0x04,0x78},//m
{0x00,0x7C,0x08,0x04,0x04,0x78},//n
{0x00,0x38,0x44,0x44,0x44,0x38},//o
{0x00,0xFC,0x24,0x24,0x24,0x18},//p
{0x00,0x18,0x24,0x
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 STM32F107 电子 温度计
![提示](https://static.bdocx.com/images/bang_tan.gif)