📄 时钟.c
字号:
}
void timer_1(void) interrupt 1 //中断入口,闪烁
{
TH0=0x3c; //50ms定时
TL0=0xb0;
if(msec++==10) //500ms
{msec=0;a=~a; //闪烁标志反转
if(a==0) //1秒后背光时间减一秒。
LedTime--;
}
}
//根据选择调整相应项目并写入DS1302
void Set(uchar sel,uchar sel_1)
{
uchar address,item;
uchar max,min;
if(sel==1) {address=0x8c; max=99;min=0;} //年
if(sel==2) {address=0x88; max=12;min=1;} //月
if(sel==3) {address=0x86; max=31;min=1;} //日
if(sel==4) {address=0x8a; max=7; min=1;} //星期
if(sel==6) {address=0x84; max=23;min=0;} //小时
if(sel==7) {address=0x82; max=59;min=0;} //分钟
if(sel==8) {address=0x80; max=59;min=0;} //秒
if(sel==10) {address=0xc0; max=59;min=0;} //背光时间,最长1分钟
if(sel==12) {address=0xc2; max=1;min=0;} //闹铃开关寄存器
if(sel==13) {address=0xc4; max=23;min=0;} //闹铃时寄存器
if(sel==14) {address=0xc6; max=59;min=0;} //闹铃分寄存器
item=R1302(address+1)/16*10+R1302(address+1)%16;
if (sel_1==0) item++; else item--;
if(item>max) item=min;
if(item<min) item=max;
W1302(0x8e,0x00); //允许写操作
W1302(address,item/10*16+item%10); //写入DS1302 //转成BCD码
W1302(0x8e,0x80); //写保护,禁止写操作
}
//屏幕显示
void Out_LCM(void)
{ switch(model)
{
case 0: model0(); break;
case 1: model1(); break;
case 2: model2(); break; //在不同的条件下显示不同的字符
case 3: model3(); break;
case 4: model4(); break;
case 5: model5(); break;
case 6: model6(); break;
}
}
/***********************model为零时第一行显示时间,不为零时显示system setup******/
void model0()
{
DisplayListChar(0,0,TIMER); //显示固定字符串(Time)
OutputInformation(13,0,0x20); //不显示
OutputInformation(4,0,0x20); //不显示
OutputInformation(4,1,0x20); //不显示
OutputInformation(15,1,0x20); //不显示
OutputInformation(7,1,0x2f); //显示固定字符 "/"
OutputInformation(10,1,0x2f); //显示固定字符 "/"
OutputInformation(13,1,0x2f); //显示固定字符 "/"
DisplayListChar(0,1,DATE); //显示固定字符串Date(日期)
if(a==1) //冒号闪烁
{OutputInformation(7,0,0x3a); OutputInformation(10,0,0x3a);}
else
{OutputInformation(7,0,0x20); OutputInformation(10,0,0x20);}
/*******************model为零时第二行显示日期,不为零显示设置项目*******/
OutputInformation(5,1,R1302(0x8d)/16+0x30); //显示年
OutputInformation(6,1,R1302(0x8d)%16+0x30);
OutputInformation(8,1,R1302(0x89)/16+0x30); //显示月
OutputInformation(9,1,R1302(0x89)%16+0x30);
OutputInformation(11,1,R1302(0x87)/16+0x30); //显示日
OutputInformation(12,1,R1302(0x87)%16+0x30);
OutputInformation(14,1,R1302(0x8b)%16+0x30); //显示星期
OutputInformation(5,0,R1302(0x85)/16+0x30); //显示小时
OutputInformation(6,0,R1302(0x85)%16+0x30);
OutputInformation(8,0,R1302(0x83)/16+0x30); //显示分钟
OutputInformation(9,0,R1302(0x83)%16+0x30);
OutputInformation(11,0,R1302(0x81)/16+0x30); //显示秒
OutputInformation(12,0,R1302(0x81)%16+0x30);
}
/*************************model不为零时显示系统设置***********************************/
//model为1时time闪烁,按下模式键后进入时间调整
void model1()
/*************************************判断ID的值来显示项目***********************/
{ OutputInformation(0,0,0x20); //不显示
OutputInformation(1,0,0x20);
DisplayListChar(2,0,systemp); //第一行显示system setup
if(id==0) //为0时显示TIME date lalcak
{OutputInformation(9,1,0x20); //不显示
OutputInformation(4,1,0x20); //不显示
OutputInformation(15,1,0x20); //不显示
DisplayListChar(5,1,DATE); //显示date
DisplayListChar(10,1,alarmclock);//显示lalcak
if(a==1)
{OutputInformation(0,1,0x20); //不显示
OutputInformation(1,1,0x20); //不显示
OutputInformation(2,1,0x20); //不显示
OutputInformation(3,1,0x20); //不显示
}
else
DisplayListChar(0,1,TIMER); //显示time
}
else
{ //id不为零进入时间调整项目
OutputInformation(3,1,0x3a); //显示固定字符 ":"
OutputInformation(6,1,0x3a); //显示固定字符 ":"
OutputInformation(9,1,0x20); //不显示
OutputInformation(10,1,0x20); //不显示
OutputInformation(0,1,0x20); //不显示
/****************************时显示闪烁控制********************/
if((id==6)&&(a==1)) //id为5时时闪烁
{
OutputInformation(1,1,0x20); //不显示
OutputInformation(2,1,0x20); //不显示
}
else
{OutputInformation(1,1,R1302(0x85)/16+0x30); //显示时
OutputInformation(2,1,R1302(0x85)%16+0x30);
}
/******************************分显示闪烁控制********************/
if((id==7)&&(a==1)) //id为6时分闪烁
{
OutputInformation(4,1,0x20); //不显示
OutputInformation(5,1,0x20); //不显示
}
else
{OutputInformation(4,1,R1302(0x83)/16+0x30); //显示分
OutputInformation(5,1,R1302(0x83)%16+0x30);
}
/******************************秒显示闪烁控制********************/
if((id==8)&&(a==1)) //id为7时秒闪烁
{
OutputInformation(7,1,0x20); //不显示
OutputInformation(8,1,0x20); //不显示
}
else
{OutputInformation(7,1,R1302(0x81)/16+0x30); //显示秒
OutputInformation(8,1,R1302(0x81)%16+0x30);
}
/*******************************Exit显示闪烁控制********************/
if((id==9)&&(a==1)) //id为8时exit闪烁
{OutputInformation(11,1,0x20); //不显示
OutputInformation(12,1,0x20); //不显示
OutputInformation(13,1,0x20); //不显示
OutputInformation(14,1,0x20); //不显示
}
else
DisplayListChar(11,1,exit); //显示exit
}
}
/***************************************modelo为2时date闪烁***********************************************/
void model2()
{
if(id==0)
{OutputInformation(9,1,0x20); //不显示
OutputInformation(4,1,0x20); //不显示
OutputInformation(15,1,0x20); //不显示
DisplayListChar(0,1,TIMER); //显示time
DisplayListChar(10,1,alarmclock); //显示clock
if(a==1)
{OutputInformation(5,1,0x20); //不显示
OutputInformation(6,1,0x20); //不显示
OutputInformation(7,1,0x20); //不显示
OutputInformation(8,1,0x20); //不显示
}
else
DisplayListChar(5,1,DATE); //显示date
}
/*****************************************************************************************************/
//id不为零时、进入日期调整
/*****************************************************************************************************/
else
{ OutputInformation(0,1,0x20); //不显示
OutputInformation(11,1,0x20); //不显示
OutputInformation(3,1,0x2f); //显示固定字符 "/"
OutputInformation(6,1,0x2f); //显示固定字符 "/"
OutputInformation(9,1,0x2f); //显示固定字符 "/"
/****************************年显示闪烁控制********************/
if((id==1)&&(a==1)) //id为1时年闪烁
{
OutputInformation(1,1,0x20); //不显示
OutputInformation(2,1,0x20); //不显示
}
else
{OutputInformation(1,1,R1302(0x8d)/16+0x30); //显示年
OutputInformation(2,1,R1302(0x8d)%16+0x30);
}
/***************************月闪烁控制************************/
if((id==2)&&(a==1)) //id为2时月闪烁
{
OutputInformation(4,1,0x20); //不显示
OutputInformation(5,1,0x20); //不显示
}
else
{OutputInformation(4,1,R1302(0x89)/16+0x30); //显示月
OutputInformation(5,1,R1302(0x89)%16+0x30);
}
/***************************日闪烁控制************************/
if((id==3)&&(a==1)) //id为2日闪烁
{
OutputInformation(7,1,0x20); //不显示
OutputInformation(8,1,0x20); //不显示
}
else
{OutputInformation(7,1,R1302(0x87)/16+0x30); //显示日
OutputInformation(8,1,R1302(0x87)%16+0x30);
}
/***************************星期闪烁控制*********************************/
if((id==4)&&(a==1)) //id为2时星期闪烁
{
OutputInformation(10,1,0x20); //不显示
}
else
{OutputInformation(10,1,R1302(0x8b)%16+0x30); //显示星期
}
/**************************exit闪烁控制*********************************/
if((id==5)&&(a==1)) //id为5时exit闪烁
{ OutputInformation(12,1,0x20); //不显示
OutputInformation(13,1,0x20); //不显示
OutputInformation(14,1,0x20); //不显示
OutputInformation(15,1,0x20); //不显示
}
else
DisplayListChar(12,1,exit); //显示exit
}
}
/*********************************************************************************/
/*model为3时进入闹铃项目
/**********************************************************************************/
void model3()
{
if(id==0)
{OutputInformation(9,1,0x20); //不显示
OutputInformation(4,1,0x20); //不显示
OutputInformation(15,1,0x20); //不显示
DisplayListChar(0,1,TIMER); //显示time
DisplayListChar(5,1,DATE); //显示date
if(a==1)
{ OutputInformation(10,1,0x20); //不显示
OutputInformation(11,1,0x20); //不显示
OutputInformation(12,1,0x20); //不显示
OutputInformation(13,1,0x20); //不显示
OutputInformation(14,1,0x20);
}
else
DisplayListChar(10,1,alarmclock); //显示cloak
}
/**************************id不为零进入闹铃设置显示********************/
else
{if(id==12) //闹铃开关显示
{DisplayListChar(0,1,ClockSet); //显示ClockSet
OutputInformation(8,1,0x20);
OutputInformation(13,1,0x20);
OutputInformation(14,1,0x20);
/*****************************闹铃开关显示********************************/
if(a==1) //A为闪烁标志
{OutputInformation(10,1,0x20); //不显示
OutputInformation(11,1,0x20); //不显示
OutputInformation(12,1,0x20); //不显示
OutputInformation(13,1,0x20); //不显示
}
else
{
if(R1302(0xc3)%16==0) //闹铃寄存器的值是否为零(关)
{DisplayListChar(10,1,ClockOff);}//显示OFF
else
{OutputInformation(9,1,0x20); //不显示
OutputInformation(12,1,0x20); //不显示
OutputInformation(13,1,0x20); //不显示
OutputInformation(14,1,0x20); //不显示
OutputInformation(15,1,0x20); //不显示
DisplayListChar(10,1,ClockOn); //显示ON
}
}
}
else
{DisplayListChar(0,1,alarmclock); //显示clock
OutputInformation(8,1,0x3a); //显示固定字符 ":"
OutputInformation(5,1,0x20); //不显示
OutputInformation(11,1,0x20); //不显示
/**************************闹铃时闪烁显示**********************/
if((id==13)&&(a==1)) //闹铃时闪烁
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -