基于单片机多功能数字钟系统仿真设计-毕设课设资料

本文档详细介绍了如何使用单片机实现一个具备时钟计时、闹钟设置、时间调整、12/24小时切换、温度显示等功能的系统。涉及到的硬件电路包括显示电路、按键电路、单片机电路、温度传感器电路、时钟电路和声光电路。代码中定义了各控制引脚,并提供了延时函数和关键变量,展示了时间管理和温度读取的实现过程。

资料下载地址-1026(百度网盘):点击下载

实现时钟计时功能,闹钟设置功能,时间调整、12/24小时切换功能,能实时显示温度,包含显示电路,按键电路,单片机电路,温度传感器电路,时钟电路,声光电路等。

#include <reg52.h>
#include <intrins.h>
#define NOP		_nop_()
#define TEMP_ALERT_L	0x00
#define TEMP_ALERT_H	0x25
#define SET_TIME	6500
#define END_ALERT	100
typedef unsigned char	uchar;
typedef unsigned int	uint;

sbit	RS		= P2 ^ 0;       /* P2^0; */
sbit	RW		= P2 ^ 1;       /* P2^1; */
sbit	EN		= P2 ^ 2;       /* P2^2; */
sbit	RST		= P2 ^ 3;       /* DS1302使能信号,高电平有效 */
sbit	CLK		= P2 ^ 4;       /* 时钟信号 */
sbit	IO		= P2 ^ 5;
sbit	DQ		= P2 ^ 6;       /* ds18b20数据线 */
sbit	BUZ		= P2 ^ 7;
sbit	Touch		= P1 ^ 4;
sbit	BG		= P1 ^ 5;
sbit	Key_Select	= P1 ^ 0;
sbit	Key_Up		= P1 ^ 1;
sbit	Key_Down	= P1 ^ 2;
sbit	Key_Alert	= P1 ^ 3;
sbit	Key_12_24	= P1 ^ 6;
sbit	Key_clear	= P1 ^ 7;

bit	timerflag = 0;
uint	j, bg_count = 0, sf1 = SET_TIME, sf2 = 0;
uchar	i, tmp, TEMP, dat, re_dat, wr_dat, alert = 0, temp_flag = 0, select = 0;
uchar	temperature[2];
uchar	alesta[2] = { 'F', 'F' };
uchar	alert_sleep[2] = { 0, 0 };
uchar	alert_hour[2];
uchar	slpcon[2] = { 0, 0 };
uchar	disp1[16]	= "    Welcome!    ";
uchar	disp2[16]	= "Have A Nice Day!";
uchar	alerttime1[2]	= { 0, 0 };
uchar	alerttime2[2] = { 12, 0 };                                      /* 闹钟初始时间 */
uchar	rtc[7] = { 0, 0, 4, 9, 0, 0, 0 };                               /* 即时时间 real time clock */
uchar	writeaddr[7] = { 0x8c, 0x8a, 0x88, 0x86, 0x84, 0x82, 0x80 };    /* 写命令数组  年周月日时分秒 */
uchar	readaddr[7] = { 0x8d, 0x8b, 0x89, 0x87, 0x85, 0x83, 0x81 };

void delay_ms( uint );


void delay_50us( uint );


void delay_us( uchar );

基于51单片机多功能数字钟 片段代码: #include<reg51.h> #include "lcd1602.h" #include "ds1302.h" #include "button.c" sbit buzzer=P1^7; char time_h=0,time_m=0; void scankey(); void main() { uchar t=0,i=0,j=0; buzzer=0; LCD_Initial(); //Init_DS1302(); //仿真不需加 buzzer=0; //LCD_Write(0,0x0d);LCD_Write(0,0x04); while(1) { j=0; scankey(); if(!k_flag0 || flag_xx) //键没未按or置闹钟 { if(flag_xx) //闹钟 { j=1; if(!t)LCD_Write(0,0x01); else t=1; t++; L1602_string(1,1,"Seting Alarm:"); if(!time_h)time_h=hour; if(!time_m)time_m=minute; Set_Alarm(2,1,time_h,time_m); //LCD_Write(0,0x0d); goto_XY(count_y,count_x); if(count_x==1) { if((shi>0&&(time_h/10!=2)) || (shi<0 &&(time_h/10!=0)))time_h+=shi*10; } else if(count_x==2) { if((ge>0&&(time_h!=9)) || (ge<0 &&(time_h!=0)))time_h+=ge; } else if(count_x==4) { if((shi>0&&(time_m/10!=5)) || (shi<0 &&(time_m/10!=0)))time_m+=shi*10; } else if(count_x==5) { if((ge>0&&(time_m!=9)) || (ge<0 &&(time_m!=0)))time_m+=ge; } //L1602_char(2,7,'0'+time_h/10); //L1602_char(2,11,0x30+count_x); //L1602_char(2,14,0x30+flag_xx); if(count_x>5)count_x=1; shi=ge=0; set_time[0]=time_h;set_time[1]=time_m; } else //正常显示 { j=2;t=0; (void)ReadTemperature(); diaplay_Temperature(2,9,integer_value,fraction_value); diaplay_calendar(1,1,2,1); if(hour==set_time[0]&&minute==set_time[1])buzzer=1; else buzzer=0; } } else //时间置 { LCD_Write(0,0x0f); // goto_XY(count_y,count_x); t=0; if(count_x==1)L1602_char(count_y,count_x,0x30+hour/10); else if(count_x==2)L1602_char(count_y,count_x,0x30+hour); else if(count_x==4)L1602_char(count_y,count_x,0x30+minute/10); else if(count_x==5)L1602_char(count_y,count_x,0x30+minute); else if(count_x==6)L1602_char(count_y,count_x,0x30+mouth/10); else if(count_x==7)L1602_char(count_y,count_x,0x30+mouth); else if(count_x==9)L1602_char(count_y,count_x,0x30+day/10); else if(count_x==10)L1602_char(count_y,count_x,0x30+day); shi=ge=0; if(k_flag3) //时间定完成、各值恢复原值。 { k_flag0=0;k_flag3=0; count_x=0;count_y=2; LCD_Write(0,0x0c); DS1302_reset(mouth,day,hour,minute);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值