带温度显示的万年历Word文档格式.docx
《带温度显示的万年历Word文档格式.docx》由会员分享,可在线阅读,更多相关《带温度显示的万年历Word文档格式.docx(40页珍藏版)》请在冰豆网上搜索。
![带温度显示的万年历Word文档格式.docx](https://file1.bdocx.com/fileroot1/2022-10/24/3c2e60aa-dd87-47f7-bfb4-10e063289495/3c2e60aa-dd87-47f7-bfb4-10e0632894951.gif)
二、主要研究内容:
本设计为软件,硬件相结合的一组设计。
在软件设计过程中,应对硬件部分有相关了解,这样有助于对设计题目的更深了解,有助于软件设计。
基本的要了解一些主要器件的基本功能和作用。
本设计以STC89C52单片机为控制核心,将时间数据通过LCD1602显示出来,同时通过相应的按键调整相应的值。
通过温度传感器将采集到的温度实时的显示在显示屏上。
本设计可分为以下模块进行设计:
显示模块,时间计算模块,设置模块,温度采集模块。
显示模块采用用液晶显示器LCD1602显示,通过P2.0、P2.1、P2.2和P0给1602送指令和数据来控制想要显示的位置和数据;
时间计算模块使用时钟芯片DS1302来进行时间和日期的计算,采用的是SPI总线,单片机通过模拟SPI接口来与它进行通信,他只有三条线与单片机连接,其他接晶振、电源和地线;
设置模块为键盘模块,有两个按键分别接到单片机的外部中断,其他三个采用的是键盘扫描,并且在程序中进行了按键消抖,温度采集模块使用的是DS18B20,它直接将模拟的温度量转换为数字量,采用单总线与单片机相连,这样可以省出大量的I/O口,供给其他芯片使用,在电路中还加入了闹钟的功能,闹钟的程序采用定时器控制,这样在显示时间和日期的同时,闹钟同时起作用。
三、设计的方法及步骤:
1、整个系统由主控模块和显示模块两大模块组成,主控模块包括主控芯片、温度检测、实时时钟电路及键盘接口电路,系统构成框图如下图
(1)所示。
图
(1)系统框图
2、设计步骤
(1)将LCD液晶的数据口接到P0口,P0口接上拉电阻,P2.0、P2.1、P2.2分别接到1602的RS、RW和E端口。
(2)将DS1302的SCLK,I/O,复位键接到P1.0,P1.1,P1.2;
(3)将温度芯片DS18B20接到P2.3。
(4)按键接到P3口上,通过P3.7来控制蜂鸣器的发声,起到闹钟的目的。
四、实验设计(相关原理框图):
1、主程序流程图
(2)
图
(2)主程序流程图
时间调整部分的设计流程图(3):
图(3)时间调整
主程序:
#include<
reg52.h>
intrins.h>
#include"
ds1302.h"
LCD1602.h"
ds18b20.h"
#defineucharunsignedchar
#defineuintunsignedint
sbitgon=P3^4;
sbite=P3^3;
sbitxiang=P3^7;
sbitjia=P3^6;
sbitjian=P3^5;
sbita1=P1^3;
sbita2=P1^4;
sbita3=P1^5;
sbita4=P1^6;
sbita5=P1^7;
voidgong_neng();
voiddingshi();
voidkey();
uchartimes[9];
uchardate[9];
ucharhuan;
uchartp=0,temp1=0,temp2=0,temp3=0,temp4=0,temp5=0,neng=0,d_shi=0,d_fen=5,d_shi_g=0,
d_fen_g=5,d_shi_s=0,d_fen_s=0,d_flag=0,kai=0,s_flag=0,mingzi=0,temp6=0,temp7=0;
uintdeng=0;
voidchange()
{
//时间的转换
times[0]=time_1302[2]/10+'
0'
;
times[1]=time_1302[2]%10+'
times[2]='
:
'
times[3]=time_1302[1]/10+'
times[4]=time_1302[1]%10+'
times[5]='
times[6]=time_1302[0]/10+'
times[7]=time_1302[0]%10+'
//日期的转换
date[0]=time_1302[6]/10+'
date[1]=time_1302[6]%10+'
date[2]='
-'
date[3]=time_1302[4]/10+'
date[4]=time_1302[4]%10+'
date[5]='
date[6]=time_1302[3]/10+'
date[7]=time_1302[3]%10+'
}
voidxiangling();
voidDisp_Temperature()
{
display[4]=temp_data[0]&
0x0f;
display[0]=ditab[display[4]]+0x30;
//查表得小数位的值
display[4]=((temp_data[0]&
0xf0)>
>
4)|((temp_data[1]&
0x0f)<
<
4);
display[3]=display[4]/100+0x30;
display[1]=display[4]%100;
display[2]=display[1]/10+0x30;
display[1]=display[1]%10+0x30;
if(display[3]==0x30)//高位为0,不显示
{
display[3]=0x20;
if(display[2]==0x30)//次高位为0,不显示
display[2]=0x20;
}
gotoxy(11,1);
//在LCD第一行显示
LCD_write_data(display[3]);
//百位数显示
gotoxy(12,1);
LCD_write_data(display[2]);
//十位数显示
gotoxy(13,1);
LCD_write_data(display[1]);
gotoxy(14,1);
LCD_write_data(0x2e);
//xiao数显示
gotoxy(15,1);
LCD_write_data(display[0]);
gotoxy(14,2);
LCD_write_data(0xdf);
gotoxy(15,2);
LCD_write_data('
C'
);
voidmain()
EA=1;
EX0=1;
IT0=1;
EX1=1;
IT1=1;
ET0=1;
TMOD=0X01;
TH0=(65535-5000)/256;
TL0=(65535-5000)%256;
TR0=1;
LCD_init();
//LCD初始化
init_1302(time_1302);
gotoxy(0,1);
LCD_display("
s:
"
gotoxy(0,2);
r:
times[8]='
\0'
//
date[8]='
huan=1;
P3=0xff;
xiang=0;
if(kai==0)
{
gotoxy(11,1);
LCD_write_data(0xef);
}
while
(1)
{
while(huan==1)
{
gong_neng();
key();
gotoxy(0,1);
LCD_display("
t:
gotoxy(0,2);
d:
get_1302(time_1302);
change();
gotoxy(2,1);
LCD_display(times);
gotoxy(2,2);
LCD_display(date);
if(huan==2)
LCD_init();
dingshi();
if(!
(kai))
{
gotoxy(11,1);
LCD_write_data(0xef);
}
else
{
gotoxy(11,1);
LCD_write_data(0x20);
}
}
while(huan==2)
{
if(mingzi==1)
{
gotoxy(0,1);
LCD_display("
yutong"
gotoxy(0,2);
heguanghao"
}
if(mingzi==3)
{
gotoxy(0,1);
LCD_display("
zm,shaob"
gotoxy(0,2);
LCD_display("
sunyanxiu"
}
if(mingzi==5)
gotoxy(0,1);
xiexie"
gotoxy(0