《led点阵数字钟与温度计》由会员分享,可在线阅读,更多相关《led点阵数字钟与温度计(27页珍藏版)》请在金锄头文库上搜索。
1、1LED 点阵数字钟与温度计一、系统设计方案本 LED 点阵数字钟基于 STC89C52RC 单片机设计,使用 5 片 6*7 的 LED 点阵作为显示屏。通过设计系统可以完成显示时间,日期,并增加了用 DS18B20 温度传感器显示温度的功能。同时,通过程序的改变可以为点阵数字钟扩充例如闹钟,字幕滚屏等功能。LED 点阵数字钟通过单片机来完成计时,设定,温度测量等功能。显示部分通过74HC595 通用移位寄存器,完成点阵屏幕与单片机连接从而完成显示部分的功能。其系统组成框图如下:图 1二、单元电路设计1.MCU 控制部分单片机的时钟周期由外部 12M 晶振,时间信息则通过 DS1302 产生
2、。DS1302 通过串行方式与单片机进行数据传送,能够向单片机提供包括秒、分、时、日、月、年等在内的实时时间信息,并可对月末日期、闰年天数自动进行调整;它还拥有用于主电源和备份电源的双电源引脚,在主电源关闭的情况下,也能保持时钟的连续运行。从而完成断电计时的功能。其中 DS1302 采用 32.768KHz 的晶振提供时钟周期(原理图见附录 1)按键 1按键 2按键 3STC89C52RCDS1302274HC595 LED 点阵22.LED 点阵显示部分74HC595 通用移位寄存器并行输出端具有输出锁存功能。与单片机连接简单方便,只须三个 I/O 口即可。而且通过芯片的 Q7 引脚和 SE
3、R 引脚,可以级联。点阵屏幕由 5片 6*7 的 LED 点阵组成。采用 74HC595 来实现时钟的动态显示。点阵屏幕段选码由 4片 74HC595 控制,段选数据由 74HC595 的 SER 引脚串行输入,由于输出使能时钟 RCLK并接在一起,因此,4 片 74HC595 并行输出端同时输出。而 5 个点阵位选信号也并接在一起,因此,一次可以同时点亮 4 列此过程类似于静态显示。每片 74HC595 并行输出端并接到点阵的每一位的引脚,用于扫描输出,此过程类似于动态扫描过程。此方法运用 4 片 74HC595,7 条位选信号,从而实现 LED 点阵的显示.其中位选控制端为通过经三极管放大
4、后的 P2 口输出信号控制。 (原理图见附录 2)3.电源部分采用普通电源接口和USB接口,可以使用5V,400mA电源供电,亦可使用电脑USB供电。预设备用电源纽扣电池接口,保证时钟断电后继续走时。三、程序设计1. 定义字符#include reg52.h#define uchar unsigned char #define uint unsigned int/74HC595 管脚定义sbit S_DIO = P30; sbit S_CLK = P31; sbit R_CLK = P32;/按键管脚定义sbit KEY_1 = P11; sbit KEY_2 = P12; sbit KEY_
5、3 = P10;/蜂鸣器管脚定义sbit BEEP = P27;/DS18B20 管脚定义sbit DQ = P34;uchar temp_value; unsigned char tempL=0; /设全局变量unsigned char tempH=0; unsigned int sdata;/测量到的温度的整数部分unsigned char xiaoshu1;/小数第一位unsigned char xiaoshu2;/小数第二位3unsigned char xiaoshu;/两位小数bit fg=1; /温度正负标志,等于 0 时为负数/DS1302 管脚定义sbit T_CLK = P3
6、5; sbit T_IO = P36; sbit T_RST = P37; sbit ACC0 = ACC0;sbit ACC1 = ACC1;sbit ACC2 = ACC2;sbit ACC3 = ACC3;sbit ACC4 = ACC4;sbit ACC5 = ACC5;sbit ACC6 = ACC6;sbit ACC7 = ACC7;bit distime,disdate,disyear,distweek,diswendu,setyear,setdate,settime,setalarm,setweek;unsigned char code Bmp74=0xff,0xff,0xff
7、,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,;unsigned char code font7=0x38,0x44,0x64,0x54,0x4C,0x44,0x38,/0xF8,0x88,0x88,0x88,0x88,0x88,0xF8, /-00x10,0x18,0x10,0x10,0x10,0x10,0x38,/0x20,0x30,0x28,0x20,0x20,0x20,0xF8, /
8、-10x38,0x44,0x40,0x20,0x10,0x08,0x7C,/0xF8,0x80,0x80,0xF8,0x08,0x08,0xF8, /-20x7C,0x20,0x10,0x20,0x40,0x44,0x38,/0xF8,0x80,0x80,0xF8,0x80,0x80,0xF8, /-30x20,0x30,0x28,0x24,0x7C,0x20,0x20,/0x48,0x48,0x48,0x48,0xF8,0x40,0x40, /-40x7C,0x04,0x3C,0x40,0x40,0x44,0x38,/0xF8,0x08,0x08,0xF8,0x80,0x80,0xF8, 4
9、/-50x70,0x08,0x04,0x3C,0x44,0x44,0x38,/0xF8,0x08,0x08,0xF8,0x88,0x88,0xF8, /-60x7C,0x40,0x20,0x10,0x08,0x08,0x08,/0xF8,0x80,0x80,0x80,0x80,0x80,0x80, /-70x38,0x44,0x44,0x38,0x44,0x44,0x38,/0xF8,0x88,0x88,0xF8,0x88,0x88,0xF8, /-80x38,0x44,0x44,0x78,0x40,0x20,0x1C,/0xF8,0x88,0x88,0xF8,0x80,0x80,0x80,
10、/-90x00,0x30,0x30,0x00,0x30,0x30,0x00, /-10-:0x78,0x48,0x78,0x48,0x78,0x48,0x64, /-11-月0x78,0x48,0x48,0x78,0x48,0x48,0x78, /-12-日0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /-13-0x00,0x00,0x00,0x00,0x00,0x00,0x00, /-14- 0x3C,0x44,0x44,0x44,0x44,0x44,0x3C, /-15- D0x44,0x44,0x44,0x28,0x10,0x10,0x10, /-16- Y0x
11、08,0xF8,0x24,0xF8,0x28,0xFC,0x20, /-17-年0x88,0xA8,0xA8,0xA8,0xA8,0xF8,0x70, /-18- W0x88,0x48,0x28,0x18,0x28,0x48,0x88, /-19- K0x00,0x00,0x00,0x38,0x00,0x00,0x00, /-20-0x00,0x00,0x00,0x00,0x00,0x30,0x30, /-21-.0xE8,0x10,0x10,0x10,0x10,0x10,0xE0, /-22-;unsigned char idata DisTemp57;unsigned char idata
12、 Dis5;/时钟数据(7 字节 BCD 码)格式为: 秒 分 时 日 月星期 年unsigned char idata Time7;/=0x30,0x42,0x23,0x18,0x06,0x04,0x09;unsigned char idata alarm2=0x30,0x06;uchar alarm_hh,alarm_ss,alarm_fg,alarm_off,flag;/闹钟unsigned char idata CSRow7=0x01,0x02,0x04,0x08,0x10,0x20,0x40;unsigned char idata second,minute,hour,day,mon
13、th,week,year,time_revise;unsigned char idata keyvalue;unsigned long int idata Disbuf5;unsigned long int idata Disbuftemp7;unsigned int ss,i,TimeT1;/* * 函数名: Delay 5* 功能描述:延时(带参数) */ void Delay(unsigned int i)unsigned int j;for(j=0;j0; i-)T_IO = ACC0; T_CLK = 1;T_CLK = 0;ACC = ACC 1; /* * 函数名: ReadByteDS1302 * 功能描述: */ unsigned char ReadByteDS1302(void) unsigned char i;for(i=8; i0; i-)ACC = ACC 1; ACC7 = T_IO;T_CLK = 1;T_CLK = 0; 7return(ACC); /*