單片機電子時鐘
單片機源程序如下:
- #include<reg51.h>
- #include"lcd.h"
- #include"ds1302.h"
- void Int0Configuration();
- void LcdDisplay();
- unsigned char SetState,SetPlace;
- /*******************************************************************************
- * 函數名 : main
- * 函數功能 : 主函數
- * 輸入 : 無
- * 輸出 : 無
- *******************************************************************************/
- void main()
- {
- LcdInit();
- Ds1302Init();
- Ds1302ReadTime();
- while(1)
- {
- if(SetState==0)
- {
- Ds1302ReadTime();
- }
- LcdDisplay();
-
- }
-
- }
- /*******************************************************************************
- * 函數名 : LcdDisplay()
- * 函數功能 : 顯示函數
- * 輸入 : 無
- * 輸出 : 無
- *******************************************************************************/
- void LcdDisplay()
- {
- LcdWriteCom(0x80+0X40);
- LcdWriteData('0'+TIME[2]/16); //時
- LcdWriteData('0'+(TIME[2]&0x0f));
- LcdWriteData('-');
- LcdWriteData('0'+TIME[1]/16); //分
- LcdWriteData('0'+(TIME[1]&0x0f));
- LcdWriteData('-');
- LcdWriteData('0'+TIME[0]/16); //秒
- LcdWriteData('0'+(TIME[0]&0x0f));
- LcdWriteCom(0x80);
- LcdWriteData('2');
- LcdWriteData('0');
- LcdWriteData('0'+TIME[6]/16); //年
- LcdWriteData('0'+(TIME[6]&0x0f));
- LcdWriteData('-');
- LcdWriteData('0'+TIME[4]/16); //月
- LcdWriteData('0'+(TIME[4]&0x0f));
- LcdWriteData('-');
- LcdWriteData('0'+TIME[3]/16); //日
- LcdWriteData('0'+(TIME[3]&0x0f));
- LcdWriteCom(0x8D);
- LcdWriteData('0'+(TIME[5]&0x07)); //星期
- }
復制代碼
所有資料51hei提供下載:
shizhong.zip
(62.93 KB, 下載次數: 4)
2017-9-26 18:39 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|