找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

帖子
查看: 6495|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

基于51單片機(jī)的音樂(lè)播放器仿真程序設(shè)計(jì)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  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. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
多功能音樂(lè)播放器仿真程序.7z (46.71 KB, 下載次數(shù): 157)
網(wǎng)上找的文檔資料.7z (441.5 KB, 下載次數(shù): 5)

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩1
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:670803 發(fā)表于 2019-12-22 23:09 | 只看該作者
可以用I2C存儲(chǔ)器24C04芯片跟單片機(jī)做一個(gè)音樂(lè)播放器嗎?
回復(fù)

使用道具 舉報(bào)

板凳
ID:327029 發(fā)表于 2019-12-23 07:45 | 只看該作者
你這是拿別人的功能音樂(lè)盒仿真資料混著一篇根本不對(duì)應(yīng)的花樣流水燈音樂(lè)盒文檔 哈哈
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表