EDABOSS电子论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 693|回复: 1

[资料共享] 1602+ds12b80+ds1302+音乐+电子书+流水灯的电子表

[复制链接]

26

主题

0

回帖

197

E币

技术员

Rank: 2

积分
52
发表于 2017-5-10 15:05:23 | 显示全部楼层 |阅读模式
功能十分强大,我觉得是现在比较好的一个,特拿来和大家分享,这是7zip压缩,把rar改成那个就可以解压了

213112g00qi3iioedvxohx.jpg
捕获.PNG

基于1602 ds12b80 ds1302 音乐 电子书 流水灯的多功能电子表.rar (58.88 KB, 下载次数: 0)

  1. #include<reg52.h>
  2. #include <intrins.h>
  3. #include <absacc.h>
  4. #include<lcd.h>
  5. #include<1302.h>
  6. #include<music_code.h>
  7. #include<SoundPlay.h>
  8. #include<dds.h>
  9. uchar code time[]={'0','1','2','3','4','5','6','7','8','9'};
  10. uchar code get_up[]="Time to Get up!";
  11. uchar code str[]="Never frown,even when you are sad,because you never know who is falling in love with your smile! To the world you may be one person,but to one person you may be the world ";
  12. uchar code menu[4][10]={{"Time Set"},{"Music"},{"Books"},{"Ring Set"}};
  13. void main()
  14. {
  15.         ini();
  16.         open();
  17.         delay(255);
  18.         delay(255);
  19.         delay(255);
  20.         delay(255);
  21.         write_order(0x01,1);
  22.         init_ds1302();
  23.         set_ds1302(time_add,initial_time);
  24.         while(1)
  25.         {
  26.                 /*read_ring();
  27.                 if(ring_time[0]==now_time[0]&&ring_time[1]==now_time[1]&&ring_time[2]==now_time[2])
  28.                 {
  29.                         timeup();
  30.                 }  */
  31.                 detect();
  32.                 write_order(0x80+0x04,1);               
  33.                 for(i=0;menu[key][i]!=0;i++)
  34.                 {
  35.                         write_date(menu[key][i]);
  36.                 }
  37.                 get_ds1302();
  38.                 write_order(0x80+0x40,1);
  39.                 write_date(time[now_time[4]>>4]);
  40.                 write_date(time[now_time[4]&0x0f]);
  41.                 write_date(0x01);
  42.                 write_date(time[now_time[3]>>4]);
  43.                 write_date(time[now_time[3]&0x0f]);
  44.                 write_date(0x00);
  45.                 write_date(' ');
  46.                 write_date(' ');
  47.                 write_date(time[now_time[2]>>4]);
  48.                 write_date(time[now_time[2]&0x0f]);
  49.                 write_date(':');
  50.                 write_date(time[now_time[1]>>4]);
  51.                 write_date(time[now_time[1]&0x0f]);
  52.                 write_date(':');
  53.                 write_date(time[now_time[0]>>4]);
  54.                 write_date(time[now_time[0]&0x0f]);
  55.                 if(key==2)
  56.                 {
  57.                
  58.                         sum=0;
  59.                         book();

  60.                 }
  61.                 if(key==1)
  62.                 {
  63.                         music();

  64.                 }
  65.                 if(key==3)
  66.                 {               
  67.                         alamn();
  68.         
  69.                 }
  70.                 if(key==0)
  71.                 {        
  72.                         time_set();
  73.         
  74.                 }
  75.         }
  76. }
  77. void detect()
  78. {
  79.         uchar temp;
  80.         temp=P2;
  81.         temp=temp&0x0f;
  82.         if(temp!=0x0f)
  83.         {
  84.                 switch(temp)
  85.                 {
  86.                         case 0x0e:
  87.                                 while(temp!=0x0f)
  88.                         {
  89.                                 temp=P2;
  90.                                 temp=temp&0x0f;
  91.                         }
  92.                         if(key==0)
  93.                         {
  94.                                 key=4;
  95.                         }
  96.                         key--;
  97.                         flag=1;
  98.                         write_order(0x01 ,1);
  99.                         break;
  100.                         case 0x0d:
  101.                                 while(temp!=0x0f)
  102.                         {
  103.                                 temp=P2;
  104.                                 temp=temp&0x0f;
  105.                         }
  106.                         key++;
  107.                         flag=2;
  108.                         if(key==4)
  109.                         {
  110.                                 key=0;
  111.                         }
  112.                         write_order(0x01,1);
  113.                         break;
  114.                         case 0x0b:
  115.                                 while(temp!=0x0f)
  116.                         {
  117.                                 temp=P2;
  118.                                 temp=temp&0x0f;
  119.                         }
  120.                         flag=3;
  121.                         write_order(0x01,1);
  122.                         break;
  123.                         case 0x07:
  124.                                 while(temp!=0x0f)
  125.                         {
  126.                                 temp=P2;
  127.                                 temp=temp&0x0f;
  128.                         }
  129.                         flag=4;
  130.                         write_order(0x01,1);
  131.                         break;
  132.                 }
  133.         }

  134. }
  135. void page(uchar k)
  136. {
  137.         write_order(0x80,1);
  138.         for(i=k*32;i<k*32+16&&str[i]!='\0';i++)
  139.         {
  140.                 write_date(str[i]);
  141.         }
  142.         write_order(0x80+0x40,1);
  143.         for(i=k*32+16;i<k*32+32&&str[i]!='\0';i++)
  144.         {
  145.                 write_date(str[i]);
  146.         }
  147. }

  148. void book()
  149. {                        
  150.         
  151.                         flag=0;
  152.                         detect();
  153.                         if(flag==3)
  154.                         {
  155.                         flag=0;
  156.                         page(sum);
  157.                         while(flag!=4)
  158.                         {
  159.                                 detect();
  160.                                 if(flag==1)
  161.                                 {
  162.                                         flag=0;
  163.                                         if(sum!=0)
  164.                                         {
  165.                                         sum--;
  166.                                         }
  167.                                         page(sum);
  168.                                 }
  169.                                 if(flag==2)
  170.                                 {
  171.                                         flag=0;
  172.                                         if(sum<5)
  173.                                         {
  174.                                                 sum++;
  175.                                         }
  176.                                         page(sum);
  177.                                 }
  178.                         }
  179.                         key=2;
  180.                         }
  181. }

  182. void alamn()
  183. {
  184.                         flag=0;
  185.                         detect();
  186.                         if(flag==3)
  187.                         {
  188.                                 flag=0;
  189.                                 while(flag!=4)
  190.                                 {                                       
  191.                                         write_order(0x80+0x02,1);
  192.                                         write_date(time[move[0]]);
  193.                                         write_date(time[move[1]]);
  194.                                         write_date(':');
  195.                                         write_date(time[move[2]]);
  196.                                         write_date(time[move[3]]);
  197.                                         detect();
  198.                                         if(flag==1)
  199.                                         {
  200.                                                 flag=0;
  201.                                                 move[1]++;
  202.                                                 
  203.                                                 if(move[1]==10)
  204.                                                         {
  205.                                                                 move[1]=0;
  206.                                                                 move[0]++;
  207.                                                         }
  208.                                                 
  209.                                                 if(move[0]==2)
  210.                                                 {
  211.                                                         if(move[1]==4)
  212.                                                         {
  213.                                                                 move[1]=0;
  214.                                                                 move[0]=0;
  215.                                                         }
  216.                                                 }
  217.                                                 ringgo[2]=move[0]<<4|move[1];
  218.                                         }
  219.                                         if(flag==2)
  220.                                         {
  221.                                                 flag=0;
  222.                                                 move[3]++;
  223.                                                 if(move[3]==10)
  224.                                                 {
  225.                                                         move[3]=0;
  226.                                                         move[2]++;
  227.                                                         if(move[2]==6)
  228.                                                         {
  229.                                                                 move[2]=0;
  230.                                                         }
  231.                                                 }
  232.                                                 ringgo[1]=move[2]<<4|move[3];
  233.                                         }
  234.                                         if(flag==3)
  235.                                         {
  236.                                                 set_ds1302(alamn_add,ringgo);
  237.                                                 flag=4;
  238.                                         }
  239.                                        
  240.                                 }
  241.                                 key=3;
  242.                         }
  243. }

  244. void time_set()
  245. {
  246.                         flag=0;
  247.                         detect();
  248.                         if(flag==3)
  249.                         {
  250.                                 flag=0;
  251.                                 while(flag!=4)
  252.                                 {                                       
  253.                                         write_order(0x80+0x02,1);
  254.                                         write_date(time[set[0]]);
  255.                                         write_date(time[set[1]]);
  256.                                         write_date(':');
  257.                                         write_date(time[set[2]]);
  258.                                         write_date(time[set[3]]);
  259.                                         detect();
  260.                                         if(flag==1)
  261.                                         {
  262.                                                 flag=0;
  263.                                                 set[1]++;
  264.                                                 
  265.                                                         if(set[1]==10)
  266.                                                         {
  267.                                                                 set[1]=0;
  268.                                                                 set[0]++;
  269.                                                         }
  270.                                                 
  271.                                                 if(set[0]==2)
  272.                                                 {
  273.                                                         if(set[1]==4)
  274.                                                         {
  275.                                                                 set[1]=0;
  276.                                                                 set[0]=0;
  277.                                                         }
  278.                                                 }
  279.                                                 timego[2]=set[0]<<4|set[1];
  280.                                         }
  281.                                         if(flag==2)
  282.                                         {
  283.                                                 flag=0;
  284.                                                 set[3]++;
  285.                                                 if(set[3]==10)
  286.                                                 {
  287.                                                         set[3]=0;
  288.                                                         set[2]++;
  289.                                                         if(set[2]==6)
  290.                                                         {
  291.                                                                 set[2]=0;
  292.                                                         }
  293.                                                 }
  294.                                                 timego[1]=set[2]<<4|set[3];
  295.                                         }
  296.                                         if(flag==3)
  297.                                 {
  298.                                         set_ds1302(time_add,timego);
  299.                                         flag=4;
  300.                                 }
  301.                                 }
  302.                                 key=0;        
  303.                         }
  304. }

  305. void timeup()
  306. {        
  307.                         write_order(0x01,1);
  308.                         write_order(0x80+0x00,1);
  309.                         for(i=0;get_up[i]!='\0';i++)
  310.                         {
  311.                                 write_date(get_up[i]);
  312.                         }
  313.         
  314.                                 InitialSound();
  315.                                 switch(ring_song)
  316.                                                 {
  317.                                                         case 0:Play(tale,0,3,300);break;
  318.                                                         case 1:Play(coral,0,3,300);break;
  319.                                                         case 2:Play(Meet,0,3,300);break;
  320.                                                         case 3:Play(Love,0,3,340);break;
  321.                                                 }
  322.                                 write_order(0x01,1);
  323. }

  324. void music()
  325. {
  326.         if(flag==3)
  327.                         {
  328.                                 flag=0;        
  329.                                 write_order(0x01,1);                                                        
  330.                                 while(flag!=4)
  331.                                 {
  332.                                                 detect();
  333.                                                 write_order(0x80,1);
  334.                                                 for(i=0;song[key][i]!='\0';i++)
  335.                                         {                                                
  336.                                                 write_date(song[key][i]);
  337.                                         }
  338.                                         if(flag==3)
  339.                                         {
  340.                                                 InitialSound();
  341.                                                 switch(key)
  342.                                                 {
  343.                                                         case 0:Play(tale,0,3,300);break;
  344.                                                         case 1:Play(coral,0,3,300);break;
  345.                                                         case 2:Play(Meet,0,3,300);break;
  346.                                                         case 3:Play(Love,0,3,340);break;
  347.                                                 }
  348.                                                 ring_song=key;
  349.                                                 while(!esc);
  350.                                         }                             
  351.                                 }
  352.                                 write_order(0x01,1);
  353.                                 key=1;        
  354.                         }
  355. }
复制代码



积分规则
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|EDABOSS电子论坛

GMT+8, 2024-4-20 15:26 , Processed in 0.041651 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表