📄 main.c
字号:
PlayRespond(C_SECOND);
}
//********************报时*********************************//
//input:1 ----- 报年、月、日
// 0 ----- 报时、分、秒
//*********************************************************//
void SpeakTime(TimeType)
{
if(TimeType == 0x01)
{
PlayAdjustTime(CON_YEAR); //年
PlayAdjustTime(CON_MONTH); //月
PlayAdjustTime(CON_DAY); //日
}
else
{
PlayRespond(C_BELL); //报时声
PlayRespond(C_NOW); //现在时刻
PlayAdjustTime(CON_HOUR); //时
PlayAdjustTime(CON_MINUTE); //分
}
}
//=============================================================
// 以下为设置LED缓冲区LED_Date和LED_Time的子程序
// 在Calendar_Counter()中被调用
//=============================================================
void LED_ss(){ //Second
unsigned int temp;
temp=ReadRealSecond();
temp=temp & 0x00ff;
LED_Time[4]=temp/10;
LED_Time[5]=temp%10;
}
void LED_mm(){ //Minute
unsigned int temp;
temp=ReadRealHourMin();
temp=temp & 0x00ff;
LED_Time[2]=temp/10;
LED_Time[3]=temp%10;
}
void LED_hh(){ //Hour
unsigned int temp;
temp=ReadRealHourMin();
temp=(temp>>8)&0x00ff;
LED_Time[0]=temp/10;
LED_Time[1]=temp%10;
}
void LED_DD(){ //Day
unsigned int temp;
temp=ReadRealMonthDay();
temp=temp & 0x00ff;
LED_Date[4]=temp/10;
LED_Date[5]=temp%10;
}
void LED_MM(){ //Month
unsigned int temp;
temp=ReadRealMonthDay();
temp=(temp>>8)&0x00ff;
LED_Date[2]=temp/10;
LED_Date[3]=temp%10;
}
void LED_YY(){ //Year
unsigned int temp;
temp=ReadRealYear();
temp %= 100; //2001 to 3099 保留后低两位
LED_Date[0]=temp/10;
LED_Date[1]=temp%10;
}
void Disp_SingleDig(unsigned int i){
int Dig_Now,Seg_Disp,Dig_Sellect=0x0001;
Disp_Pointer = (DateOrTime==0) ? LED_Time : LED_Date; //显示时间或日期
*P_WatchDog_Clear=1; //feed the dog
Dig_Now =(*P_IOB_Buffer)&0xff00; //全灭
*P_IOB_Data = Dig_Now;
Seg_Disp=Disp[Disp_Pointer[i]];
Seg_Disp=Seg_Disp<<8;
Seg_Disp|= ((*P_IOB_Buffer)&0x8000);
*P_IOB_Data=Seg_Disp;
Dig_Now = (Dig_Sellect<<i) |((*P_IOB_Buffer)&0xffc0);
*P_IOB_Data = Dig_Now;
}
//=============================================================
// 函数名称: void Disp_Time()
// 功能描述: 延时并清看门狗
//=============================================================
void LED_Disp(){
Disp_SingleDig(Disp_Dig); //逐位显示
Disp_Dig=(Disp_Dig>=5)?0:Disp_Dig+1; //改变位的计数
}
//***************延时子程序********************************//
//*********************************************************//
void Delay3ms()
{
int delaytemp=0;
for(delaytemp=0;delaytemp<0x06FF;delaytemp++)
*P_WatchDog_Clear=1;
}
//*********************************************************//
//函数:Alarm()
//描述:闹钟报时
//*********************************************************//
void Alarm(){
SpeakTime(0);
}
//*********************************************************//
//函数:main()
//描述:主函数
//*********************************************************//
int main()
{
System_Initial();
while(1)
{
Key_Scan_ServiceLoop(); //键盘扫描
//**********************TRIG/TIME**************************************************//
if(Key==1 && KeyStatus==0 ) //keystate 校时状态还是报时状态,1-----校时;Key=1:S0
{ //按下S0键,初始化
KeyCount=1; //按键计数单元
Key=0;
}
if(Key==0x8001 && KeyStatus==0 ) //按住S0键不放
{
KeyCount++;
Key=0;
}
if (KeyPressFlag==0 && KeyCount>0 ) //松开S0键,报时
{
if(KeyCount<10) //报时
{
YearOrTime=0x0; //报年月日或时分:报时 1----year 0----time
SpeakTime(YearOrTime);
KeyCount=0;
}
else if(KeyCount>=10) //进入调整时间状态
{
KeyCount=0;
KeyStatus=1;
KeyAdjust=0;
TimeCount = 0; //两分钟计时单元
Start256HzRTC();
PlayAdjustTime(KeyAdjust);
}
}
//**********************Display Date Or Time******************************************//
if((Key==2 || Key==4) && KeyStatus==0){
asm ("%0 ^= %1" : "+p" (DateOrTime) : "i"(0x0001)); //将B0位异或
}
//*********************************************************************************//
if(KeyStatus==1) //keystate 校时状态还是报时状态,1-----校时
{
switch(Key)
{
case 1:
KeyAdjust++;
if(KeyAdjust == 5) //KeyAdjust:0-YY 1-MM 2-DD 3-hh 4-mm 5-ss 6-exit
{
KeyStatus=0; KeyAdjust=0;
PlayAdjustTime(CON_YEAR); //年
PlayAdjustTime(CON_MONTH); //月
PlayAdjustTime(CON_DAY); //日
PlayAdjustTime(CON_HOUR); //时
PlayAdjustTime(CON_MINUTE); //分
Stop256HzRTC();
}
else
PlayAdjustTime(KeyAdjust);
Key=0;
TimeCount = 0;
TimeChangeKey=0;
break;
case 2:
Adjust_Time_Up(KeyAdjust);
TimeChangeCount = 0; //调校时间状态下,有键按下,计时器清0
TimeChangeKey=1; //调校时间状态下,有加减键按下标志
TimeCount = 0; //两分钟计时单元
Key=0;
break;
case 4:
Adjust_Time_Down(KeyAdjust);//KeyAdjust:0-YY 1-MM 2-DD 3-hh 4-mm 5-ss 6-exit
TimeChangeCount = 0;
TimeChangeKey=1;
TimeCount = 0; //两分钟计时单元
Key=0;
break;
default:
break;
}
if(TimeChangeKey==1 && TimeChangeCount > 100)//在加减调整之后的多长时间内播放调整后的单项时间语音
{ //TimeChangeKey校时状态下有加减键按下的标志
TimeChangeKey=0;
PlayAdjustTime(KeyAdjust);
}
if(TimeCount > 60) //TimeCount在IRQ5_2Hz里头完成自加,即若在1分钟内无按键,则退出校时状态
{
KeyStatus=0;
KeyAdjust=0;
}
}
//*********************************************************************************//
if(SecondAddOne==0xFFFF) //分加1时,与作息时间比较
{
SecondAddOne=0;
HourMinTemp=ReadRealHourMin();
for(i=0;i<2;i++) //作息时间
if(HourMinTemp==gTimeVSShem[i]){
Alarm(); //打铃
break;
}
HourMinTemp&=0x00ff;
if (HourMinTemp==0) Alarm(); //整点打铃
}
if(SleepFlag == 0x01 && KeyStatus == 0 ) //无键按下,且不处于校时状态时。
SP_GoSleep(); // 进入睡眠模式
}
}
//*****************************主程序结束******************************************//
//*********************************************************************************//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -