找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6547|回复: 2
收起左侧

基于51单片机的音乐播放器仿真程序设计

[复制链接]
ID:557684 发表于 2019-6-8 13:49 | 显示全部楼层 |阅读模式
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
51hei.png

仿真图

仿真图

文档

文档


单片机源程序如下:
  1. #include<reg52.h>
  2. #include<lcd.h>
  3. #include<1302.h>
  4. #include<music_code.h>
  5. #include<SoundPlay.h>
  6. #include<dds.h>
  7. uchar code time[]={'0','1','2','3','4','5','6','7','8','9'};
  8. uchar code get_up[]="Time to Get up!";
  9. 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 ";
  10. uchar code menu[4][10]={{"Time Set"},{"Music"},{"Books"},{"Ring Set"}};
  11. void main()
  12. {
  13.         ini();
  14.         open();
  15.         delay(255);
  16.         delay(255);
  17.         delay(255);
  18.         delay(255);
  19.         write_order(0x01);
  20.         init_ds1302();
  21.         set_ds1302(time_add,initial_time);
  22.         while(1)
  23.         {
  24.                 read_ring();
  25.                 if(ring_time[0]==now_time[0]&&ring_time[1]==now_time[1]&&ring_time[2]==now_time[2])
  26.                 {
  27.                         timeup();
  28.                 }
  29.                 detect();
  30.                 write_order(0x80+0x04);               
  31.                 for(i=0;menu[key][i]!=0;i++)
  32.                 {
  33.                         write_date(menu[key][i]);
  34.                 }
  35.                 get_ds1302();
  36.                 write_order(0x80+0x40);
  37.                 write_date(time[now_time[4]>>4]);
  38.                 write_date(time[now_time[4]&0x0f]);
  39.                 write_date(0x01);
  40.                 write_date(time[now_time[3]>>4]);
  41.                 write_date(time[now_time[3]&0x0f]);
  42.                 write_date(0x00);
  43.                 write_date(' ');
  44.                 write_date(' ');
  45.                 write_date(time[now_time[2]>>4]);
  46.                 write_date(time[now_time[2]&0x0f]);
  47.                 write_date(':');
  48.                 write_date(time[now_time[1]>>4]);
  49.                 write_date(time[now_time[1]&0x0f]);
  50.                 write_date(':');
  51.                 write_date(time[now_time[0]>>4]);
  52.                 write_date(time[now_time[0]&0x0f]);
  53.                 if(key==2)
  54.                 {
  55.                
  56.                         sum=0;
  57.                         book();

  58.                 }
  59.                 if(key==1)
  60.                 {
  61.                         music();

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

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

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

  180. void alamn()
  181. {
  182.                         flag=0;
  183.                         detect();
  184.                         if(flag==3)
  185.                         {
  186.                                 flag=0;
  187.                                 while(flag!=4)
  188.                                 {                                       
  189.                                         write_order(0x80+0x02);
  190. ……………………

  191. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
多功能音乐播放器仿真程序.7z (46.71 KB, 下载次数: 157)
网上找的文档资料.7z (441.5 KB, 下载次数: 5)

回复

使用道具 举报

ID:670803 发表于 2019-12-22 23:09 | 显示全部楼层
可以用I2C存储器24C04芯片跟单片机做一个音乐播放器吗?
回复

使用道具 举报

ID:327029 发表于 2019-12-23 07:45 | 显示全部楼层
你这是拿别人的功能音乐盒仿真资料混着一篇根本不对应的花样流水灯音乐盒文档 哈哈
回复

使用道具 举报

无效楼层,该帖已经被删除
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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