?? test.c
字號(hào):
/**************************************************************************
* 文 件 名:test.c
* 功 能:我的小制作-------萬(wàn)年歷( 陰歷)
* 作 者:卓超
* QQ : 305661237
**************************************************************************/
/****************************文件包含*************************************/
#include < reg52.h >
#include < character.h >
#include < lcd.h >
#include < sensor.h>
#include < calendar.h >
#include < key.h >
/*****************************預(yù)定義**************************************/
#define uchar unsigned char
#define uint unsigned int
/****************************************************************************/
sbit bell = P2 ^ 0; //定義蜂鳴器端口
sbit in = P2 ^ 7; //定義紅外檢測(cè)端口
/*****************************************************************************
* 名稱: Timer0_Service() inturrupt 1
* 功能: 中斷服務(wù)程序 整點(diǎn)報(bào)時(shí) 3聲嘟嘟的聲音
* 入口參數(shù):
* 出口參數(shù):
*****************************************************************************/
void Timer0_Service() interrupt 1
{
static uchar count = 0;
static uchar flag = 0; //記錄鳴叫的次數(shù)
count = 0;
TR0 = 0; //關(guān)閉Timer0
TH0 = 0x3c;
TL0 = 0XB0; //延時(shí) 50 ms
TR0 = 1 ; //啟動(dòng)Timer0
count ++;
if( count == 20 ) //鳴叫 1 秒
{
bell = ~ bell;
count = 0;
flag ++;
}
if( flag == 6 )
{
flag = 0;
TR0 = 0; //關(guān)閉Timer0
}
}
/*****************************************************************************
* 名稱: Timer2_Servie() interrupt 5
* 功能: 中斷服務(wù)程序 整點(diǎn)報(bào)時(shí) 一分鐘
* 入口參數(shù):
* 出口參數(shù):
*****************************************************************************/
void Timer3_Service() interrupt 5
{
static uchar count;
TF2 = 0; //軟件清除中斷標(biāo)志
count ++;
if( in == 1 )
{
count = 0; //計(jì)算清0
TR2 = 0; //關(guān)閉Timer2
bell = 1; //關(guān)閉蜂鳴器
}
if( count == 120 ) // 一分鐘后 關(guān)閉報(bào)警
{
count = 0; //計(jì)算清0
TR2 = 0; //關(guān)閉Timer2
bell = 1; //關(guān)閉蜂鳴器
}
}
/******************************************************************************
* 函數(shù)名稱:main()
* 功 能:
* 入口參數(shù):
* 出口參數(shù):
********************************************************************************/
void main( void )
{
uchar clock_time[7] = { 0x00, 0x00, 0x02, 0x01, 0x06, 0x07 }; //定義時(shí)間變量 秒 分 時(shí) 日 月 年
uchar alarm_time[2] = { 0, 0}; //鬧鐘設(shè)置 alarm_time[0]: 分鐘 alarm_time[1] :小時(shí)
uchar temperature[2]; //定義溫度變量 temperature[0] 低8位 temperature[1] 高8位
Lcd_Initial(); //LCD初始化
Clock_Initial( clock_time ); //時(shí)鐘初試化
/***********************中斷初始化***************************/
EA = 1; //開總中斷
ET0 = 1; //Timer0 開中斷
ET2 = 1; //Timer2 開中斷
TMOD = 0x01 ; //Timer0 工作方式 1
RCAP2H = 0x3c;
RCAP2L = 0xb0; //Timer2 延時(shí) 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 ); //時(shí)間刷新
Lcd_Clock( clock_time ); //時(shí)間顯示
Sensor_Fresh( temperature ); //溫度更新
Lcd_Temperture( temperature ); //溫度顯示
Calendar_Convert( 0 , clock_time );
Week_Convert( 0, clock_time );
//整點(diǎn)報(bào)時(shí)
if( ( * clock_time == 0x59 ) && ( * ( clock_time + 1 ) == 0x59 ) )
{
bell = 0;
TR2 = 1; //啟動(dòng)Timer2
}
//鬧鐘報(bào)警
if( * alarm_time == * ( clock_time + 1 ) ) //分鐘相吻合
if( * ( alarm_time + 1 ) == *( clock_time + 2 ) ) //小時(shí)相吻合
{
bell = 0;
TR2 = 1; //啟動(dòng)Timer2
}
}
break;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -