/*******************************************
点阵时钟
芯片:时钟DS1302,点阵驱动595,温度感应18B20,单片机90C516RD+
存储24C02,点阵8*8(32mm*32mm)共阳
时间;2023.10.28
版本;2023100602 (时钟变化时滚动显示)
编写;明洋工作室
***********************************************/
#include"main.h"
#include"config.h"
#include"font.h"
#include"DS1302.h"
#include"DS18B20.h"
#include"keyboard.h"
unsigned char T1RH = 0; //T1重载值的高字节
unsigned char T1RL = 0; //T1重载值的低字节
bit flag200ms = 0; //200ms进入读时间标志
bit flag500ms = 0;
bit typeTime = 0;
bit flag8s = 0; //1秒更新一次温度标志
struct sTime pdata bufTime; //日期时间缓冲区
enum eStaSystem staSystem = E_NORMAL; //系统开机运行在正常显示状态
//四个点阵缓存
unsigned char UnmberDat[4][8] = {
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}
};
unsigned char Timebuf[13]; //BCD码缓存
unsigned char Setsiz = 0; //设置位标号
void main()
{
unsigned char psec=0xaa; //秒备份,初值AA确保首次读取时间后会刷新显示
ConfigTimer1(1);
InitDS1302(); //初始化时钟芯片
Start18B20(); //启动一次18B20温度转换,返回值-表示是否启动成功
LineSan(); //行扫描
ColumnSan(); //列扫描
EA = 1; //开总中断
while(1)
{
KeyDriver(); //扫描按键
if(staSystem == E_NORMAL)
{
if(flag200ms==1)
{
flag200ms = 0;
GetRealTime(&bufTime); //获取当前时间
if(psec != bufTime.sec) //检测到时间有变化时刷新显示
{
typeTime = 1;
TimeBcdseparate(); //分解BCD码
TypeConversionroll();
psec = bufTime.sec; //用当前值更新上次秒数
}
}
Spotscanning();
if(flag8s==1)
{
flag8s = 0;
TypeData();
NormallyRefreshTemp();
}
}
else if(staSystem == E_SET_TIME) //时间设置画面
{
if(Setsiz<=6)
{
RefreshTimeSetShow(); //时间设置画面
}
else
{
RefreshDataSetShow();//日期设置画面
}
Spotscanning();
}
}
}
/******************************************************
给按键定义功能
*******************************************************/
void KeyAction(unsigned char keycode)
{
if(keycode == 0x3d) //进入设置与确认功能
{
if(staSystem == E_NORMAL)
{ //在主界面时进入设置界面
staSystem = E_SET_TIME;
Setsiz = 1;
}
else if(staSystem == E_SET_TIME)
{
staSystem = E_NORMAL;
Setsiz = 0;
}
}
if(keycode == 0x2d) //调整设置位
{
if(staSystem == E_SET_TIME)
{
Setsiz++;
if(Setsiz>=12) //Setsiz决定哪个位调整,秒个位为第一位
Setsiz = 1;
}
}
if(keycode == 0x25) //递增一个BCD码
{
IncSetTime();
}
if(keycode == 0x24)
{
ExitTimeSet();
}
}
/*************************************************************
递增时间设置
********************************************************/
void IncSetTime()
{
switch(Setsiz)
{
case 1: bufTime.sec = BcdTimeUp(bufTime.sec,0); break;
case 2: bufTime.sec = BcdTimeUp(bufTime.sec,1); break;
case 3: bufTime.min = BcdTimeUp(bufTime.min,0); break;
case 4: bufTime.min = BcdTimeUp(bufTime.min,1); break;
case 5: bufTime.hour = BcdTimeUp(bufTime.hour,0); break;
case 6: bufTime.hour = BcdTimeUp(bufTime.hour,1); break;
case 7: bufTime.mon = BcdTimeUp(bufTime.mon,1); break;
case 8: bufTime.mon = BcdTimeUp(bufTime.mon,0); break;
case 9: bufTime.day = BcdTimeUp(bufTime.day,1); break;
case 10: bufTime.day = BcdTimeUp(bufTime.day,0); break;
case 11: bufTime.week = BcdWeekUp(bufTime.week); break;
default: break;
}
TimeBcdseparate(); //分解BCD码
}
/******************************************************
退出时间设置状态
*******************************************************/
void ExitTimeSet()
{
Setsiz = 0;
//需保存时即把当前设置时间写入DS1302
DS1302SingleWrite(7,0x00);
SetRealTime(&bufTime);
staSystem = E_NORMAL;
}
/***********************************
函数功能:递增日期与时间一个BCD码
***********************************/
unsigned char BcdTimeUp(unsigned char bcd,bit HL)
{
if(HL==0) //为零时写个位
{
if((bcd&0x0F) >= 0x09)
bcd &= 0xf0;
else
bcd += 0x01;
}
else if(HL==1) //为一时写十位
{
if((bcd&0xf0) >= 0x90)
bcd &= 0x0f;
else
bcd += 0x10;
}
return bcd;
}
/***********************************
函数功能:递增星期一个BCD码
***********************************/
unsigned char BcdWeekUp(unsigned char bcd)
{
if((bcd&0x0F) < 0x06)
bcd += 0x01;
else
bcd &=0xf0;
return bcd;
}
/************************************************************************
时间设置界面显示
***************************************************************************/
void RefreshTimeSetShow()
{
unsigned char i;
for(i=7;i>0;i--)
{
//左一个点阵
if(Setsiz==6)
{
if(flag500ms==0)
UnmberDat[0][i] = bignumber[Timebuf[6]][i]; //小时十位
else if(flag500ms==1)
UnmberDat[0][i] = 0xf0;
}
else
UnmberDat[0][i] = bignumber[Timebuf[6]][i]; //小时十位
if(Setsiz==5)
{
if(flag500ms==0)
{
UnmberDat[0][i] = (UnmberDat[0][i]<<4) | (bignumber[Timebuf[7]][i]>>1); //小时个位
UnmberDat[1][i] = bignumber[Timebuf[7]][i]<<7; //小时个位
}
else if(flag500ms==1)
{
UnmberDat[0][i] = (UnmberDat[0][i]<<4) | 0x00;
UnmberDat[1][i] = 0x00;
}
}
else
{
UnmberDat[0][i] = (UnmberDat[0][i]<<4) | (bignumber[Timebuf[7]][i]>>1); //小时个位
UnmberDat[1][i] = bignumber[Timebuf[7]][i]<<7; //小时个位
}
UnmberDat[0][i] = ~UnmberDat[0][i];
//第二个点阵
UnmberDat[1][i] = UnmberDat[1][i] | (bignumber[10][i]<<3); //隔点
if(Setsiz==4)
{
if(flag500ms==0)
UnmberDat[1][i] = UnmberDat[1][i] | bignumber[Timebuf[8]][i]; // 分十位
else if(flag500ms==1)
UnmberDat[1][i] = UnmberDat[1][i] | 0x00;
}
else
UnmberDat[1][i] = UnmberDat[1][i] | bignumber[Timebuf[8]][i]; // 分十位
UnmberDat[1][i] = ~UnmberDat[1][i];
//第三个点阵
if(Setsiz==3)
{
if(flag500ms==0)
UnmberDat[2][i] = bignumber[Timebuf[9]][i]<<3; //分个位
else if(flag500ms==1)
UnmberDat[2][i] = 0x00;
}
else
UnmberDat[2][i] = bignumber[Timebuf[9]][i]<<3; //分个位
UnmberDat[2][i] = UnmberDat[2][i] | (bignumber[10][i]>>1); //隔点;
UnmberDat[2][i] = ~UnmberDat[2][i];
//第四个点阵
if(Setsiz==2)
{
if(flag500ms==0)
UnmberDat[3][i] = smallnumber[Timebuf[10]][i]<<5; //秒十位
else if(flag500ms==1)
UnmberDat[3][i] = 0x00;
}
else
UnmberDat[3][i] = smallnumber[Timebuf[10]][i]<<5; //秒十位
if(Setsiz==1)
{
if(flag500ms==0)
UnmberDat[3][i] = UnmberDat[3][i] | (smallnumber[Timebuf[11]][i]<<1); //秒个位
else if(flag500ms==1)
UnmberDat[3][i] = UnmberDat[3][i] | 0x00;
}
else
UnmberDat[3][i] = UnmberDat[3][i] | (smallnumber[Timebuf[11]][i]<<1); //秒个位
UnmberDat[3][i] = ~UnmberDat[3][i];
}
}
/******************************************************************
日期设置显示
**********************************************************************/
void RefreshDataSetShow()
{
unsigned char i;
for(i=7;i>0;i--)
{
if(Setsiz==7)
{
if(flag500ms==0)
UnmberDat[0][i] = bignumber[Timebuf[2]][i]; //月十位
else if(flag500ms==1)
UnmberDat[0][i] = 0xf0;
}
else
UnmberDat[0][i] = bignumber[Timebuf[2]][i]; //月十位
if(Setsiz==8)
{
if(flag500ms==0)
{
UnmberDat[0][i] = (UnmberDat[0][i]<<4) | (bignumber[Timebuf[3]][i]>>1); //月个位
UnmberDat[1][i] = bignumber[Timebuf[3]][i]<<7; //月个位
}
else if(flag500ms==1)
{
UnmberDat[0][i] = (UnmberDat[0][i]<<4) | 0x00;
UnmberDat[1][i] = 0x00;
}
}
else
{
UnmberD
![avatar](https://profile-avatar.csdnimg.cn/47e3136d144c4a10bb310f8c19d9cdc8_qq_45072457.jpg!1)
钱的奴隶
- 粉丝: 0
- 资源: 2
最新资源
- AI绘画工具介绍(文档)
- pandas-2.2.2-cp311-cp311-musllinux-1-1-aarch64.whl
- 小程序开发基础与简单示例.pdf
- matlab:读取图像+显示图像+显示图像的直方图+直方图均衡
- pandas-2.2.2-cp311-cp311-manylinux-2-17-x86-64.manylinux2014.whl
- 如何充分运用ansys的HELP
- pandas-2.2.2-cp311-cp311-musllinux-1-1-x86-64.whl
- C语言可变长数组(VLA)详解与应用
- android-studio-2024.1.1.12-windows-zip.zip.001
- 辰光PHP客服系统多商户全开源V3.1版+安装教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)