当前位置:   article > 正文

可编程作息时间控制器设计

作息时间控制器

利用单片机AT89C51设计可编程族系时间控制器,能按照给定时间模拟控制,实现打铃、灯光控制。

创新:显示时间和日期;有音乐背景等。

任务区分:

A——早晨起床、上午上课准备、下午上课准备、晚上熄灯准备播放不同的音乐。

B——早晨起床、上午上课准备、下午上课准备、晚上熄灯准备在显示屏上文字提示。

主程序:

  1. #include <reg51.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. sbit key1=P1^0;
  5. sbit key2=P1^1;
  6. sbit key3=P1^2;
  7. sbit rs=P2^0;
  8. sbit rw=P2^1;
  9. sbit en=P2^2;
  10. sbit light=P2^6;
  11. sbit sound=P2^7;
  12. int a,b,i,j,min,hour,minge,minshi,hourge,hourshi,sec=0,secge,secshi,cnt,cnt1,nian=2022,yue=11,ri=19;
  13. int xdata
  14. amin1=00,ahour1=6,aminge1,aminshi1,ahourge1,ahourshi1,
  15. amin2=45,ahour2=6,aminge2,aminshi2,ahourge2,ahourshi2,
  16. amin3=45,ahour3=7,aminge3,aminshi3,ahourge3,ahourshi3,
  17. amin4=00,ahour4=10,aminge4,aminshi4,ahourge4,ahourshi4,
  18. amin5=00,ahour5=12,aminge5,aminshi5,ahourge5,ahourshi5,
  19. amin6=15,ahour6=14,aminge6,aminshi6,ahourge6,ahourshi6,
  20. amin7=30,ahour7=14,aminge7,aminshi7,ahourge7,ahourshi7,
  21. amin8=00,ahour8=21,aminge8,aminshi8,ahourge8,ahourshi8,
  22. amin9=30,ahour9=21,aminge9,aminshi9,ahourge9,ahourshi9;
  23. uchar code table1[]={'0','1','2','3','4','5','6','7','8','9'};
  24. uchar code table2[]={"Time:00:00"};
  25. uchar xdata tips[]={"Tips:"};
  26. uchar xdata Date[]={"Date:"};
  27. uchar xdata clock_0[]={" "};
  28. uchar xdata clock_1[]={"clock:06:00"};
  29. uchar xdata clock_2[]={"clock:06:45"};
  30. uchar xdata clock_3[]={"clock:07:45"};
  31. uchar xdata clock_4[]={"clock:10:00"};
  32. uchar xdata clock_5[]={"clock:12:00"};
  33. uchar xdata clock_6[]={"clock:14:15"};
  34. uchar xdata clock_7[]={"clock:14:30"};
  35. uchar xdata clock_8[]={"clock:21:00"};
  36. uchar xdata clock_9[]={"clock:21:30"};
  37. uchar xdata qc[]={"ZCQC"};
  38. uchar xdata sk1[]={"SWSK"};
  39. uchar xdata sk2[]={"XWSK"};
  40. uchar xdata xd[]={"XDJQ"};
  41. uchar xdata rest[]={"Rest"};
  42. uchar xdata clock[]={"CLOCK"};
  43. uchar xdata riqi[]={"2022-11-19"};
  44. void delay(unsigned int z)
  45. {
  46. uint i,j;
  47. for(i=z;i>0;i--)
  48. for(j=110;j>0;j--);
  49. }
  50. void write_com(uchar com)
  51. {
  52. en=0;
  53. rw=0;
  54. rs=0;
  55. P0=com;
  56. en=1;
  57. delay(5);
  58. en=0;
  59. }
  60. void write_data(uchar date)
  61. {
  62. en=0;
  63. rw=0;
  64. rs=1;
  65. P0=date;
  66. en=1;
  67. delay(5);
  68. en=0;
  69. }
  70. void write_nian(uchar add,uint date)
  71. {
  72. uchar qian,bai,shi,ge;
  73. qian=date/1000;
  74. bai=(date-qian*1000)/100;
  75. shi=(date-qian*1000-bai*100)/10;
  76. ge=date%10;
  77. write_com(0x80+0x40+add);
  78. write_data(table1[qian]);
  79. write_data(table1[bai]);
  80. write_data(table1[shi]);
  81. write_data(table1[ge]);
  82. }
  83. void write_yue(uchar add,uint date)
  84. {
  85. uchar shi,ge;
  86. shi=date/10;
  87. ge=date%10;
  88. write_com(0x80+0x40+add);
  89. write_data(0x30+shi);
  90. write_data(0x30+ge);
  91. }
  92. void write_ri(uchar add,uint date)
  93. {
  94. uchar shi,ge;
  95. shi=date/10;
  96. ge=date%10;
  97. write_com(0x80+0x40+add);
  98. write_data(0x30+shi);
  99. write_data(0x30+ge);
  100. }
  101. void qi()
  102. {
  103. write_com(0x80+0x40+0);
  104. for(i=0;i<5;i++)
  105. write_data(Date[i]);
  106. write_nian(5,nian);
  107. write_yue(10,yue);
  108. write_ri(13,ri);
  109. write_com(0x80+0x40+12);
  110. write_data('-');
  111. write_com(0x80+0x40+9);
  112. write_data('-');
  113. }
  114. void tip()
  115. {
  116. if(hour>=0&&hour<5)
  117. {
  118. write_com(0x80+20+5);
  119. for(i=0;i<4;i++)
  120. write_data(xd[i]);
  121. }
  122. else
  123. if(hour>=5&&hour<7)
  124. {
  125. write_com(0x80+20+5);
  126. for(i=0;i<4;i++)
  127. write_data(qc[i]);
  128. }
  129. else
  130. if(hour>=7&&hour<12)
  131. {
  132. write_com(0x80+20+5);
  133. for(i=0;i<4;i++)
  134. write_data(sk1[i]);
  135. }
  136. else
  137. if(hour>=12&&hour<14)
  138. {
  139. write_com(0x80+20+5);
  140. for(i=0;i<4;i++)
  141. write_data(rest[i]);
  142. }
  143. else
  144. if(hour>=14&&hour<18)
  145. {
  146. write_com(0x80+20+5);
  147. for(i=0;i<4;i++)
  148. write_data(sk2[i]);
  149. }
  150. else
  151. if(hour>=18&&hour<24)
  152. {
  153. write_com(0x80+20+5);
  154. for(i=0;i<4;i++)
  155. write_data(xd[i]);
  156. }
  157. }
  158. void show()
  159. {
  160. if(ahour1==hour&&amin1==min)
  161. {
  162. tip();
  163. }
  164. else
  165. if(ahour2==hour&&amin2==min)
  166. {
  167. tip();
  168. }
  169. else
  170. if(ahour3==hour&&amin3==min)
  171. {
  172. tip();
  173. }
  174. else
  175. if(ahour4==hour&&amin4==min)
  176. {
  177. tip();
  178. }
  179. else
  180. if(ahour5==hour&&amin5==min)
  181. {
  182. tip();
  183. }
  184. else
  185. if(ahour6==hour&&amin6==min)
  186. {
  187. tip();
  188. }
  189. else
  190. if(ahour7==hour&&amin7==min)
  191. {
  192. tip();
  193. }
  194. else
  195. if(ahour8==hour&&amin8==min)
  196. {
  197. tip();
  198. }
  199. else
  200. if(ahour9==hour&&amin9==min)
  201. {
  202. write_com(0x80+20+5);
  203. for(i=0;i<11;i++)
  204. write_data(clock_9[i]);
  205. }
  206. else
  207. write_com(0x80+20+5);
  208. for(i=0;i<11;i++)
  209. write_data(clock_0[i]);
  210. }
  211. void time()
  212. {
  213. while(1)
  214. {
  215. if(key1==0)
  216. {
  217. if(key1==0)
  218. {
  219. if(hour==23)
  220. hour=0;
  221. else
  222. hour++;
  223. hourge=hour%10;
  224. hourshi=hour/10;
  225. write_com(0x0f);
  226. delay(2);
  227. write_com(0x80+6);
  228. write_data(table1[hourge]);
  229. delay(5);
  230. write_com(0x80+5);
  231. delay(2);
  232. write_data(table1[hourshi]);
  233. while(!key1);
  234. }
  235. }
  236. if(key2==0)
  237. {
  238. delay(10);
  239. if(key2==0)
  240. {
  241. if(min==59)
  242. min=0;
  243. else
  244. min++;
  245. minge=min%10;
  246. minshi=min/10;
  247. write_com(0x0f);
  248. write_com(0x80+9);
  249. write_data(table1[minge]);
  250. delay(1);
  251. write_com(0x80+8);
  252. write_data(table1[minshi]);
  253. delay(1);
  254. while(!key2);
  255. }
  256. }
  257. if(key3==0)
  258. {
  259. delay(10);
  260. if(key3==0)
  261. {
  262. write_com(0x0c);
  263. TR1=1;
  264. while(!key3);
  265. break;
  266. }
  267. }
  268. }
  269. }
  270. void display1()//set clock time 1
  271. {
  272. while(1)
  273. {
  274. if(key1==0)
  275. {
  276. delay(10);
  277. if(key1==0)
  278. {
  279. if(ahour1==23)
  280. ahour1=0;
  281. else
  282. ahour1++;
  283. ahourge1=ahour1%10;
  284. ahourshi1=ahour1/10;
  285. write_com(0x0f);
  286. write_com(0x80+0x40+8);
  287. write_data(':');
  288. write_com(0x80+0x40+7);
  289. write_data(table1[ahourge1]);
  290. delay(1);
  291. write_com(0x80+0x40+6);
  292. write_data(table1[ahourshi1]);
  293. delay(1);
  294. while(!key1);
  295. }
  296. }
  297. if(key2==0)
  298. {
  299. delay(10);
  300. if(key2==0)
  301. {
  302. if(amin1==59)
  303. amin1=0;
  304. else
  305. amin1++;
  306. aminge1=amin1%10;
  307. aminshi1=amin1/10;
  308. write_com(0x0f);
  309. write_com(0x80+0x40+10);
  310. write_data(table1[aminge1]);
  311. delay(1);
  312. write_com(0x80+0x40+9);
  313. write_data(table1[aminshi1]);
  314. delay(1);
  315. while(!key2);
  316. }
  317. }
  318. if(key3==0)
  319. {
  320. write_com(0x0c);
  321. write_com(0x80+0x40+0);
  322. for(i=0;i<5;i++)
  323. write_data(Date[i]);
  324. write_com(0x80+0x40+5);
  325. for(i=0;i<11;i++)
  326. write_data(riqi[i]);
  327. while(!key3);
  328. break;
  329. }
  330. }
  331. }
  332. void display2()//set clock time 2
  333. {
  334. while(1)
  335. {
  336. if(key1==0)
  337. {
  338. delay(10);
  339. if(key1==0)
  340. {
  341. if(ahour2==23)
  342. ahour2=0;
  343. else
  344. ahour2++;
  345. ahourge2=ahour2%10;
  346. ahourshi2=ahour2/10;
  347. write_com(0x0f);
  348. write_com(0x80+0x40+8);
  349. write_data(':');
  350. write_com(0x80+0x40+7);
  351. write_data(table1[ahourge2]);
  352. delay(1);
  353. write_com(0x80+0x40+6);
  354. write_data(table1[ahourshi2]);
  355. delay(1);
  356. while(!key1);
  357. }
  358. }
  359. if(key2==0)
  360. {
  361. delay(10);
  362. if(key2==0)
  363. {
  364. if(amin2==59)
  365. amin2=0;
  366. else
  367. amin2++;
  368. aminge2=amin2%10;
  369. aminshi2=amin2/10;
  370. write_com(0x0f);
  371. write_com(0x80+0x40+10);
  372. write_data(table1[aminge2]);
  373. delay(1);
  374. write_com(0x80+0x40+9);
  375. write_data(table1[aminshi2]);
  376. delay(1);
  377. while(!key2);
  378. }
  379. }
  380. if(key3==0)
  381. {
  382. write_com(0x0c);
  383. write_com(0x80+0x40+0);
  384. for(i=0;i<5;i++)
  385. write_data(Date[i]);
  386. write_com(0x80+0x40+5);
  387. for(i=0;i<11;i++)
  388. write_data(riqi[i]);
  389. while(!key3);
  390. break;
  391. }
  392. }
  393. }
  394. void display3()//set clock time 3
  395. {
  396. while(1)
  397. {
  398. if(key1==0)
  399. {
  400. delay(10);
  401. if(key1==0)
  402. {
  403. if(ahour3==23)
  404. ahour3=0;
  405. else
  406. ahour3++;
  407. ahourge3=ahour3%10;
  408. ahourshi3=ahour3/10;
  409. write_com(0x0f);
  410. write_com(0x80+0x40+8);
  411. write_data(':');
  412. write_com(0x80+0x40+7);
  413. write_data(table1[ahourge3]);
  414. delay(1);
  415. write_com(0x80+0x40+6);
  416. write_data(table1[ahourshi3]);
  417. delay(1);
  418. while(!key1);
  419. }
  420. }
  421. if(key2==0)
  422. {
  423. delay(10);
  424. if(key2==0)
  425. {
  426. if(amin3==59)
  427. amin3=0;
  428. else
  429. amin3++;
  430. aminge3=amin3%10;
  431. aminshi3=amin3/10;
  432. write_com(0x0f);
  433. write_com(0x80+0x40+10);
  434. write_data(table1[aminge3]);
  435. delay(1);
  436. write_com(0x80+0x40+9);
  437. write_data(table1[aminshi3]);
  438. delay(1);
  439. while(!key2);
  440. }
  441. }
  442. if(key3==0)
  443. {
  444. write_com(0x0c);
  445. write_com(0x80+0x40+0);
  446. for(i=0;i<5;i++)
  447. write_data(Date[i]);
  448. write_com(0x80+0x40+5);
  449. for(i=0;i<11;i++)
  450. write_data(riqi[i]);
  451. while(!key3);
  452. break;
  453. }
  454. }
  455. }
  456. void display4()//set clock time 4
  457. {
  458. while(1)
  459. {
  460. if(key1==0)
  461. {
  462. delay(10);
  463. if(key1==0)
  464. {
  465. if(ahour4==23)
  466. ahour4=0;
  467. else
  468. ahour4++;
  469. ahourge4=ahour4%10;
  470. ahourshi4=ahour4/10;
  471. write_com(0x0f);
  472. write_com(0x80+0x40+8);
  473. write_data(':');
  474. write_com(0x80+0x40+7);
  475. write_data(table1[ahourge4]);
  476. delay(1);
  477. write_com(0x80+0x40+6);
  478. write_data(table1[ahourshi4]);
  479. delay(1);
  480. while(!key1);
  481. }
  482. }
  483. if(key2==0)
  484. {
  485. delay(10);
  486. if(key2==0)
  487. {
  488. if(amin4==59)
  489. amin4=0;
  490. else
  491. amin4++;
  492. aminge4=amin4%10;
  493. aminshi4=amin4/10;
  494. write_com(0x0f);
  495. write_com(0x80+0x40+10);
  496. write_data(table1[aminge4]);
  497. delay(1);
  498. write_com(0x80+0x40+9);
  499. write_data(table1[aminshi4]);
  500. delay(1);
  501. while(!key2);
  502. }
  503. }
  504. if(key3==0)
  505. {
  506. write_com(0x0c);
  507. write_com(0x80+0x40+0);
  508. for(i=0;i<5;i++)
  509. write_data(Date[i]);
  510. write_com(0x80+0x40+5);
  511. for(i=0;i<11;i++)
  512. write_data(riqi[i]);
  513. while(!key3);
  514. break;
  515. }
  516. }
  517. }
  518. void display5()//set clock time 5
  519. {
  520. while(1)
  521. {
  522. if(key1==0)
  523. {
  524. delay(10);
  525. if(key1==0)
  526. {
  527. if(ahour5==23)
  528. ahour5=0;
  529. else
  530. ahour5++;
  531. ahourge5=ahour5%10;
  532. ahourshi5=ahour5/10;
  533. write_com(0x0f);
  534. write_com(0x80+0x40+8);
  535. write_data(':');
  536. write_com(0x80+0x40+7);
  537. write_data(table1[ahourge5]);
  538. delay(1);
  539. write_com(0x80+0x40+6);
  540. write_data(table1[ahourshi5]);
  541. delay(1);
  542. while(!key1);
  543. }
  544. }
  545. if(key2==0)
  546. {
  547. delay(10);
  548. if(key2==0)
  549. {
  550. if(amin5==59)
  551. amin5=0;
  552. else
  553. amin5++;
  554. aminge5=amin5%10;
  555. aminshi5=amin5/10;
  556. write_com(0x0f);
  557. write_com(0x80+0x40+10);
  558. write_data(table1[aminge5]);
  559. delay(1);
  560. write_com(0x80+0x40+9);
  561. write_data(table1[aminshi5]);
  562. delay(1);
  563. while(!key2);
  564. }
  565. }
  566. if(key3==0)
  567. {
  568. write_com(0x0c);
  569. write_com(0x80+0x40+0);
  570. for(i=0;i<5;i++)
  571. write_data(Date[i]);
  572. write_com(0x80+0x40+5);
  573. for(i=0;i<11;i++)
  574. write_data(riqi[i]);
  575. while(!key3);
  576. break;
  577. }
  578. }
  579. }
  580. void display6()//set clock time 6
  581. {
  582. while(1)
  583. {
  584. if(key1==0)
  585. {
  586. delay(10);
  587. if(key1==0)
  588. {
  589. if(ahour6==23)
  590. ahour6=0;
  591. else
  592. ahour6++;
  593. ahourge6=ahour6%10;
  594. ahourshi6=ahour6/10;
  595. write_com(0x0f);
  596. write_com(0x80+0x40+8);
  597. write_data(':');
  598. write_com(0x80+0x40+7);
  599. write_data(table1[ahourge6]);
  600. delay(1);
  601. write_com(0x80+0x40+6);
  602. write_data(table1[ahourshi6]);
  603. delay(1);
  604. while(!key1);
  605. }
  606. }
  607. if(key2==0)
  608. {
  609. delay(10);
  610. if(key2==0)
  611. {
  612. if(amin6==59)
  613. amin6=0;
  614. else
  615. amin6++;
  616. aminge6=amin6%10;
  617. aminshi6=amin6/10;
  618. write_com(0x0f);
  619. write_com(0x80+0x40+10);
  620. write_data(table1[aminge6]);
  621. delay(1);
  622. write_com(0x80+0x40+9);
  623. write_data(table1[aminshi6]);
  624. delay(1);
  625. while(!key2);
  626. }
  627. }
  628. if(key3==0)
  629. {
  630. write_com(0x0c);
  631. write_com(0x80+0x40+0);
  632. for(i=0;i<5;i++)
  633. write_data(Date[i]);
  634. write_com(0x80+0x40+5);
  635. for(i=0;i<11;i++)
  636. write_data(riqi[i]);
  637. while(!key3);
  638. break;
  639. }
  640. }
  641. }
  642. void display7()//set clock time 7
  643. {
  644. while(1)
  645. {
  646. if(key1==0)
  647. {
  648. delay(10);
  649. if(key1==0)
  650. {
  651. if(ahour7==23)
  652. ahour7=0;
  653. else
  654. ahour7++;
  655. ahourge7=ahour7%10;
  656. ahourshi7=ahour7/10;
  657. write_com(0x0f);
  658. write_com(0x80+0x40+8);
  659. write_data(':');
  660. write_com(0x80+0x40+7);
  661. write_data(table1[ahourge7]);
  662. delay(1);
  663. write_com(0x80+0x40+6);
  664. write_data(table1[ahourshi7]);
  665. delay(1);
  666. while(!key1);
  667. }
  668. }
  669. if(key2==0)
  670. {
  671. delay(10);
  672. if(key2==0)
  673. {
  674. if(amin7==59)
  675. amin7=0;
  676. else
  677. amin7++;
  678. aminge7=amin7%10;
  679. aminshi7=amin7/10;
  680. write_com(0x0f);
  681. write_com(0x80+0x40+10);
  682. write_data(table1[aminge7]);
  683. delay(1);
  684. write_com(0x80+0x40+9);
  685. write_data(table1[aminshi7]);
  686. delay(1);
  687. while(!key2);
  688. }
  689. }
  690. if(key3==0)
  691. {
  692. write_com(0x0c);
  693. write_com(0x80+0x40+0);
  694. for(i=0;i<5;i++)
  695. write_data(Date[i]);
  696. write_com(0x80+0x40+5);
  697. for(i=0;i<11;i++)
  698. write_data(riqi[i]);
  699. while(!key3);
  700. break;
  701. }
  702. }
  703. }
  704. void display8()//set clock time 8
  705. {
  706. while(1)
  707. {
  708. if(key1==0)
  709. {
  710. delay(10);
  711. if(key1==0)
  712. {
  713. if(ahour8==23)
  714. ahour8=0;
  715. else
  716. ahour8++;
  717. ahourge8=ahour8%10;
  718. ahourshi8=ahour8/10;
  719. write_com(0x0f);
  720. write_com(0x80+0x40+8);
  721. write_data(':');
  722. write_com(0x80+0x40+7);
  723. write_data(table1[ahourge8]);
  724. delay(1);
  725. write_com(0x80+0x40+6);
  726. write_data(table1[ahourshi8]);
  727. delay(1);
  728. while(!key1);
  729. }
  730. }
  731. if(key2==0)
  732. {
  733. delay(10);
  734. if(key2==0)
  735. {
  736. if(amin8==59)
  737. amin8=0;
  738. else
  739. amin8++;
  740. aminge8=amin8%10;
  741. aminshi8=amin8/10;
  742. write_com(0x0f);
  743. write_com(0x80+0x40+10);
  744. write_data(table1[aminge8]);
  745. delay(1);
  746. write_com(0x80+0x40+9);
  747. write_data(table1[aminshi8]);
  748. delay(1);
  749. while(!key2);
  750. }
  751. }
  752. if(key3==0)
  753. {
  754. write_com(0x0c);
  755. write_com(0x80+0x40+0);
  756. for(i=0;i<5;i++)
  757. write_data(Date[i]);
  758. write_com(0x80+0x40+5);
  759. for(i=0;i<11;i++)
  760. write_data(riqi[i]);
  761. while(!key3);
  762. break;
  763. }
  764. }
  765. }
  766. void display9()//set clock time 9
  767. {
  768. while(1)
  769. {
  770. if(key1==0)
  771. {
  772. delay(10);
  773. if(key1==0)
  774. {
  775. if(ahour9==23)
  776. ahour9=0;
  777. else
  778. ahour9++;
  779. ahourge9=ahour9%10;
  780. ahourshi9=ahour9/10;
  781. write_com(0x0f);
  782. write_com(0x80+0x40+8);
  783. write_data(':');
  784. write_com(0x80+0x40+7);
  785. write_data(table1[ahourge9]);
  786. delay(1);
  787. write_com(0x80+0x40+6);
  788. write_data(table1[ahourshi9]);
  789. delay(1);
  790. while(!key1);
  791. }
  792. }
  793. if(key2==0)
  794. {
  795. delay(10);
  796. if(key2==0)
  797. {
  798. if(amin9==59)
  799. amin9=0;
  800. else
  801. amin9++;
  802. aminge9=amin9%10;
  803. aminshi9=amin9/10;
  804. write_com(0x0f);
  805. write_com(0x80+0x40+10);
  806. write_data(table1[aminge9]);
  807. delay(1);
  808. write_com(0x80+0x40+9);
  809. write_data(table1[aminshi9]);
  810. delay(1);
  811. while(!key2);
  812. }
  813. }
  814. if(key3==0)
  815. {
  816. write_com(0x0c);
  817. write_com(0x80+0x40+0);
  818. for(i=0;i<5;i++)
  819. write_data(Date[i]);
  820. write_com(0x80+0x40+5);
  821. for(i=0;i<11;i++)
  822. write_data(riqi[i]);
  823. while(!key3);
  824. break;
  825. }
  826. }
  827. }
  828. void keyscan()//keyscan
  829. {
  830. if(key1==0)
  831. {
  832. delay(10);
  833. if(key1==0)
  834. {
  835. while(!key1);
  836. time();
  837. }
  838. }
  839. else
  840. if(key2==0)
  841. {
  842. cnt1++;
  843. delay(10);
  844. if(cnt1==1)
  845. {
  846. while(!key2)
  847. {
  848. ahourge1=ahour1%10;
  849. ahourshi1=ahour1/10;
  850. write_com(0x80+0x40+7);
  851. write_data(table1[ahourge1]);
  852. delay(5);
  853. write_com(0x80+0x40+6);
  854. delay(2);
  855. write_data(table1[ahourshi1]);
  856. aminge1=amin1%10;
  857. aminshi1=amin1/10;
  858. write_com(0x80+0x40+10);
  859. write_data(table1[aminge1]);
  860. delay(5);
  861. write_com(0x80+0x40+9);
  862. delay(2);
  863. write_data(table1[aminshi1]);
  864. write_com(0x80+0x40);
  865. for(i=0;i<11;++i)
  866. write_data(clock_1[i]);
  867. write_com(0x80+0x40+11);
  868. for(i=0;i<5;i++)
  869. write_data(clock_0[i]);
  870. }
  871. write_com(0x80+0x40+0);
  872. for(i=0;i<5;i++)
  873. write_data(Date[i]);
  874. write_com(0x80+0x40+5);
  875. for(i=0;i<11;i++)
  876. write_data(riqi[i]);
  877. }
  878. if(cnt1==2)
  879. {
  880. while(!key2)
  881. {
  882. ahourge2=ahour2%10;
  883. ahourshi2=ahour2/10;
  884. write_com(0x80+0x40+7);
  885. write_data(table1[ahourge2]);
  886. delay(5);
  887. write_com(0x80+0x40+6);
  888. delay(2);
  889. write_data(table1[ahourshi2]);
  890. aminge2=amin2%10;
  891. aminshi2=amin2/10;
  892. write_com(0x80+0x40+10);
  893. write_data(table1[aminge2]);
  894. delay(5);
  895. write_com(0x80+0x40+9);
  896. delay(2);
  897. write_data(table1[aminshi2]);
  898. write_com(0x80+0x40);
  899. for(i=0;i<11;++i)
  900. write_data(clock_2[i]);
  901. write_com(0x80+0x40+11);
  902. for(i=0;i<5;i++)
  903. write_data(clock_0[i]);
  904. }
  905. write_com(0x80+0x40+0);
  906. for(i=0;i<5;i++)
  907. write_data(Date[i]);
  908. write_com(0x80+0x40+5);
  909. for(i=0;i<11;i++)
  910. write_data(riqi[i]);
  911. }
  912. if(cnt1==3)
  913. {
  914. while(!key2)
  915. {
  916. ahourge3=ahour3%10;
  917. ahourshi3=ahour3/10;
  918. write_com(0x80+0x40+7);
  919. write_data(table1[ahourge3]);
  920. delay(5);
  921. write_com(0x80+0x40+6);
  922. delay(2);
  923. write_data(table1[ahourshi3]);
  924. aminge3=amin3%10;
  925. aminshi3=amin3/10;
  926. write_com(0x80+0x40+10);
  927. write_data(table1[aminge3]);
  928. delay(5);
  929. write_com(0x80+0x40+9);
  930. delay(2);
  931. write_data(table1[aminshi3]);
  932. write_com(0x80+0x40);
  933. for(i=0;i<11;++i)
  934. write_data(clock_3[i]);
  935. write_com(0x80+0x40+11);
  936. for(i=0;i<5;i++)
  937. write_data(clock_0[i]);
  938. }
  939. write_com(0x80+0x40+0);
  940. for(i=0;i<5;i++)
  941. write_data(Date[i]);
  942. write_com(0x80+0x40+5);
  943. for(i=0;i<11;i++)
  944. write_data(riqi[i]);
  945. }
  946. if(cnt1==4)
  947. {
  948. while(!key2)
  949. {
  950. ahourge4=ahour4%10;
  951. ahourshi4=ahour4/10;
  952. write_com(0x80+0x40+7);
  953. write_data(table1[ahourge4]);
  954. delay(5);
  955. write_com(0x80+0x40+6);
  956. delay(2);
  957. write_data(table1[ahourshi4]);
  958. aminge4=amin4%10;
  959. aminshi4=amin4/10;
  960. write_com(0x80+0x40+10);
  961. write_data(table1[aminge4]);
  962. delay(5);
  963. write_com(0x80+0x40+9);
  964. delay(2);
  965. write_data(table1[aminshi4]);
  966. write_com(0x80+0x40);
  967. for(i=0;i<11;++i)
  968. write_data(clock_4[i]);
  969. write_com(0x80+0x40+11);
  970. for(i=0;i<5;i++)
  971. write_data(clock_0[i]);
  972. }
  973. write_com(0x80+0x40+0);
  974. for(i=0;i<5;i++)
  975. write_data(Date[i]);
  976. write_com(0x80+0x40+5);
  977. for(i=0;i<11;i++)
  978. write_data(riqi[i]);
  979. }
  980. if(cnt1==5)
  981. {
  982. while(!key2)
  983. {
  984. ahourge5=ahour5%10;
  985. ahourshi5=ahour5/10;
  986. write_com(0x80+0x40+7);
  987. write_data(table1[ahourge5]);
  988. delay(5);
  989. write_com(0x80+0x40+6);
  990. delay(2);
  991. write_data(table1[ahourshi5]);
  992. aminge4=amin4%10;
  993. aminshi4=amin4/10;
  994. write_com(0x80+0x40+10);
  995. write_data(table1[aminge5]);
  996. delay(5);
  997. write_com(0x80+0x40+9);
  998. delay(2);
  999. write_data(table1[aminshi5]);
  1000. write_com(0x80+0x40);
  1001. for(i=0;i<11;++i)
  1002. write_data(clock_5[i]);
  1003. write_com(0x80+0x40+11);
  1004. for(i=0;i<5;i++)
  1005. write_data(clock_0[i]);
  1006. }
  1007. write_com(0x80+0x40+0);
  1008. for(i=0;i<5;i++)
  1009. write_data(Date[i]);
  1010. write_com(0x80+0x40+5);
  1011. for(i=0;i<11;i++)
  1012. write_data(riqi[i]);
  1013. }
  1014. if(cnt1==6)
  1015. {
  1016. while(!key2)
  1017. {
  1018. ahourge6=ahour6%10;
  1019. ahourshi6=ahour6/10;
  1020. write_com(0x80+0x40+7);
  1021. write_data(table1[ahourge6]);
  1022. delay(5);
  1023. write_com(0x80+0x40+6);
  1024. delay(2);
  1025. write_data(table1[ahourshi6]);
  1026. aminge6=amin6%10;
  1027. aminshi6=amin6/10;
  1028. write_com(0x80+0x40+10);
  1029. write_data(table1[aminge6]);
  1030. delay(5);
  1031. write_com(0x80+0x40+9);
  1032. delay(2);
  1033. write_data(table1[aminshi6]);
  1034. write_com(0x80+0x40);
  1035. for(i=0;i<11;++i)
  1036. write_data(clock_6[i]);
  1037. write_com(0x80+0x40+11);
  1038. for(i=0;i<5;i++)
  1039. write_data(clock_0[i]);
  1040. }
  1041. write_com(0x80+0x40+0);
  1042. for(i=0;i<5;i++)
  1043. write_data(Date[i]);
  1044. write_com(0x80+0x40+5);
  1045. for(i=0;i<11;i++)
  1046. write_data(riqi[i]);
  1047. }
  1048. if(cnt1==7)
  1049. {
  1050. while(!key2)
  1051. {
  1052. ahourge7=ahour7%10;
  1053. ahourshi7=ahour7/10;
  1054. write_com(0x80+0x40+7);
  1055. write_data(table1[ahourge7]);
  1056. delay(5);
  1057. write_com(0x80+0x40+6);
  1058. delay(2);
  1059. write_data(table1[ahourshi7]);
  1060. aminge7=amin7%10;
  1061. aminshi7=amin7/10;
  1062. write_com(0x80+0x40+10);
  1063. write_data(table1[aminge7]);
  1064. delay(5);
  1065. write_com(0x80+0x40+9);
  1066. delay(2);
  1067. write_data(table1[aminshi7]);
  1068. write_com(0x80+0x40);
  1069. for(i=0;i<11;++i)
  1070. write_data(clock_7[i]);
  1071. write_com(0x80+0x40+11);
  1072. for(i=0;i<5;i++)
  1073. write_data(clock_0[i]);
  1074. }
  1075. write_com(0x80+0x40+0);
  1076. for(i=0;i<5;i++)
  1077. write_data(Date[i]);
  1078. write_com(0x80+0x40+5);
  1079. for(i=0;i<11;i++)
  1080. write_data(riqi[i]);
  1081. }
  1082. if(cnt1==8)
  1083. {
  1084. while(!key2)
  1085. {
  1086. ahourge8=ahour8%10;
  1087. ahourshi8=ahour8/10;
  1088. write_com(0x80+0x40+7);
  1089. write_data(table1[ahourge8]);
  1090. delay(5);
  1091. write_com(0x80+0x40+6);
  1092. delay(2);
  1093. write_data(table1[ahourshi8]);
  1094. aminge8=amin8%10;
  1095. aminshi8=amin8/10;
  1096. write_com(0x80+0x40+10);
  1097. write_data(table1[aminge8]);
  1098. delay(5);
  1099. write_com(0x80+0x40+9);
  1100. delay(2);
  1101. write_data(table1[aminshi8]);
  1102. write_com(0x80+0x40);
  1103. for(i=0;i<11;++i)
  1104. write_data(clock_8[i]);
  1105. write_com(0x80+0x40+11);
  1106. for(i=0;i<5;i++)
  1107. write_data(clock_0[i]);
  1108. }
  1109. write_com(0x80+0x40+0);
  1110. for(i=0;i<5;i++)
  1111. write_data(Date[i]);
  1112. write_com(0x80+0x40+5);
  1113. for(i=0;i<11;i++)
  1114. write_data(riqi[i]);
  1115. }
  1116. if(cnt1==9)
  1117. {
  1118. while(!key2)
  1119. {
  1120. ahourge9=ahour9%10;
  1121. ahourshi9=ahour9/10;
  1122. write_com(0x80+0x40+7);
  1123. write_data(table1[ahourge9]);
  1124. delay(5);
  1125. write_com(0x80+0x40+6);
  1126. delay(2);
  1127. write_data(table1[ahourshi9]);
  1128. aminge9=amin9%10;
  1129. aminshi9=amin9/10;
  1130. write_com(0x80+0x40+10);
  1131. write_data(table1[aminge9]);
  1132. delay(5);
  1133. write_com(0x80+0x40+9);
  1134. delay(2);
  1135. write_data(table1[aminshi9]);
  1136. write_com(0x80+0x40);
  1137. for(i=0;i<11;++i)
  1138. write_data(clock_9[i]);
  1139. write_com(0x80+0x40+11);
  1140. for(i=0;i<5;i++)
  1141. write_data(clock_0[i]);
  1142. }
  1143. write_com(0x80+0x40+0);
  1144. for(i=0;i<5;i++)
  1145. write_data(Date[i]);
  1146. write_com(0x80+0x40+5);
  1147. for(i=0;i<11;i++)
  1148. write_data(riqi[i]);
  1149. }
  1150. if(cnt1>9)
  1151. cnt1=0;
  1152. }
  1153. else if(key3==0)
  1154. {
  1155. cnt++;
  1156. delay(10);
  1157. if(cnt==1)
  1158. {
  1159. while(!key3);
  1160. ahourge1=ahour1%10;
  1161. ahourshi1=ahour1/10;
  1162. write_com(0x80+0x40+7);
  1163. write_data(table1[ahourge1]);
  1164. delay(5);
  1165. write_com(0x80+0x40+6);
  1166. delay(2);
  1167. write_data(table1[ahourshi1]);
  1168. aminge1=amin1%10;
  1169. aminshi1=amin1/10;
  1170. write_com(0x80+0x40+10);
  1171. write_data(table1[aminge1]);
  1172. delay(5);
  1173. write_com(0x80+0x40+9);
  1174. delay(2);
  1175. write_data(table1[aminshi1]);
  1176. write_com(0x80+0x40);
  1177. for(i=0;i<11;++i)
  1178. write_data(clock_1[i]);
  1179. write_com(0x80+0x40+11);
  1180. for(i=0;i<5;i++)
  1181. write_data(clock_0[i]);
  1182. display1();
  1183. }
  1184. if(cnt==3)
  1185. {
  1186. while(!key3);
  1187. ahourge2=ahour2%10;
  1188. ahourshi2=ahour2/10;
  1189. write_com(0x80+0x40+7);
  1190. write_data(table1[ahourge2]);
  1191. delay(5);
  1192. write_com(0x80+0x40+6);
  1193. delay(2);
  1194. write_data(table1[ahourshi2]);
  1195. aminge2=amin2%10;
  1196. aminshi2=amin2/10;
  1197. write_com(0x80+0x40+10);
  1198. write_data(table1[aminge2]);
  1199. delay(5);
  1200. write_com(0x80+0x40+9);
  1201. delay(2);
  1202. write_data(table1[aminshi2]);
  1203. write_com(0x80+0x40);
  1204. for(i=0;i<11;++i)
  1205. write_data(clock_2[i]);
  1206. write_com(0x80+0x40+11);
  1207. for(i=0;i<5;i++)
  1208. write_data(clock_0[i]);
  1209. display2();
  1210. }
  1211. if(cnt==5)
  1212. {
  1213. while(!key3);
  1214. ahourge3=ahour3%10;
  1215. ahourshi3=ahour3/10;
  1216. write_com(0x80+0x40+7);
  1217. write_data(table1[ahourge3]);
  1218. delay(5);
  1219. write_com(0x80+0x40+6);
  1220. delay(2);
  1221. write_data(table1[ahourshi3]);
  1222. aminge3=amin3%10;
  1223. aminshi3=amin3/10;
  1224. write_com(0x80+0x40+10);
  1225. write_data(table1[aminge3]);
  1226. delay(5);
  1227. write_com(0x80+0x40+9);
  1228. delay(2);
  1229. write_data(table1[aminshi3]);
  1230. write_com(0x80+0x40);
  1231. for(i=0;i<11;++i)
  1232. write_data(clock_3[i]);
  1233. write_com(0x80+0x40+11);
  1234. for(i=0;i<5;i++)
  1235. write_data(clock_0[i]);
  1236. display3();
  1237. }
  1238. if(cnt==7)
  1239. {
  1240. while(!key3);
  1241. ahourge4=ahour4%10;
  1242. ahourshi4=ahour4/10;
  1243. write_com(0x80+0x40+7);
  1244. write_data(table1[ahourge4]);
  1245. delay(5);
  1246. write_com(0x80+0x40+6);
  1247. delay(2);
  1248. write_data(table1[ahourshi4]);
  1249. aminge4=amin4%10;
  1250. aminshi4=amin4/10;
  1251. write_com(0x80+0x40+10);
  1252. write_data(table1[aminge4]);
  1253. delay(5);
  1254. write_com(0x80+0x40+9);
  1255. delay(2);
  1256. write_data(table1[aminshi4]);
  1257. write_com(0x80+0x40);
  1258. for(i=0;i<11;++i)
  1259. write_data(clock_4[i]);
  1260. write_com(0x80+0x40+11);
  1261. for(i=0;i<5;i++)
  1262. write_data(clock_0[i]);
  1263. display4();
  1264. }
  1265. if(cnt==9)
  1266. {
  1267. while(!key3);
  1268. ahourge5=ahour5%10;
  1269. ahourshi5=ahour5/10;
  1270. write_com(0x80+0x40+7);
  1271. write_data(table1[ahourge5]);
  1272. delay(5);
  1273. write_com(0x80+0x40+6);
  1274. delay(2);
  1275. write_data(table1[ahourshi5]);
  1276. aminge5=amin5%10;
  1277. aminshi5=amin5/10;
  1278. write_com(0x80+0x40+10);
  1279. write_data(table1[aminge5]);
  1280. delay(5);
  1281. write_com(0x80+0x40+9);
  1282. delay(2);
  1283. write_data(table1[aminshi5]);
  1284. write_com(0x80+0x40);
  1285. for(i=0;i<11;++i)
  1286. write_data(clock_5[i]);
  1287. write_com(0x80+0x40+11);
  1288. for(i=0;i<5;i++)
  1289. write_data(clock_0[i]);
  1290. display5();
  1291. }
  1292. if(cnt==11)
  1293. {
  1294. while(!key3);
  1295. ahourge6=ahour6%10;
  1296. ahourshi6=ahour6/10;
  1297. write_com(0x80+0x40+7);
  1298. write_data(table1[ahourge6]);
  1299. delay(5);
  1300. write_com(0x80+0x40+6);
  1301. delay(2);
  1302. write_data(table1[ahourshi6]);
  1303. aminge6=amin6%10;
  1304. aminshi6=amin6/10;
  1305. write_com(0x80+0x40+10);
  1306. write_data(table1[aminge6]);
  1307. delay(5);
  1308. write_com(0x80+0x40+9);
  1309. delay(2);
  1310. write_data(table1[aminshi6]);
  1311. write_com(0x80+0x40);
  1312. for(i=0;i<11;++i)
  1313. write_data(clock_6[i]);
  1314. write_com(0x80+0x40+11);
  1315. for(i=0;i<5;i++)
  1316. write_data(clock_0[i]);
  1317. display6();
  1318. }
  1319. if(cnt==13)
  1320. {
  1321. while(!key3);
  1322. ahourge7=ahour7%10;
  1323. ahourshi7=ahour7/10;
  1324. write_com(0x80+0x40+7);
  1325. write_data(table1[ahourge7]);
  1326. delay(5);
  1327. write_com(0x80+0x40+6);
  1328. delay(2);
  1329. write_data(table1[ahourshi7]);
  1330. aminge7=amin7%10;
  1331. aminshi7=amin7/10;
  1332. write_com(0x80+0x40+10);
  1333. write_data(table1[aminge7]);
  1334. delay(5);
  1335. write_com(0x80+0x40+9);
  1336. delay(2);
  1337. write_data(table1[aminshi7]);
  1338. write_com(0x80+0x40);
  1339. for(i=0;i<11;++i)
  1340. write_data(clock_7[i]);
  1341. write_com(0x80+0x40+11);
  1342. for(i=0;i<5;i++)
  1343. write_data(clock_0[i]);
  1344. display7();
  1345. }
  1346. if(cnt==15)
  1347. {
  1348. while(!key3);
  1349. ahourge8=ahour8%10;
  1350. ahourshi8=ahour8/10;
  1351. write_com(0x80+0x40+7);
  1352. write_data(table1[ahourge8]);
  1353. delay(5);
  1354. write_com(0x80+0x40+6);
  1355. delay(2);
  1356. write_data(table1[ahourshi8]);
  1357. aminge8=amin8%10;
  1358. aminshi8=amin8/10;
  1359. write_com(0x80+0x40+10);
  1360. write_data(table1[aminge8]);
  1361. delay(5);
  1362. write_com(0x80+0x40+9);
  1363. delay(2);
  1364. write_data(table1[aminshi8]);
  1365. write_com(0x80+0x40);
  1366. for(i=0;i<11;++i)
  1367. write_data(clock_8[i]);
  1368. write_com(0x80+0x40+11);
  1369. for(i=0;i<5;i++)
  1370. write_data(clock_0[i]);
  1371. display8();
  1372. }
  1373. if(cnt==17)
  1374. {
  1375. while(!key3);
  1376. ahourge9=ahour9%10;
  1377. ahourshi9=ahour9/10;
  1378. write_com(0x80+0x40+7);
  1379. write_data(table1[ahourge9]);
  1380. delay(5);
  1381. write_com(0x80+0x40+6);
  1382. delay(2);
  1383. write_data(table1[ahourshi9]);
  1384. aminge9=amin9%10;
  1385. aminshi9=amin9/10;
  1386. write_com(0x80+0x40+10);
  1387. write_data(table1[aminge9]);
  1388. delay(5);
  1389. write_com(0x80+0x40+9);
  1390. delay(2);
  1391. write_data(table1[aminshi9]);
  1392. write_com(0x80+0x40);
  1393. for(i=0;i<11;++i)
  1394. write_data(clock_9[i]);
  1395. write_com(0x80+0x40+11);
  1396. for(i=0;i<5;i++)
  1397. write_data(clock_0[i]);
  1398. display9();
  1399. }
  1400. if(cnt>20)
  1401. {
  1402. cnt=0;
  1403. }
  1404. }
  1405. }
  1406. void ruler()//
  1407. {
  1408. if(sec==60)
  1409. {
  1410. min++;
  1411. sec=0;
  1412. }
  1413. if(min==60)
  1414. {
  1415. hour++;
  1416. min=0;
  1417. }
  1418. if(hour==24)
  1419. {
  1420. ri++;
  1421. hour=0;
  1422. }
  1423. if(ri==30)
  1424. {
  1425. yue++;
  1426. ri=0;
  1427. }
  1428. if(yue==12)
  1429. {
  1430. nian++;
  1431. yue=1;
  1432. }
  1433. }
  1434. void init()//danpianji chushihua
  1435. {
  1436. key1=1;key2=1;key3=1;sec=0;sound=1;
  1437. TMOD=0x10;
  1438. TL1=0xB0;
  1439. TH1=0x3C;//¼ÆÊý³õֵΪ15536
  1440. EA=1;
  1441. ET1=1;
  1442. TR1=1;
  1443. }
  1444. void speak()// music
  1445. {
  1446. if(amin1==min&&ahour1==hour||amin2==min&&ahour2==hour||amin3==min&&ahour3==hour||amin4==min&&ahour4==hour||amin5==min&&ahour5==hour||amin6==min&&ahour6==hour||amin7==min&&ahour7==hour||amin8==min&&ahour8==hour||amin9==min&&ahour9==hour)
  1447. {
  1448. delay(5);
  1449. sound=0;
  1450. }
  1451. delay(10);
  1452. delay(10);
  1453. delay(10);
  1454. sound=1;
  1455. }
  1456. void led1() interrupt 3
  1457. {
  1458. TL1=0xB0;
  1459. TH1=0x3C;
  1460. speak();
  1461. num1++;
  1462. num2++;
  1463. if(num2==20)
  1464. {
  1465. sec++;
  1466. num2=0;
  1467. ruler();
  1468. }
  1469. }
  1470. void lcd_init()//lcd chushihua
  1471. {
  1472. en=0;
  1473. rw=0;
  1474. write_com(0x01);
  1475. write_com(0x06);
  1476. write_com(0x0c);
  1477. write_com(0x38);
  1478. delay(2);
  1479. write_com(0x80);
  1480. for(i=0;i<16;i++)
  1481. {
  1482. write_data(table2[i]);
  1483. delay(1);
  1484. }
  1485. }
  1486. void displays()
  1487. {
  1488. minge=min%10;
  1489. minshi=min/10;
  1490. write_com(0x80+9);
  1491. write_data(table1[minge]);
  1492. delay(5);
  1493. write_com(0x80+8);
  1494. write_data(table1[minshi]);
  1495. hourge=hour%10;
  1496. hourshi=hour/10;
  1497. write_com(0x80+6);
  1498. write_data(table1[hourge]);
  1499. delay(5);
  1500. write_com(0x80+5);
  1501. write_data(table1[hourshi]);
  1502. write_com(0x80+7);
  1503. write_data(':');
  1504. write_com(0x80+10);
  1505. write_data(':');
  1506. write_com(0x80+15);
  1507. for(i=0;i<5;i++)
  1508. write_data(clock[i]);
  1509. delay(5);
  1510. secge=sec%10;
  1511. secshi=sec/10;
  1512. write_com(0x80+12);
  1513. write_data(table1[secge]);
  1514. delay(5);
  1515. write_com(0x80+11);
  1516. write_data(table1[secshi]);
  1517. write_com(0x80+20+0);
  1518. for(i=0;i<5;i++)
  1519. write_data(tips[i]);
  1520. }
  1521. void main()
  1522. {
  1523. lcd_init();
  1524. init();
  1525. while(1)
  1526. {
  1527. keyscan();
  1528. displays();
  1529. qi();
  1530. show();
  1531. }
  1532. }

仿真Proteus

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号