標(biāo)題:
帶片選LCD12864+RTC1302的時(shí)鐘單片機(jī)程序和Proteus仿真圖
[打印本頁(yè)]
作者:
3花木城
時(shí)間:
2021-12-28 13:35
標(biāo)題:
帶片選LCD12864+RTC1302的時(shí)鐘單片機(jī)程序和Proteus仿真圖
程序如圖,接下來(lái)改成可調(diào)12,24小時(shí)制。
程序和代碼在附近里,
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei截圖_20211227195022.png
(106.14 KB, 下載次數(shù): 46)
下載附件
2021-12-28 13:33 上傳
單片機(jī)源程序如下:
/****************************文件包含*************************************/
#include < reg52.h >
#include < character.h >
#include < lcd.h >
#include < clock.h >
#include < sensor.h>
#include < calendar.h >
#include < key.h >
/*****************************預(yù)定義**************************************/
#define uchar unsigned char
#define uint unsigned int
/****************************************************************************/
sbit bell = P3 ^ 6; //定義蜂鳴器端口
/*****************************************************************************
* 名稱: 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ù):
*****************************************************************************/
uchar HexNum_Convert(uchar HexNum)/*時(shí)間存儲(chǔ)個(gè)位和十位的方式與我們用的十進(jìn)制不一樣,你懂的,呵呵--BB車*/
{
uchar Numtemp;
Numtemp=(HexNum>>4)*10+(HexNum&0X0F);
return Numtemp;
}
/******************************************************************************
* 函數(shù)名稱:main()
* 功 能:
* 入口參數(shù):
* 出口參數(shù):
********************************************************************************/
void main( void )
{
uchar clock_time[6] = {0X00,0X59,0X23,0X09,0X04,0X11}; //定義時(shí)間變量 秒 分 時(shí) 日 月 年
uchar alarm_time[2] = { 10, 06}; //鬧鐘設(shè)置 alarm_time[0]: 分鐘 alarm_time[1] :小時(shí)
uchar temperature[2]; //定義溫度變量 temperature[0] 低8位 temperature[1] 高8位
Lcd_Initial(); //LCD初始化
Clock_Fresh( clock_time ); //我把時(shí)間刷新放在這里,proteus會(huì)調(diào)用當(dāng)前系統(tǒng)時(shí)間,別問(wèn)為什么,經(jīng)驗(yàn),呵呵
Clock_Initial( clock_time ); //時(shí)鐘初試化
/***********************中斷初始化***************************/
EA = 1; //開(kāi)總中斷
ET0 = 1; //Timer0 開(kāi)中斷
ET2 = 1; //Timer2 開(kāi)中斷
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 == HexNum_Convert(* ( clock_time + 1 ) )) //分鐘相吻合
if( * ( alarm_time + 1 ) == HexNum_Convert(*( clock_time + 2 )) ) //小時(shí)相吻合
{
bell = 0;
TR2 = 1; //啟動(dòng)Timer2
}
}
break;
}
}
}
復(fù)制代碼
Keil代碼與Proteus仿真下載:
4.0版 - 嘗試改界面-時(shí)分秒后移一位.7z
(95.05 KB, 下載次數(shù): 25)
2021-12-29 05:42 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1