📄 51
字号:
C51 COMPILER V8.18 DA1302 12/15/2009 15:11:35 PAGE 5
242 1 while(model==1) //model为1时进入时间调整
243 1 {
244 2 b=1;
245 2 Modset();
246 2 if(b==0)
247 2 {KeySound(); //蜂鸣声
248 3 if(id++==9) //6..9为时分秒调。 .
249 3 id=6;
250 3 }
251 2 id_case1_key(); //调用按键处理
252 2 Out_LCM(); //显示输出
253 2 }
254 1 }
255 void datesetup() //对日期进行调整
256 {
257 1 id=1;
258 1 while(model==2) //model为2时进入日期调整
259 1 {b=1;
260 2 Modset(); //模式键是否动作
261 2 if(b==0)
262 2 {KeySound(); //蜂鸣声
263 3 if(id++==5) //1..5为年月日星期 exit
264 3 id=1;
265 3 }
266 2 id_case1_key(); //日期调整
267 2 Out_LCM(); //显示输出
268 2 }
269 1 }
270 void alarmclockset(void) //闹铃调整
271 {id=12;
272 1 while(model==3) //进入闹铃设置
273 1 {b=1;
274 2 Modset(); //模式键是否动作
275 2 if(b==0)
276 2 {KeySound(); //蜂鸣声
277 3 if(R1302(0xc3)%16==0)
278 3 {id=0;model++;} //0xc2为闹铃开关寄存器。当为关时按下模式键时将退出闹铃设置,当开时进入闹铃时
-间设置
279 3
280 3 else if(id++==15) //12..15为闹铃开关和时间设置 exit
281 3 id=12;
282 3 }
283 2 id_case1_key(); //调整
284 2 Out_LCM(); //显示输出
285 2 }
286 1 }
287
288 void lampsetup(void) //背光灯时间设置
289 {id=10; //背光灯存储空间DS1302(0xc0)
290 1 while(model==4) //model为3时进入背光灯调整
291 1 {b=1;
292 2 Modset(); //模式键是否动作
293 2 if(b==0)
294 2 {KeySound(); //蜂鸣声
295 3 if(id++==11) //10为背光灯 exit
296 3 id=10;
297 3 }
298 2 id_case1_key();
299 2 Out_LCM(); //显示输出
300 2 }
301 1
302 1 }
C51 COMPILER V8.18 DA1302 12/15/2009 15:11:35 PAGE 6
303 void timereset() //时间清零
304 {
305 1 Set1302(inittime); //清时间
306 1 W1302(0x90,0xa5); //打开充电二级管 一个二级管串联一个2K电阻
307 1 model++;
308 1 }
309 //对相应的项目进行加、减调整。
310 void id_case1_key() //按键处理
311 {
312 1 if (TimerUp==0) //增加
313 1 {
314 2 Delay5Ms();
315 2 if(TimerUp==0)
316 2 {a=0;msec=0;KeySound(); //蜂鸣声
317 3 if((id==9)||(id==5)||(id==11)||(id==15)) //当ID为9、5时按下加、减键将退出调整
318 3 { model++; //退出时间、日期设置
319 4 id=0;
320 4 }
321 3 else
322 3 Set(id,1);
323 3 }
324 2 while(TimerUp==0);
325 2 }
326 1 if (TimerDown==0) //减少
327 1 {
328 2 Delay5Ms();
329 2 if(TimerDown==0)
330 2 {a=0;msec=0;KeySound(); //蜂鸣声
331 3 if((id==9)||(id==5)||(id==11)||(id==15)) //当ID为9、5时按下加、减键将退出调整
332 3 { model++; //退出时间、日期设置
333 4 id=0;
334 4 }
335 3 else
336 3 Set(id,0); //调用DS1302写入函数
337 3 }
338 2 while(TimerDown==0);
339 2 }
340 1 }
341
342 void timer_1(void) interrupt 1 //中断入口,闪烁
343 {
344 1 TH0=0x3c; //50ms定时
345 1 TL0=0xb0;
346 1 if(msec++==10) //500ms
347 1 {msec=0;a=~a; //闪烁标志反转
348 2 if(a==0) //1秒后背光时间减一秒。
349 2 LedTime--;
350 2 }
351 1 }
352
353 //根据选择调整相应项目并写入DS1302
354 void Set(uchar sel,uchar sel_1)
355 {
356 1 uchar address,item;
357 1 uchar max,min;
358 1 if(sel==1) {address=0x8c; max=99;min=0;} //年
359 1 if(sel==2) {address=0x88; max=12;min=1;} //月
360 1 if(sel==3) {address=0x86; max=31;min=1;} //日
361 1 if(sel==4) {address=0x8a; max=7; min=1;} //星期
362 1 if(sel==6) {address=0x84; max=23;min=0;} //小时
363 1 if(sel==7) {address=0x82; max=59;min=0;} //分钟
364 1 if(sel==8) {address=0x80; max=59;min=0;} //秒
C51 COMPILER V8.18 DA1302 12/15/2009 15:11:35 PAGE 7
365 1 if(sel==10) {address=0xc0; max=59;min=0;} //背光时间,最长1分钟
366 1 if(sel==12) {address=0xc2; max=1;min=0;} //闹铃开关寄存器
367 1 if(sel==13) {address=0xc4; max=23;min=0;} //闹铃时寄存器
368 1 if(sel==14) {address=0xc6; max=59;min=0;} //闹铃分寄存器
369 1
370 1
371 1 item=R1302(address+1)/16*10+R1302(address+1)%16;
372 1 if (sel_1==0) item++; else item--;
373 1 if(item>max) item=min;
374 1 if(item<min) item=max;
375 1
376 1 W1302(0x8e,0x00); //允许写操作
377 1 W1302(address,item/10*16+item%10); //写入DS1302 //转成BCD码
378 1 W1302(0x8e,0x80); //写保护,禁止写操作
379 1 }
380
381 //屏幕显示
382 void Out_LCM(void)
383 { switch(model)
384 1 {
385 2 case 0: model0(); break;
386 2 case 1: model1(); break;
387 2 case 2: model2(); break; //在不同的条件下显示不同的字符
388 2 case 3: model3(); break;
389 2 case 4: model4(); break;
390 2 case 5: model5(); break;
391 2 case 6: model6(); break;
392 2 }
393 1 }
394
395 /***********************model为零时第一行显示时间,不为零时显示system setup******/
396 void model0()
397 {
398 1 DisplayListChar(0,0,TIMER); //显示固定字符串(Time)
399 1 OutputInformation(13,0,0x20); //不显示
400 1 OutputInformation(4,0,0x20); //不显示
401 1 OutputInformation(4,1,0x20); //不显示
402 1 OutputInformation(15,1,0x20); //不显示
403 1 OutputInformation(7,1,0x2f); //显示固定字符 "/"
404 1 OutputInformation(10,1,0x2f); //显示固定字符 "/"
405 1 OutputInformation(13,1,0x2f); //显示固定字符 "/"
406 1 DisplayListChar(0,1,DATE); //显示固定字符串Date(日期)
407 1 if(a==1) //冒号闪烁
408 1 {OutputInformation(7,0,0x3a); OutputInformation(10,0,0x3a);}
409 1 else
410 1 {OutputInformation(7,0,0x20); OutputInformation(10,0,0x20);}
411 1
412 1 /*******************model为零时第二行显示日期,不为零显示设置项目*******/
413 1
414 1 OutputInformation(5,1,R1302(0x8d)/16+0x30); //显示年
415 1 OutputInformation(6,1,R1302(0x8d)%16+0x30);
416 1
417 1 OutputInformation(8,1,R1302(0x89)/16+0x30); //显示月
418 1 OutputInformation(9,1,R1302(0x89)%16+0x30);
419 1
420 1 OutputInformation(11,1,R1302(0x87)/16+0x30); //显示日
421 1 OutputInformation(12,1,R1302(0x87)%16+0x30);
422 1
423 1 OutputInformation(14,1,R1302(0x8b)%16+0x30); //显示星期
424 1
425 1 OutputInformation(5,0,R1302(0x85)/16+0x30); //显示小时
426 1 OutputInformation(6,0,R1302(0x85)%16+0x30);
C51 COMPILER V8.18 DA1302 12/15/2009 15:11:35 PAGE 8
427 1
428 1 OutputInformation(8,0,R1302(0x83)/16+0x30); //显示分钟
429 1 OutputInformation(9,0,R1302(0x83)%16+0x30);
430 1
431 1 OutputInformation(11,0,R1302(0x81)/16+0x30); //显示秒
432 1 OutputInformation(12,0,R1302(0x81)%16+0x30);
433 1 }
434
435 /*************************model不为零时显示系统设置***********************************/
436
437
438
439 //model为1时time闪烁,按下模式键后进入时间调整
440 void model1()
441 /*************************************判断ID的值来显示项目***********************/
442 { OutputInformation(0,0,0x20); //不显示
443 1 OutputInformation(1,0,0x20);
444 1 DisplayListChar(2,0,systemp); //第一行显示system setup
445 1 if(id==0) //为0时显示TIME date lalcak
446 1 {OutputInformation(9,1,0x20); //不显示
447 2 OutputInformation(4,1,0x20); //不显示
448 2 OutputInformation(15,1,0x20); //不显示
449 2 DisplayListChar(5,1,DATE); //显示date
450 2 DisplayListChar(10,1,alarmclock);//显示lalcak
451 2
452 2 if(a==1)
453 2 {OutputInformation(0,1,0x20); //不显示
454 3 OutputInformation(1,1,0x20); //不显示
455 3 OutputInformation(2,1,0x20); //不显示
456 3 OutputInformation(3,1,0x20); //不显示
457 3 }
458 2 else
459 2 DisplayListChar(0,1,TIMER); //显示time
460 2 }
461 1 else
462 1 { //id不为零进入时间调整项目
463 2 OutputInformation(3,1,0x3a); //显示固定字符 ":"
464 2 OutputInformation(6,1,0x3a); //显示固定字符 ":"
465 2 OutputInformation(9,1,0x20); //不显示
466 2 OutputInformation(10,1,0x20); //不显示
467 2 OutputInformation(0,1,0x20); //不显示
468 2 /****************************时显示闪烁控制********************/
469 2 if((id==6)&&(a==1)) //id为5时时闪烁
470 2 {
471 3 OutputInformation(1,1,0x20); //不显示
472 3 OutputInformation(2,1,0x20); //不显示
473 3 }
474 2 else
475 2 {OutputInformation(1,1,R1302(0x85)/16+0x30); //显示时
476 3 OutputInformation(2,1,R1302(0x85)%16+0x30);
477 3 }
478 2 /******************************分显示闪烁控制********************/
479 2 if((id==7)&&(a==1)) //id为6时分闪烁
480 2 {
481 3 OutputInformation(4,1,0x20); //不显示
482 3 OutputInformation(5,1,0x20); //不显示
483 3 }
484 2 else
485 2 {OutputInformation(4,1,R1302(0x83)/16+0x30); //显示分
486 3 OutputInformation(5,1,R1302(0x83)%16+0x30);
487 3 }
488 2 /******************************秒显示闪烁控制********************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -