找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3075|回复: 1
收起左侧

51单片机音频显示(源码+原理图)

[复制链接]
ID:227946 发表于 2017-8-16 18:19 | 显示全部楼层 |阅读模式
51单片机音频显示
部分源码,详细源码和原理图见附件

效果图

效果图
0.png

单片机源程序:
  1. #include "Led.h"

  2. uint code ILoveWenWen[15][16] =  {
  3.                                                                 {0x0810,0x0c10,0x2b20,0x18c0,0x08c0,0x0f20,0x0810,0x0810,
  4.                                                                  0x0408,0x0608,0x1598,0x0c60,0x0460,0x0790,0x0408,0x0408},        // 显示 文文           1
  5.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x2020,0x2010,0x1008,0x0804,
  6.                                      0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        // 显示 I Love You 2
  7.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3020,0x2010,0x1008,0x0804,
  8.                                      0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   3
  9.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3820,0x3010,0x1008,0x0804,
  10.                                      0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   4
  11.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3c20,0x3810,0x1008,0x0804,
  12.                                      0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   5
  13.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3e20,0x3c10,0x1808,0x0804,
  14.                                      0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   6
  15.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3f20,0x3e10,0x1c08,0x0804,
  16.                                      0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   7
  17.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3fa0,0x3f10,0x1e08,0x0c04,
  18.                                      0x1808,0x3010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   8
  19.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3f90,0x1f08,0x0e04,
  20.                                      0x1c08,0x3810,0x3020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   9
  21.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3fd0,0x1f88,0x0f04,
  22.                                      0x1e08,0x3c10,0x3820,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   10
  23.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3ff0,0x1fc8,0x0f84,
  24.                                      0x1f08,0x3e10,0x3c20,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   11
  25.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3ff0,0x1fe8,0x0fc4,
  26.                                      0x1f88,0x3f10,0x3e20,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   12
  27.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3ff0,0x1ff8,0x0fe4,
  28.                                      0x1fc8,0x3f90,0x3f20,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   13
  29.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3ff0,0x1ff8,0x0ff4,
  30.                                      0x1fe8,0x3fd0,0x3fa0,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   14
  31.                                                                 {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3ff0,0x1ff8,0x0ffc,
  32.                                      0x1ff8,0x3ff0,0x3fe0,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc},        //                                   15
  33.                                                                 };
  34. uint code Dis_num[10][3]  = {
  35.                                                                 {0x3ffc,0x300c,0x3ffc},        // 0
  36.                                                                 {0x0000,0x0000,0x3ffc},        // 1
  37.                                                                 {0x31fc,0x318c,0x3f8c}, // 2
  38.                                                                 {0x318c,0x318c,0x3ffc},        // 3
  39.                                                                 {0x3f80,0x0180,0x3ffc}, // 4
  40.                                                                 {0x3f8c,0x318c,0x31fc}, // 5
  41.                                                                 {0x3ffc,0x318c,0x31fc}, // 6
  42.                                                                 {0x3000,0x3000,0x3ffc}, // 7
  43.                                                                 {0x3ffc,0x318c,0x3ffc}, // 8
  44.                                                                 {0x3f8c,0x318c,0x3ffc}  // 9                                                        
  45.                                                     };
  46. uchar code ColScan[16]   =  {0x17,0x13,0x15,0x11,0x16,0x12,0x14,0x10,
  47.                              0x27,0x23,0x25,0x21,0x26,0x22,0x24,0x20};                                            // 74hc138 进行列扫描

  48. void delay10ms(void)   
  49. {
  50.     unsigned char a,b,c;
  51.     for(c=199;c>0;c--)
  52.         for(b=120;b>0;b--)
  53.             for(a=1;a>0;a--);
  54. }

  55. void LineInput(uint dat)                                   // 单列数据显示
  56. {
  57.     uchar n;
  58.     _RCLK = 0;
  59.     for(n=0;n<16;n++)
  60.     {
  61.         _SRCLK = 0;
  62.         _SER  = (dat>>n)&0x01;
  63.         _SRCLK = 1;
  64.     }
  65.     _RCLK = 1;
  66. }

  67. void DisplayTime(void)
  68. {
  69.         uchar m,n,i,a,b;
  70.         static uchar breathe = 255;
  71.         static uchar sign    = 0;                  
  72.         n =        0;
  73.         a = DS1302Read(0x85)&0x0f;                           // 读取小时的个位
  74.         b = (DS1302Read(0x85)&0x70)>>4;                   // 读取小时的十位
  75.         for(i=0;i<3;i++)                                           // 显示小时的十位
  76.         {
  77.         LineInput(0x0000);
  78.         P2 = ColScan[n];
  79.         LineInput(Dis_num[b][i]);
  80.                 n++;
  81.                 m = light;
  82.                 while(m--);                                                   // 亮度调节
  83.         LineInput(0x0000);                                
  84.         }
  85.         n++;                                                                   // 空一行
  86.         for(i=0;i<3;i++)                                           // 显示小时的个位
  87.         {
  88.         LineInput(0x0000);
  89.         P2 = ColScan[n];
  90.         LineInput(Dis_num[a][i]);
  91.                 n++;
  92.                 m = light;
  93.                 while(m--);
  94.         LineInput(0x0000);                                
  95.         }
  96.         for(i=0;i<2;i++)                                           // 显示分割符 呼吸效果
  97.         {
  98.                 LineInput(0x0000);
  99.         P2 = ColScan[n];
  100.         LineInput(0x0660);
  101.                 n++;
  102.                 if(sign == 0)                           // 渐渐变暗
  103.                 {
  104.                         breathe--;        
  105.                         if(breathe == 0)
  106.                         {               
  107.                                 sign = 1;
  108.                         }
  109.                 }
  110.                 else
  111.                 {
  112.                         breathe++;        
  113.                         if(breathe == 255)
  114.                         {
  115.                                 sign = 0;
  116.                         }
  117.                 }
  118.                 m = breathe;
  119.                 while(m--);                                                                                                                        
  120.             LineInput(0x0000);
  121.         }
  122.         a = DS1302Read(0x83)&0x0f;                           // 读取分钟个位
  123.         b = (DS1302Read(0x83)&0x70)>>4;                   // 读取分钟十位
  124.         for(i=0;i<3;i++)                                           // 显示分钟十位
  125.         {
  126.         LineInput(0x0000);
  127.         P2 = ColScan[n];
  128.         LineInput(Dis_num[b][i]);
  129.                 n++;
  130.                 m = light;
  131.                 while(m--);        
  132.         LineInput(0x0000);
  133.         }
  134.         n++;                                                                        // 空一行
  135.         for(i=0;i<3;i++)                                                // 显示分钟个位
  136.         {
  137.         LineInput(0x0000);
  138.         P2 = ColScan[n];
  139.         LineInput(Dis_num[a][i]);
  140.                 n++;
  141.                 m = light;
  142.                 while(m--);
  143.         LineInput(0x0000);                        
  144.         }
  145. }

  146. void TimeSetting(void)
  147. {
  148.         uchar m,n,i,a,b,x;
  149.         if(Key_1==0)                                                  // 按键进入时间设定
  150.         {
  151.                 delay10ms();
  152.                 delay10ms();
  153.                 if(Key_1==0)                                        // 确定按下按键
  154.                 {
  155.                         while(Key_1==0);                           // 松手检测
  156.                         a = DS1302Read(0x85)&0x0f;                                   // 读取小时的个位
  157.                         b = (DS1302Read(0x85)&0x70)>>4;                           // 读取小时的十位
  158.                         x = 10*b+a;                                                                // 化成十进制数
  159.                         while(Key_1==1)                                // 首先设定小时
  160.                         {
  161.                                 n =        0;
  162.                                 for(i=0;i<3;i++)                                           // 显示小时的十位
  163.                                 {
  164.                                 LineInput(0x0000);
  165.                                 P2 = ColScan[n];
  166.                                 LineInput(Dis_num[b][i]);
  167.                                         n++;
  168.                                         m = light;
  169.                                         while(m--);                                                   // 亮度调节
  170.                                 LineInput(0x0000);                                
  171.                                 }
  172.                                 n++;                                                                   // 空一行
  173.                                 for(i=0;i<3;i++)                                           // 显示小时的个位
  174.                                 {
  175.                                 LineInput(0x0000);
  176.                                 P2 = ColScan[n];
  177.                                 LineInput(Dis_num[a][i]);
  178.                                         n++;
  179.                                         m = light;
  180.                                         while(m--);
  181.                                 LineInput(0x0000);                                
  182.                                 }
  183.                                 if(Key_2==0)                                                          // 按下另外一键使小时加一
  184.                                 {
  185.                                         delay10ms();
  186.                                         delay10ms();
  187.                                         if(Key_2==0)
  188.                                         {
  189.                                                 while(Key_2==0);
  190.                                                 x++;
  191.                                                 if(x>23)                                                // 小时的最大值为23
  192.                                                 {
  193.                                                         x = 0;
  194.                                                 }
  195.                                                 a = x%10;
  196.                                                 b = x/10;
  197.                                         }
  198.                                 }
  199.                         }
  200.                         delay10ms();
  201.                         delay10ms();
  202.                         while(Key_1==0);                        // 松手检测
  203.                         x = a+(b<<4);
  204.                         DS1302Write(0x8e,0x00);                // 写保护关
  205.                         DS1302Write(0x84,x);                // 保存更改
  206.                         DS1302Write(0x8e,0xff);                // 开写保护
  207.                         a = DS1302Read(0x83)&0x0f;                                   // 读取分钟的个位
  208.                         b = (DS1302Read(0x83)&0x70)>>4;                           // 读取分钟的十位
  209.                         x = 10*b+a;                                                                // 化成十进制数
  210.                         while(Key_1==1)                                // 然后设定分钟
  211.                         {
  212.                                 n = 9;
  213.                                 for(i=0;i<3;i++)                                           // 显示分钟的十位
  214.                                 {
  215.                                 LineInput(0x0000);
  216.                                 P2 = ColScan[n];
  217.                                 LineInput(Dis_num[b][i]);
  218.                                         n++;
  219.                                         m = light;
  220.                                         while(m--);                                                   // 亮度调节
  221.                                 LineInput(0x0000);                                
  222.                                 }
  223.                                 n++;                                                                   // 空一行
  224.                                 for(i=0;i<3;i++)                                           // 显示分钟的个位
  225.                                 {
  226.                                 LineInput(0x0000);
  227.                                 P2 = ColScan[n];
  228.                                 LineInput(Dis_num[a][i]);
  229.                                         n++;
  230.                                         m = light;
  231.                                         while(m--);
  232.                                 LineInput(0x0000);                                
  233.                                 }
  234.                                 if(Key_2==0)                                                          // 按下另外一键使分钟加一
  235.                                 {
  236.                                         delay10ms();
  237.                                         delay10ms();
  238.                                         if(Key_2==0)
  239.                                         {
  240.                                                 while(Key_2==0);
  241.                                                 x++;
  242.                                                 if(x>59)                                                // 分钟的最大值为23
  243.                                                 {
  244.                                                         x = 0;
  245.                                                 }
  246.                                                 a = x%10;
  247.                                                 b = x/10;
  248.                                         }
  249.                                 }
  250.                         }
  251.                         delay10ms();
  252.                         delay10ms();
  253.                         while(Key_1==0);                        // 松手检测
  254.                         x = a+(b<<4);
  255.                         DS1302Write(0x8e,0x00);                // 写保护关
  256.                         DS1302Write(0x82,x);                // 保存更改
  257.                         DS1302Write(0x8e,0xff);                // 开写保护
  258.                 }
  259.         }        
  260. }

  261. void MyLove(void)
  262. {
  263.         uchar m,i;
  264.         int n;
  265.         for(n=0;n<=256;n++)
  266.         {
  267.                 for(i=0;i<16;i++)
  268.                 {
  269.                 LineInput(0x0000);
  270.                 P2 = ColScan[i];
  271.                         if(i <= n>>4)
  272.                         {
  273.                         LineInput(ILoveWenWen[0][i]|0x8000);
  274.                         }
  275.                         else
  276.                         {
  277.                                 LineInput(ILoveWenWen[0][i]);
  278.                         }
  279.                         m = light;
  280.                         while(m--);
  281.                         LineInput(0x0000);               
  282.                 }
  283.         }
  284.         for(n=256;n>=0;n--)
  285.         {
  286.                 for(i=0;i<16;i++)
  287.                 {
  288.                 LineInput(0x0000);
  289.                 P2 = ColScan[i];
  290.                         if(i >= n>>4)
  291.                         {
  292.                         LineInput(ILoveWenWen[0][i]|0x8001);
  293.                         }
  294.                         else
  295.                         {
  296.                                 LineInput(ILoveWenWen[0][i]|0x8000);
  297.                         }
  298.                         m = light;
  299.                         while(m--);
  300.                         LineInput(0x0000);               
  301.                 }
  302.         }
  303.         for(n=0;n<=1024;n++)
  304.         {
  305.                 for(i=0;i<16;i++)
  306.                 {
  307.                 LineInput(0x0000);
  308.                 P2 = ColScan[i];
  309.                         if((n>>6)>=13)
  310.                         {
  311.                                 LineInput(ILoveWenWen[14][i]);
  312.                         }
  313.                         else
  314.                         {
  315.                                 LineInput(ILoveWenWen[(n>>6)+1][i]);                        
  316.                         }
  317.                         m = light;
  318.                         while(m--);
  319.                         LineInput(0x0000);
  320.                 }
  321.         }
  322. }

复制代码

全部资料下载地址:
程序.zip (139.47 KB, 下载次数: 31)

评分

参与人数 1黑币 +100 收起 理由
admin + 100 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:250010 发表于 2017-11-16 13:30 | 显示全部楼层
能不能加我qq,或者留个qq,想请教请教,主要是没有黑币我qq1821068212
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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