欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
單片機(jī)實(shí)時時鐘 仿真電路原理圖程序 ds1302+lcd1602
[打印本頁]
作者:
gaoweijie
時間:
2019-4-23 15:38
標(biāo)題:
單片機(jī)實(shí)時時鐘 仿真電路原理圖程序 ds1302+lcd1602
實(shí)時時鐘 仿真電路原理圖程序
可以直接拿去用
0.png
(13.01 KB, 下載次數(shù): 16)
下載附件
2019-4-23 17:53 上傳
單片機(jī)源程序如下:
/*******************************************************************************
* 實(shí)驗名: 用單片機(jī)實(shí)現(xiàn)的實(shí)時時鐘系統(tǒng)研究
* 使用的IO:
* 實(shí)驗效果 :1602顯示時鐘
* 注意 :
*******************************************************************************/
#include<reg51.h>
#include"lcd.h"
#include"ds1302.h"
sbit SET_KEY=P3^7;
sbit ADD_KEY=P3^6;
sbit SUB_KEY=P3^5;
sbit DETERMINE_KEY=P3^4;
unsigned char Set_Step = 0;
#define NormalRun 0
#define SetYear 1
#define SetMon 2
#define SetDay 3
#define SetHour 4
#define SetMin 5
#define SetSec 6
#define SetWeek 7
void LcdDisplay();
extern unsigned char TIME[7]; //加入全局變量
void Key_Scan();
/*******************************************************************************
* 函數(shù)名 : main
* 函數(shù)功能 : 主函數(shù)
* 輸入 : 無
* 輸出 : 無
*******************************************************************************/
void main()
{
Set_Step = NormalRun;
LcdInit();
//Ds1302Init();
while(1)
{
Key_Scan();
if(Set_Step == NormalRun)
{
Ds1302ReadTime();
LcdDisplay();
}
}
}
/*******************************************************************************
* 函數(shù)名 : LcdDisplay()
* 函數(shù)功能 : 顯示函數(shù)
* 輸入 : 無
* 輸出 : 無
*******************************************************************************/
void LcdDisplay()
{
LcdWriteCom(0x80+0X40);
LcdWriteData('0'+TIME[2]/16); //時
LcdWriteData('0'+((TIME[2]%16)&0x0f));
LcdWriteData(':');
LcdWriteData('0'+TIME[1]/16); //分
LcdWriteData('0'+((TIME[1]%16)&0x0f));
LcdWriteData(':');
LcdWriteData('0'+TIME[0]/16); //秒
LcdWriteData('0'+((TIME[0]%16)&0x0f));
LcdWriteCom(0x80);
LcdWriteData('2');
LcdWriteData('0');
LcdWriteData('0'+TIME[6]/16); //年
LcdWriteData('0'+((TIME[6]%16)&0x0f));
LcdWriteData('-');
LcdWriteData('0'+TIME[4]/16); //月
LcdWriteData('0'+((TIME[4]%16)&0x0f));
LcdWriteData('-');
LcdWriteData('0'+TIME[3]/16); //日
LcdWriteData('0'+((TIME[3]%16)&0x0f));
LcdWriteCom(0x8D);
LcdWriteData('W'); //星期
if(TIME[5]==1)
LcdWriteData('7');
else
LcdWriteData('0'+((TIME[5]-1)&0x07)); //星期
}
void Key_Scan()
{
if(SET_KEY == 0)
{
Delay10us(5000);
if(SET_KEY == 0)
{
LcdWriteCom(0x0f);//顯示光標(biāo)
switch(Set_Step)
{
case NormalRun:
LcdWriteCom(0x83); //設(shè)置光標(biāo)
Set_Step = SetYear;
break;
case SetYear:
LcdWriteCom(0x86); //設(shè)置光標(biāo)
Set_Step = SetMon;
break;
case SetMon:
LcdWriteCom(0x89); //設(shè)置光標(biāo)
Set_Step = SetDay;
break;
case SetDay:
LcdWriteCom(0xc1); //設(shè)置光標(biāo)
Set_Step = SetHour;
break;
case SetHour:
LcdWriteCom(0xc4); //設(shè)置光標(biāo)
Set_Step = SetMin;
break;
case SetMin:
LcdWriteCom(0xc7); //設(shè)置光標(biāo)
Set_Step = SetSec;
break;
case SetSec:
LcdWriteCom(0x8E); //設(shè)置光標(biāo)
Set_Step = SetWeek;
break;
case SetWeek:
LcdWriteCom(0x83); //設(shè)置光標(biāo)
Set_Step = SetYear;
break;
}
}
}
if(Set_Step == NormalRun)
return ;
if(ADD_KEY == 0)
{
Delay10us(5000);
if(ADD_KEY == 0)
{
if(Set_Step == SetYear)
{
if(TIME[6] == 0x99)
TIME[6] = 0x0;
else
{
TIME[6]=(TIME[6]/16)*10+(TIME[6]%16);
TIME[6]=TIME[6]+1;
TIME[6]=(TIME[6]/10)*16+(TIME[6]%10);
}
LcdDisplay();
LcdWriteCom(0x83); //設(shè)置光標(biāo)
}
else if(Set_Step == SetMon)
{
if(TIME[4] == 0x12)
TIME[4] = 0x1;
else
{
TIME[4]=(TIME[4]/16)*10+(TIME[4]%16);
TIME[4]=TIME[4]+1;
TIME[4]=(TIME[4]/10)*16+(TIME[4]%10);
}
LcdDisplay();
LcdWriteCom(0x86); //設(shè)置光標(biāo)
}
else if(Set_Step == SetDay)
{
TIME[3]=(TIME[3]/16)*10+(TIME[3]%16);
TIME[3]=TIME[3]+1;
TIME[3]=(TIME[3]/10)*16+(TIME[3]%10);
LcdDisplay();
LcdWriteCom(0x89); //設(shè)置光標(biāo)
}
else if(Set_Step == SetHour)
{
if(TIME[2] == 0x23)
TIME[2] = 0x0;
else
{
TIME[2]=(TIME[2]/16)*10+(TIME[2]%16);
TIME[2]=TIME[2]+1;
TIME[2]=(TIME[2]/10)*16+(TIME[2]%10);
}
LcdDisplay();
LcdWriteCom(0xc1); //設(shè)置光標(biāo)
}
else if(Set_Step == SetMin)
{
if(TIME[1] == 0x59)
TIME[1] = 0x0;
else
{
TIME[1]=(TIME[1]/16)*10+(TIME[1]%16);
TIME[1]=TIME[1]+1;
TIME[1]=(TIME[1]/10)*16+(TIME[1]%10);
}
LcdDisplay();
LcdWriteCom(0xc4); //設(shè)置光標(biāo)
}
else if(Set_Step == SetSec)
{
if(TIME[0] == 0x59)
TIME[0] = 0x0;
else
{
TIME[0]=(TIME[0]/16)*10+(TIME[0]%16);
TIME[0]=TIME[0]+1;
TIME[0]=(TIME[0]/10)*16+(TIME[0]%10);
}
LcdDisplay();
LcdWriteCom(0xc7); //設(shè)置光標(biāo)
}
else if(Set_Step == SetWeek)
{
if(TIME[5] == 7)
TIME[5] = 1;
else
TIME[5] = TIME[5]+1;
LcdDisplay();
LcdWriteCom(0x8E); //設(shè)置光標(biāo)
}
}
}
if(SUB_KEY == 0)
{
Delay10us(5000);
if(SUB_KEY == 0)
{
if(Set_Step == SetYear)
{
if(TIME[6] == 0x00)
TIME[6] = 0x99;
else
{
TIME[6]=(TIME[6]/16)*10+(TIME[6]%16);
TIME[6]=TIME[6]-1;
TIME[6]=(TIME[6]/10)*16+(TIME[6]%10);
}
LcdDisplay();
LcdWriteCom(0x83); //設(shè)置光標(biāo)
}
else if(Set_Step == SetMon)
{
if(TIME[4] == 0x01)
TIME[4] = 0x12;
else
{
TIME[4]=(TIME[4]/16)*10+(TIME[4]%16);
TIME[4]=TIME[4]-1;
TIME[4]=(TIME[4]/10)*16+(TIME[4]%10);
}
LcdDisplay();
LcdWriteCom(0x86); //設(shè)置光標(biāo)
}
else if(Set_Step == SetDay)
{
TIME[3]=(TIME[3]/16)*10+(TIME[3]%16);
TIME[3]=TIME[3]-1;
TIME[3]=(TIME[3]/10)*16+(TIME[3]%10);
LcdDisplay();
LcdWriteCom(0x89); //設(shè)置光標(biāo)
}
else if(Set_Step == SetHour)
{
if(TIME[2] == 0x00)
TIME[2] = 0x23;
else
{
TIME[2]=(TIME[2]/16)*10+(TIME[2]%16);
TIME[2]=TIME[2]-1;
TIME[2]=(TIME[2]/10)*16+(TIME[2]%10);
}
LcdDisplay();
LcdWriteCom(0xc1); //設(shè)置光標(biāo)
}
else if(Set_Step == SetMin)
{
if(TIME[1] == 0x00)
TIME[1] = 0x59;
else
{
TIME[1]=(TIME[1]/16)*10+(TIME[1]%16);
TIME[1]=TIME[1]-1;
TIME[1]=(TIME[1]/10)*16+(TIME[1]%10);
}
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
實(shí)時時鐘.rar
(318.13 KB, 下載次數(shù): 23)
2019-4-23 15:37 上傳
點(diǎn)擊文件名下載附件
仿真電路原理圖
下載積分: 黑幣 -5
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1