找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5009|回复: 0
打印 上一主题 下一主题
收起左侧

基于51单片机的电子万年历代码

[复制链接]
跳转到指定楼层
楼主
ID:441643 发表于 2018-12-7 14:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include < reg52.h >

#include < character.h >

#include < lcd.h >

#include < clock.h >

#include < sensor.h>

#include < calendar.h >

#include < key.h >

/*****************************预定义**************************************/

#define uchar unsigned char

#define uint unsigned int

/****************************************************************************/ sbit bell = P2 ^ 0; //定义蜂鸣器端口

sbit in = P2 ^ 7; //定义红外检测端口

/***************************************************************************** * 名称: Timer0_Service() inturrupt 1

* 功能: 中断服务程序整点报时3声嘟嘟的声音

*****************************************************************************/ void Timer0_Service() interrupt 1

{

static uchar count = 0;

static uchar flag = 0; //记录鸣叫的次数

count = 0;

TR0 = 0; //关闭Timer0

TH0 = 0x3c;

TL0 = 0XB0; //延时50 ms

TR0 = 1 ; //启动Timer0

count ++;

if( count == 20 ) //鸣叫1 秒

{

bell = ~ bell;

count = 0;

flag ++;

}

if( flag == 6 )

{

flag = 0;

TR0 = 0; //关闭Timer0

}

}

/*****************************************************************************

* 名称: Timer2_Servie() interrupt 5

* 功能: 中断服务程序整点报时一分钟

*****************************************************************************/

void Timer3_Service() interrupt 5

{

static uchar count;

TF2 = 0; //软件清除中断标志

count ++;

if( in == 1 )

{

count = 0; //计算清0

TR2 = 0; //关闭Timer2

bell = 1; //关闭蜂鸣器

}

if( count == 120 ) // 一分钟后关闭报警

{

count = 0; //计算清0

TR2 = 0; //关闭Timer2

bell = 1; //关闭蜂鸣器

}

}

/******************************************************************************

* 函数名称:main()

********************************************************************************/

void main( void )

{

uchar clock_time[7] = { 0x00, 0x00, 0x12, 0x29, 0x06, 0x08 }; //定义时间变量秒分时日月年uchar alarm_time[2] = { 0, 0}; //闹钟设置alarm_time[0]: 分钟alarm_time[1] :小时

uchar temperature[2]; //定义温度变量temperature[0] 低8位temperature[1] 高8位

Lcd_Initial(); //LCD初始化

clock_Initial( clock_time ); //时钟初试化

/***********************中断初始化***************************/

EA = 1; //开总中断

ET0 = 1; //Timer0 开中断

ET2 = 1; //Timer2 开中断

TMOD = 0x01 ; //Timer0 工作方式1

RCAP2H = 0x3c;

RCAP2L = 0xb0; //Timer2 延时50 ms

while( 1 )

{

switch( Key_Scan() )

{

case up_array:

{

Key_Idle();

}

break;

case down_array:

{

Key_Idle();

}

break;

case clear_array:

{

Key_Idle();

}

break;

case function_array:{

Key_Function( clock_time, alarm_time );

}

case null:

{

Clock_Fresh( clock_time ); //时间刷新

Lcd_Clock( clock_time ); //时间显示

Sensor_Fresh( temperature ); //温度更新

Lcd_Temperture( temperature ); //温度显示

Calendar_Convert( 0 , clock_time );

Week_Convert( 0, clock_time );

//整点报时

if( ( * clock_time == 0x59 ) && ( * ( clock_time + 1 ) == 0x59 ) )

{

bell = 0;

TR2 = 1; //启动Timer2

}

//闹钟报警

if( * alarm_time == * ( clock_time + 1 ) ) //分钟相吻合

if( * ( alarm_time + 1 ) == *( clock_time + 2 ) ) //小时相吻合

{

bell = 0;

TR2 = 1; //启动Timer2

}

}

break;

}

}

}
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表