这个是主菜单界面
这个是设置时间的子界面
这个是设置日期
设置背景光
闹铃的界面,喇叭出现铃声。
生日倒计时提醒功能。
全部完整的源代码下载:http://www.51hei.com/bbs/dpj-20391-1.html
process.h文件:
/*------------------------------------
名称:菜单处理模块
编写:YuMin_Dong
时间:2013.01.24
------------------------------------*/
#ifndef _PROCESS_H_
#define _PROCESS_H_
bit Menu_Flag;//设置画面显示标志
bit FanHui1;//是否退出主菜单标签
bit Refresh_SetTime; //设置了时间需要刷新显示置位改表现
bit Menu1,Menu2,Menu3,Menu4,Menu5,Menu6,Enter_Menu; //Menu0定义在LCD12864.H中了,因为显示时间函数重复利用了.
//UINT8 MenuKey_Count; //菜单键按下的次数
//UINT8 fen,shi,miao;//秒表功能用
bit Again; //为了静态显示定义该标志,在子菜单下,第一次进入显示一次界面然后在不修改前不会去刷新它
//bit Speaker_Flag; //按键音标志
bit Set_Bright,Set_Speaker; //亮灭背景光和按键音开关选项标志
bit Bell_Flag;
bit Menu1_Flag,Menu2_Flag;
/*------------------------------------
按键控制位定义
------------------------------------*/
sbit KEY_MENU=P3^2; //选择键,调用中断,及时性
sbit KEY_UP=P0^0; //上调
sbit KEY_DOWN=P0^1; //下调
sbit KEY_ENTER=P0^2; //确定
sbit SPEAKER=P2^7; //驱动喇叭位
sbit BRIGHT=P0^7; //背光控制位
[page]
/*------------------------------------
主界面处理
------------------------------------*/
void MainMenu_Pro()
{
if(guide!=guide_old) //箭头位和之前的不同的话证明按键了,刷新显示
{
LCD_RefreshMenu(); //刷新菜单显示
guide_old=guide; //LCD静态显示,不然快速刷屏不好看
LCD_WriteCommand(0x30); //修正回一般指令模式
LCD_WriteCommand(0x82);
LCD_SendString("功能菜单");//菜单标题
}
if(!KEY_DOWN) //
{
DelayMs(10);
if(!KEY_DOWN)
{
TR1=1;
while(!KEY_DOWN)
;
if(guide
TR1=0;
}
}
else if(!KEY_UP)
{
DelayMs(10);
if(!KEY_UP)
{
TR1=1;
while(!KEY_UP)
;
if(guide>0)
guide--;
TR1=0;
}
}
else if(!KEY_ENTER)
{
DelayMs(10);
if(!KEY_ENTER)
{
TR1=1;
while(!KEY_ENTER)
;
switch(guide)
{
case 0: Menu0=1;Enter_Menu=1;break;
case 1: Menu1=1;Enter_Menu=1;break;
case 2: Menu2=1;Enter_Menu=1;break;
case 3: Menu3=1;Enter_Menu=1;break;
case 4: Menu4=1;Enter_Menu=1;break;
case 5: Menu5=1;Enter_Menu=1;break;
case 6: FanHui1=1;Menu_Flag=0;guide=0;
LCD_WriteCommand(0x01);break; //轮询到有enter键,当guide指向返回时候直接去掉FanHui1控制的父菜单循环
default:return;
}
TR1=0;
}
}
}
/*------------------------------------
Menu0设置时间子菜单处理
------------------------------------*/
void Menu0_Pro()
{
UINT8 temp;
if(!Again)
{
LCD_ClearGDRAM();
Set_Hour=1; //第一次进入时候直接显示调小时位
Again=1; //执行一次的标置置高,表明运行到该if条件下不执行下面语句
Refresh_SetTime=1;
LCD_WriteCommand(0x30);
LCD_WriteCommand(0x80);
LCD_SendString("设置时间:");
LCD_WriteCommand(0x98);
LCD_SendString("ENTER 键保存修改");
DS1302_ReadTime();
Second=0;
}
if(Refresh_SetTime) //当调节了刷新显示
{
Refresh_SetTime=0;
Display_Time();
//Display_SetTime();
}
if(!KEY_UP)
{
DelayMs(10);
if(!KEY_UP)
{
TR1=1;
//Refresh_SetTime=1;
while(!KEY_UP);
TR1=0;
if(Set_Hour)
{
temp=Hour/16; //这里需要进行BCD数到十进制数的转换
Hour=Hour%16+temp*10;
if(Hour<23)
Hour++;
else Hour=0;
temp=Hour/10; //转换完以后再转换会BCD数
Hour=Hour%10+temp*16;
//Display_Time();
}
else
{
temp=Minute/16;
Minute=Minute%16+temp*10;
if(Minute<59)
Minute++;
else Minute=0;
temp=Minute/10;
Minute=Minute%10+temp*16;
}
//Display_Time();
Refresh_SetTime=1;
}
}
else if(!KEY_DOWN)
{
DelayMs(10);
if(!KEY_DOWN)
{
TR1=1;
//Refresh_SetTime=1;
while(!KEY_DOWN);
TR1=0;
if(Set_Hour)
{
temp=Hour/16;
Hour=Hour%16+temp*10;
if(Hour>0)
Hour--;
else Hour=23;
temp=Hour/10;
Hour=Hour%10+temp*16;
//Display_Time();
}
else
{
temp=Minute/16;
Minute=Minute%16+temp*10;
if(Minute>0)
Minute--;
else Minute=59;
temp=Minute/10;
Minute=Minute%10+temp*16;
}
//Display_Time();
Refresh_SetTime=1;
}
}
else if(!KEY_ENTER)
{
DelayMs(10);
if(!KEY_ENTER)
{
TR1=1;
while(!KEY_ENTER);
TR1=0;
Enter_Menu=0;
Menu0=0;
guide_old++;
Again=0;
guide=0;
Set_Hour=0;
//Set_Minute=0;
DS1302_WriteTime();
LCD_ClearGDRAM();
}
}
}
/*------------------------------------
Menu1设置日期子菜单处理
------------------------------------*/
void Menu1_Pro()
{
UINT8 temp;
if(!Again)
{
LCD_ClearGDRAM();
Set_Date=0;
Again=1;
Refresh_SetTime=1;
LCD_WriteCommand(0x30);
LCD_WriteCommand(0x80);
LCD_SendString("设置日期:");
LCD_WriteCommand(0x98);
LCD_SendString("ENTER 键保存修改");
DS1302_ReadDate();
}
if(Menu1_Flag) //每次Menu1下最少轮询5个if条件,最7多个if.实验证明,能带得了,效果还行
{
Menu1_Flag=0;
//Refresh_SetTime=1;
Set_Date++;
}
if(Set_Date>2)
Set_Date=0;
if(Refresh_SetTime) //当调节了刷新显示
{
Refresh_SetTime=0;
Display_SetDate();
}
if(!KEY_UP)
{
DelayMs(10);
if(!KEY_UP)
{
TR1=1;
while(!KEY_UP);
TR1=0;
if(Set_Date==0)
{
temp=Year/16;
Year=Year%16+temp*10;
if(Year<99)
Year++;
else Year=0;
temp=Year/10;
Year=Year%10+temp*16;
}
else if(Set_Date==1)
{
temp=Month/16;
Month=Month%16+temp*10;
if(Month<12)
Month++;
else Month=1;
temp=Month/10;
Month=Month%10+temp*16;
}
else if(Set_Date==2)
{
temp=Date/16;
Date=Date%16+temp*10;
if(Date<31)
Date++;
else Date=1;
temp=Date/10;
Date=Date%10+temp*16;
}
Refresh_SetTime=1;
}
}
else if(!KEY_DOWN)
{
DelayMs(10);
if(!KEY_DOWN)
{
TR1=1;
while(!KEY_DOWN);
TR1=0;
if(!Set_Date)
{
temp=Year/16;
Year=Year%16+temp*10;
if(Year>0)
Year--;
else Year=99;
temp=Year/10;
Year=Year%10+temp*16;
}
else if(Set_Date==1)
{
temp=Month/16;
Month=Month%16+temp*10;
if(Month>1)
Month--;
else Month=12;
temp=Month/10;
Month=Month%10+temp*16;
}
else if(Set_Date==2)
{
temp=Date/16;
Date=Date%16+temp*10;
if(Date>1)
Date--;
else Date=31;
temp=Date/10;
Date=Date%10+temp*16;
}
Refresh_SetTime=1;
}
}
else if(!KEY_ENTER)
{
DelayMs(10);
if(!KEY_ENTER)
{
TR1=1;
while(!KEY_ENTER);
TR1=0;
Enter_Menu=0;
Menu1=0;
guide_old++;
Again=0;
//guide=0;
//Set_Hour=0;
//Set_Minute=0;
DS1302_WriteDate();
LCD_ClearGDRAM();
}
}
}
/*------------------------------------
Menu2闹铃功能
------------------------------------*/
void Menu2_Pro()
{
UINT8 temp;
if(!Again)
{
LCD_ClearGDRAM();
Set_Bell=0;
//Set_Hour=1; //第一次进入时候直接显示调小时位
Again=1; //执行一次的标置置高,表明运行到该if条件下不执行下面语句
Refresh_SetTime=1;
LCD_WriteCommand(0x30);
LCD_WriteCommand(0x80);
LCD_SendString("设置闹铃:");
LCD_WriteCommand(0x98);
LCD_SendString(" 开启 关闭");
}
if(Menu2_Flag)
{
Menu2_Flag=0;
Set_Bell++;
Refresh_SetTime=1;
}
if(Set_Bell>3)
Set_Bell=0;
if(Refresh_SetTime) //当调节了刷新显示
{
Refresh_SetTime=0;
Display_Bell();
LCD_WriteCommand(0x30);
LCD_WriteCommand(0x98);
LCD_SendString(" ");
LCD_WriteCommand(0x9d);
LCD_SendString(" ");
if(Set_Bell>1)
{
if(Set_Bell==2)
LCD_WriteCommand(0x98);
else
LCD_WriteCommand(0x9d);
LCD_DisplayCGRAM(1);
}
}
if(!KEY_UP)
{
DelayMs(10);
if(!KEY_UP)
{
TR1=1;
while(!KEY_UP);
TR1=0;
if(Set_Bell==0)
{
if(Bell_Hour<23)
Bell_Hour++;
else Bell_Hour=0;
}
else if(Set_Bell==1)
{
if(Bell_Minute<59)
Bell_Minute++;
else Bell_Minute=0;
}
Refresh_SetTime=1;
}
}
else if(!KEY_DOWN)
{
DelayMs(10);
if(!KEY_DOWN)
{
TR1=1;
while(!KEY_DOWN);
TR1=0;
if(Set_Bell==0)
{
if(Bell_Hour>0)
Bell_Hour--;
else Bell_Hour=23;
}
else if(Set_Bell==1)
{
if(Bell_Minute>0)
Bell_Minute--;
else Bell_Minute=59;
}
Refresh_SetTime=1;
}
}
else if(!KEY_ENTER)
{
DelayMs(10);
if(!KEY_ENTER)
{
TR1=1;
while(!KEY_ENTER);
TR1=0;
Enter_Menu=0;
Menu2=0;
guide_old++;
Again=0;
//将闹钟时转换BCD以方便和ds1302读出的数据比较
temp=Bell_Hour/10; Bell_Hour=Bell_Hour%10+temp*16;
temp=Bell_Minute/10; Bell_Minute=Bell_Minute%10+temp*16;
if(Set_Bell==2)
Bell_Flag=1;
else Bell_Flag=0;
LCD_ClearGDRAM();
}
}
}
/*------------------------------------
Menu3背光功能
------------------------------------*/
void Menu3_Pro()
{
if(!Again)
{
LCD_ClearGDRAM(); //LCD清屏幕
Again=1; //表明这个分支每次进入者只执行一次
//Set_Bright=0;
Refresh_SetTime=1;
LCD_WriteCommand(0x30);
LCD_WriteCommand(0x80);
LCD_SendString("背景光开关设置:");
LCD_WriteCommand(0x90);
LCD_SendString(" 开 关");
LCD_WriteCommand(0x98);
LCD_SendString("ENTER 键保存修改");
}
if(Refresh_SetTime) //当调节了刷新显示
{
Refresh_SetTime=0;
if(Set_Bright)
{
LCD_WriteCommand(0x94);
LCD_DisplayCGRAM(1);
LCD_WriteCommand(0x90);
LCD_SendString(" ");
}
else
{
LCD_WriteCommand(0x90);
LCD_DisplayCGRAM(1);
LCD_WriteCommand(0x94);
LCD_SendString(" ");
}
}
if(!KEY_ENTER)
{
DelayMs(10);
if(!KEY_ENTER)
{
TR1=1;
while(!KEY_ENTER);
TR1=0;
if(Set_Bright) BRIGHT=0;
else BRIGHT=1;
Enter_Menu=0;
Menu3=0;
guide_old++;
Again=0;
LCD_ClearGDRAM();
}
}
}
/*------------------------------------
Menu4按键音功能
------------------------------------*/
void Menu4_Pro()
{
if(!Again)
{
LCD_ClearGDRAM();
Again=1;
//Set_Speaker=0;
Refresh_SetTime=1;
LCD_WriteCommand(0x30);
LCD_WriteCommand(0x80);
LCD_SendString("按键音开关设置:");
LCD_WriteCommand(0x90);
LCD_SendString(" 开 关");
LCD_WriteCommand(0x98);
LCD_SendString("ENTER 键保存修改");
}
if(Refresh_SetTime) //当调节了刷新显示
{
Refresh_SetTime=0;
if(Set_Speaker)
{
LCD_WriteCommand(0x94);
LCD_DisplayCGRAM(1);
LCD_WriteCommand(0x90);
LCD_SendString(" ");
}
else
{
LCD_WriteCommand(0x90);
LCD_DisplayCGRAM(1);
LCD_WriteCommand(0x94);
LCD_SendString(" ");
}
}
if(!KEY_ENTER)
{
DelayMs(10);
if(!KEY_ENTER)
{
TR1=1;
while(!KEY_ENTER);
TR1=0;
if(Set_Speaker) ET1=0;
else ET1=1;
Enter_Menu=0;
Menu4=0;
guide_old++;
Again=0;
//guide=0;
LCD_ClearGDRAM();
}
}
}
/*------------------------------------
Menu5生日提醒功能
------------------------------------*/
void Menu5_Pro()
{
UINT16 temp;
LCD_ClearGDRAM();
LCD_WriteCommand(0x30);
LCD_WriteCommand(0x80);
LCD_SendString("距我生日还有:");
LCD_WriteCommand(0x88);
LCD_SendString("距洋洋生日还有:");
temp=Month/16;
Month=Month%16+temp*10;
temp=Date/16;
Date=Date%16+temp*10;
switch(Month)
{
case 1: temp=249-Date;break;
case 2: temp=218-Date;break;
case 3: temp=190-Date;break;
case 4: temp=159-Date;break;
case 5: temp=129-Date;break;
case 6: temp=98-Date;break;
case 7: temp=67-Date;break;
case 8: temp=37-Date;break;
case 9: if(Date<=6) temp=6-Date;
else temp=365-30+Date;break;
case 10:temp=(31-Date)+334;break;
case 12:temp=(30-Date)+304;break;
default: return;
}
if(!(Year%0x4))
temp+=1;
LCD_WriteCommand(0x06);
LCD_WriteCommand(0x90);
LCD_WriteData(temp/100|0x30);
LCD_WriteData(temp%100/10|0x30);
LCD_WriteData(temp%10|0x30);
temp+=12;
LCD_WriteCommand(0x98);
LCD_WriteData(temp/100|0x30);
LCD_WriteData(temp%100/10|0x30);
LCD_WriteData(temp%10|0x30);
LCD_WriteCommand(0x93);
LCD_SendString("天");
LCD_WriteCommand(0x9b);
LCD_SendString("天");
while(Menu5)
{
if(!KEY_ENTER)
{
DelayMs(10);
if(!KEY_ENTER)
{
TR1=1;
while(!KEY_ENTER);
TR1=0;
Menu5=0;
LCD_ClearGDRAM();
Enter_Menu=0;
guide_old++;
}
}
}
DS1302_ReadDate();
}
#endif
上一篇:单片机驱动ds18b20用12864液晶显示温度程序
下一篇:旋转LED灯原理和应用
推荐阅读最新更新时间:2024-03-16 14:05
- 热门资源推荐
- 热门放大器推荐
设计资源 培训 开发板 精华推荐
- 有奖直播:安森美光伏和储能产品介绍
- 分分钟完成电子设计的奥秘—2015WEBENCH邀你共同见证!
- 【白皮书免费下载】施耐德电气三宝典:智能配电、关键电源,全生命周期服务
- ADI有奖下载之电磁流量计解决方案
- TE Connectivity的智能建筑解决方案——传感和连接,智能楼宇设计的关键
- 为“ADI实验室电路”寻建议!
- 理想中的开发板、万用表,好用不贵? e络盟11.11抢购,给你机会!
- 下载《ADI 任意波形发生器方案》抢楼有礼啦!
- 留下你的点评,是德科技信号分析仪,精美礼品等你拿!
- Littelfuse【智能家居的电路保护方案】在线研讨会 11月22日10点 强势登场!预报名、参与研讨会赢好礼!