写一个闹钟的程序问题
发布网友
发布时间:2022-05-06 19:01
我来回答
共1个回答
热心网友
时间:2023-09-11 15:17
/*********************************************************************************************
函数名:附件函数
调 用:other()
参 数:无
返回值:无
结 果:实现附件自带的其他功能
/**********************************************************************************************/
void other() //调整时间函数:浏览选择显示屏幕界面
{
uchar sel,sel1,ww;
f=ww=1;sel=sel1=1;
if((adj==8)&&(mw==6)) //餐单键,按此键,进入菜单。
{
f=1;sel=1;Beep_set();
v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f();
while(f==1)
{
while(ww==1)
{
setwordbkcolor(1,4,16,1); setwordbkcolor(2,4,16,1);setwordbkcolor(7,4,16,1);setwordbkcolor(8,4,16,1);
v_Lcd12864SendCmd_f( 0x30 ) ; //基本指令集⒈⒉⒊
v_Lcd12864PutString_f(7,0,"");
v_Lcd12864PutString_f(1,0,"⒈遥控解码");
v_Lcd12864PutString_f(1,1,"⒉电子秒表");
v_Lcd12864PutString_f(1,2,"⒊动画播放"); // 图片浏览 电压检测 倒计时钟
v_Lcd12864PutString_f(0,3,"选择 退出");
switch(sel)
{
case 1:setwordbkcolor(3,1,16,1);setwordbkcolor(4,1,16,1);setwordbkcolor(5,1,16,1);setwordbkcolor(6,1,16,1);v_Lcd12864SendCmd_f( 0x30 );v_Lcd12864PutString_f(0,0,"→");break;
case 2:setwordbkcolor(3,2,16,1);setwordbkcolor(4,2,16,1);setwordbkcolor(5,2,16,1);setwordbkcolor(6,2,16,1);v_Lcd12864SendCmd_f( 0x30 );v_Lcd12864PutString_f(0,1,"→");break;
case 3:setwordbkcolor(3,3,16,1);setwordbkcolor(4,3,16,1);setwordbkcolor(5,3,16,1);setwordbkcolor(6,3,16,1);v_Lcd12864SendCmd_f( 0x30 );v_Lcd12864PutString_f(0,2,"→");break;
}
if(irok)
{
irok=0;
if(adj==4) //下移
{
sel++;Beep_key();
if (sel> 3 ){sel=4;ww=2;}
v_Lcd12864ClearRam_f();v_Lcd12864SendCmd_f( 0x01 ) ;
}
if(adj==3)//上移
{
sel--;Beep_key();
if (sel==0 ){sel =6;ww=2;}
v_Lcd12864ClearRam_f();v_Lcd12864SendCmd_f( 0x01 ) ;
}
if((adj==9))//餐单退出键,按此键,返回初始界面。
{
ww = 0;Beep_set();
v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f();
}
}
if((sel==1)&&(adj==7)) //遥控解码
{Beep_key();
v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f();
v_Lcd12864PutString_f(1,0,"红外遥控解码");
v_Lcd12864PutString_f(0,1,"原码: ");
v_Lcd12864PutString_f(4,1,"反码: ");
v_Lcd12864PutString_f(0,2,"用户码1:0x H");
v_Lcd12864PutString_f(0,3,"用户码2:0x H");
while(1)
{
v_Lcd12864SetAddress_f(3,1);
v_Lcd12864SendData_f(num_to_char[IRcode[2]/0x10]);//用户数据码原码显示(十六进制)
v_Lcd12864SendData_f(num_to_char[IRcode[2]%0x10]);
v_Lcd12864SetAddress_f(7,1);
v_Lcd12864SendData_f(num_to_char[IRcode[3]/0x10]);//用户数据码反码显示(十六进制)
v_Lcd12864SendData_f(num_to_char[IRcode[3]%0x10]);
v_Lcd12864SetAddress_f(5,2);
v_Lcd12864SendData_f(num_to_char[IRcode[0]/0x10]);//用户数据码1(十六进制)
v_Lcd12864SendData_f(num_to_char[IRcode[0]%0x10]);
v_Lcd12864SetAddress_f(5,3);
v_Lcd12864SendData_f(num_to_char[IRcode[1]/0x10]);//用户数据码2(十六进制)
v_Lcd12864SendData_f(num_to_char[IRcode[1]%0x10]);
DelayM(50);
if(irok)
{Beep_key();
irok=0;
if((adj==9))//餐单退出键,按此键,返回初始界面。
{
Beep_set();sel1=2;
v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f();
break;
}
}
}
}
while((sel==2)&&(adj==7)) //电子秒表
{Beep_key();
v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f();
TMOD = 0x01;
TH0 = 0x4C;
TL0 = 0x00;
EA = 1;
ET0 = 1;
TR0 = 1;
flag=3;
watch_us=watch_m=watch_s=0;
while(1)
{
/*------------图片时钟秒的处理------------------------*/
LCD16X32display(ZTB,7,watch_us/10); //更新秒的个位
LCD16X32display(ZTB,6,watch_us%10); //更新秒的十位
/*------------图片时钟分的处理------------------------*/
LCD16X32display(ZTB,3,watch_s/10);
LCD16X32display(ZTB,4,watch_s%10);
/*------------图片时钟时的处理------------------------*/
LCD16X32display(ZTB,0,watch_m/10);
LCD16X32display(ZTB,1,watch_m%10);
/*------------图片时钟闪点的处理------------------------*/
v_Lcd12864SendCmd_f(0x30); //基本指令集
v_Lcd12864PutString_f(2,0,"电子秒表");
v_Lcd12864SendCmd_f(0x8a);
v_Lcd12864SendData_f('.');
v_Lcd12864SendCmd_f(0x8d);
v_Lcd12864SendData_f('.');
v_Lcd12864PutString_f(0,3,"开始 存储 退出");
if(irok)
{
irok=0;
if((adj==9))//餐单退出键,按此键,返回初始界面。
{
Beep_set(); flag=1;InitialSound();
v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f();
break;
}
}
}
}
while((sel==3)&&(adj==7)) //铃声选择菜单
{Beep_key();
v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f();
while(1)
{
v_Lcd12864PutString_f(1,1,"3");
if(irok)
{
irok=0;
if((adj==9))//餐单退出键,按此键,返回初始界面。
{
Beep_set();
v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f();
break;
}
}
}
}
}
while(ww==2)
{
setwordbkcolor(1,4,16,1); setwordbkcolor(2,4,16,1);setwordbkcolor(7,4,16,1);setwordbkcolor(8,4,16,1);
v_Lcd12864SendCmd_f( 0x30 ) ; //基本指令集⒈⒉⒊
v_Lcd12864PutString_f(7,0,"");
v_Lcd12864PutString_f(1,0,"⒋图片浏览");
v_Lcd12864PutString_f(1,1,"⒌电压检测");
v_Lcd12864PutString_f(1,2,"⒍系统版本"); // 图片浏览 电压检测 倒计时钟
v_Lcd12864PutString_f(0,3,"选择 退出");
switch(sel)
{
case 4:setwordbkcolor(3,1,16,1);setwordbkcolor(4,1,16,1);setwordbkcolor(5,1,16,1);setwordbkcolor(6,1,16,1);v_Lcd12864SendCmd_f( 0x30 );v_Lcd12864PutString_f(0,0,"→");break;
case 5:setwordbkcolor(3,2,16,1);setwordbkcolor(4,2,16,1);setwordbkcolor(5,2,16,1);setwordbkcolor(6,2,16,1);v_Lcd12864SendCmd_f( 0x30 );v_Lcd12864PutString_f(0,1,"→");break;
case 6:setwordbkcolor(3,3,16,1);setwordbkcolor(4,3,16,1);setwordbkcolor(5,3,16,1);setwordbkcolor(6,3,16,1);v_Lcd12864SendCmd_f( 0x30 );v_Lcd12864PutString_f(0,2,"→");break;
}
if(irok)
{
irok=0;
if(adj==4) //下移
{
sel++;Beep_key();
if (sel> 6 ){sel = 1;ww=1;}
v_Lcd12864ClearRam_f();v_Lcd12864SendCmd_f( 0x01 ) ;
}
if(adj==3)//上移
{
sel--;Beep_key();
if (sel<4 ){sel =3;ww=1;}
v_Lcd12864ClearRam_f();v_Lcd12864SendCmd_f( 0x01 ) ;
}
if((adj==9))//餐单退出键,按此键,返回初始界面。
{
ww = 0;Beep_set();
v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f();
}
}
}
if((adj==9))//餐单退出键,按此键,返回初始界面。
{
f=0;
v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f();
}
}
}
}
void clock() //调整时间函数:浏览选择显示屏幕界面
{
if((adj==8)&&(mw==2)) //餐单键,按此键,进入菜单。
{
f=1;sel=1;Beep_set();
v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f();
v_Lcd12864ClearRam_f();//清除CGRAM ⒈⒉⒊
v_Lcd12864Init_f();
v_Lcd12864PutString_f(2,0,"调整");
v_Lcd12864PutString_f(2,2,"铃声:1");
v_Lcd12864PutString_f(0,1,"闹钟");
v_Lcd12864PutString_f(1,3,"闹钟始终开启");
yidong=4;
clock_num=1;
ms1=read_clock(0xc9);h1=read_clock(0xcb);m1=read_clock(0xcd);cx1=read_clock(0xc1);
while(ww==1)
{
lcm_w_test(0,0x92);
lcm_w_test(1,(clock_num%10)+0x30);
if(clock_num==1)
{
switch(ms1)
{
case 1: v_Lcd12864PutString_f(1,3,"闹钟始终开启");v_Lcd12864SendCmd_f( 0x30 ) ;break; //年1
case 2: v_Lcd12864PutString_f(1,3,"闹钟始终关闭");v_Lcd12864SendCmd_f( 0x30 ) ;break; //月2
case 3: v_Lcd12864PutString_f(1,3,"闹钟仅周日响");v_Lcd12864SendCmd_f( 0x30 ) ;break; //日3
case 4: v_Lcd12864PutString_f(1,3,"响一次后关闭");v_Lcd12864SendCmd_f( 0x30 ) ;break;
case 5: v_Lcd12864PutString_f(1,3,"周一至周五响");v_Lcd12864SendCmd_f( 0x30 ) ;break; //年1
case 6: v_Lcd12864PutString_f(1,3,"周一至周六响");v_Lcd12864SendCmd_f( 0x30 ) ;break; //月2
case 7: v_Lcd12864PutString_f(1,3,"周六和周日响");v_Lcd12864SendCmd_f( 0x30 ) ;break; //日3
}
lcm_w_test(0,0x95);
v_Lcd12864PutString(" ");
lcm_w_test(1,(h1/10)+0x30);
lcm_w_test(1,(h1%10)+0x30);
v_Lcd12864PutString(":");
lcm_w_test(1,(m1/10)+0x30);
lcm_w_test(1,(m1%10)+0x30);
lcm_w_test(0,0x8d);
lcm_w_test(1,(cx1%10)+0x30);
}
switch(yidong)
{
case 1: v_Lcd12864PutString_f(4,0,"小时");setwordbkcolor2(6,2,16,1);setwordbkcolor1(7,2,16,1);v_Lcd12864SendCmd_f( 0x30 );break; //小时
case 2: v_Lcd12864PutString_f(4,0,"分钟");setwordbkcolor(8,2,16,1);v_Lcd12864SendCmd_f( 0x30 );break; //分钟
case 3: v_Lcd12864PutString_f(4,0,"模式");setwordbkcolor(2,4,16,1);setwordbkcolor(3,4,16,1);setwordbkcolor(4,4,16,1);setwordbkcolor(5,4,16,1);setwordbkcolor(6,4,16,1);setwordbkcolor(7,4,16,1);v_Lcd12864SendCmd_f( 0x30 ) ;break; //日3
case 4: v_Lcd12864PutString_f(4,0,"闹钟");setwordbkcolor(3,2,16,1);v_Lcd12864SendCmd_f( 0x30 ) ;break; //星期4
case 5: v_Lcd12864PutString_f(4,0,"铃声");setwordbkcolor2(5,3,16,1);setwordbkcolor1(6,3,16,1);v_Lcd12864SendCmd_f( 0x30 ) ;break; //星期4
}
if(irok)
{
irok=0;
if(adj==6) //餐单右移控制键
{
yidong++;Beep_key();if (yidong> 5 ){yidong = 1;}
v_Lcd12864ClearRam_f();
}
if(adj==5)//餐单左移控制键
{
yidong--;Beep_key();if (yidong==0 ){yidong =5;}
v_Lcd12864ClearRam_f();
}
if((adj==3)&&(yidong==4))//闹钟数量+
{
clock_num++;Beep_key(); if(clock_num>3) clock_num=1;
Writ1302(0xc6,clock_num);
}
if((adj==4)&&(yidong==4))//闹钟数量-
{
clock_num--;Beep_key(); if(clock_num==0) clock_num=3;
Writ1302(0xc6,clock_num);
}
/****************闹钟1**********************************/
clock_num=read_clock(0xc7);
if(clock_num==1)
{
if((adj==3)&&(yidong==1)) //闹钟小时加
{
h1++;Beep_key(); if(h1>23) h1=0;
Writ1302(0xca,h1);
}
if((adj==4)&&(yidong==1))//闹钟小时减
{
h1--;Beep_key(); if(h1==0) h1=23;
Writ1302(0xca,h1);
}
if((adj==3)&&(yidong==2)) //闹钟分钟加
{
m1++;Beep_key(); if(m1>59) m1=0;
Writ1302(0xcc,m1);
}
if((adj==4)&&(yidong==2))//闹钟分钟减
{
m1--;Beep_key(); if(m1==0) m1=59;
Writ1302(0xcc,m1);
}
if((adj==3)&&(yidong==3))//模式变量+
{
ms1++;Beep_key(); if(ms1>7) ms1=1;
Writ1302(0xc8,ms1);
}
if((adj==4)&&(yidong==3))//模式变量-
{
ms1--;Beep_key(); if(ms1==0) ms1=7;
Writ1302(0xc8,ms1);
}
if((adj==3)&&(yidong==5))//铃声变量+
{
cx1++;Beep_key(); if(cx1>6) cx1=1;
Writ1302(0xc0,cx1);
}
if((adj==4)&&(yidong==5))//铃声变量-
{
cx1--;Beep_key(); if(cx1==0) cx1=6;
Writ1302(0xc0,cx1);
}
}
if((adj==9))//餐单退出键,按此键,返回初始界面。
{
ww=0;v_Lcd12864ClearRam_f();//清除CGRAM
v_Lcd12864Init_f(); Beep_set();
}
}
}
}
}
#endif 里面有闹钟模块,更多资料去电子发烧友论坛,我也刚学c