51单片机音频显示
部分源码,详细源码和原理图见附件
单片机源程序:
- #include "Led.h"
- uint code ILoveWenWen[15][16] = {
- {0x0810,0x0c10,0x2b20,0x18c0,0x08c0,0x0f20,0x0810,0x0810,
- 0x0408,0x0608,0x1598,0x0c60,0x0460,0x0790,0x0408,0x0408}, // 显示 文文 1
- {0x4002,0x7ffe,0x4002,0x1fc0,0x2020,0x2010,0x1008,0x0804,
- 0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 显示 I Love You 2
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3020,0x2010,0x1008,0x0804,
- 0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 3
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3820,0x3010,0x1008,0x0804,
- 0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 4
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3c20,0x3810,0x1008,0x0804,
- 0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 5
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3e20,0x3c10,0x1808,0x0804,
- 0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 6
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3f20,0x3e10,0x1c08,0x0804,
- 0x1008,0x2010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 7
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3fa0,0x3f10,0x1e08,0x0c04,
- 0x1808,0x3010,0x2020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 8
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3f90,0x1f08,0x0e04,
- 0x1c08,0x3810,0x3020,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 9
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3fd0,0x1f88,0x0f04,
- 0x1e08,0x3c10,0x3820,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 10
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3ff0,0x1fc8,0x0f84,
- 0x1f08,0x3e10,0x3c20,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 11
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3ff0,0x1fe8,0x0fc4,
- 0x1f88,0x3f10,0x3e20,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 12
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3ff0,0x1ff8,0x0fe4,
- 0x1fc8,0x3f90,0x3f20,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 13
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3ff0,0x1ff8,0x0ff4,
- 0x1fe8,0x3fd0,0x3fa0,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 14
- {0x4002,0x7ffe,0x4002,0x1fc0,0x3fe0,0x3ff0,0x1ff8,0x0ffc,
- 0x1ff8,0x3ff0,0x3fe0,0x1fc0,0x7ffc,0x0002,0x0002,0x7ffc}, // 15
- };
- uint code Dis_num[10][3] = {
- {0x3ffc,0x300c,0x3ffc}, // 0
- {0x0000,0x0000,0x3ffc}, // 1
- {0x31fc,0x318c,0x3f8c}, // 2
- {0x318c,0x318c,0x3ffc}, // 3
- {0x3f80,0x0180,0x3ffc}, // 4
- {0x3f8c,0x318c,0x31fc}, // 5
- {0x3ffc,0x318c,0x31fc}, // 6
- {0x3000,0x3000,0x3ffc}, // 7
- {0x3ffc,0x318c,0x3ffc}, // 8
- {0x3f8c,0x318c,0x3ffc} // 9
- };
- uchar code ColScan[16] = {0x17,0x13,0x15,0x11,0x16,0x12,0x14,0x10,
- 0x27,0x23,0x25,0x21,0x26,0x22,0x24,0x20}; // 74hc138 进行列扫描
- void delay10ms(void)
- {
- unsigned char a,b,c;
- for(c=199;c>0;c--)
- for(b=120;b>0;b--)
- for(a=1;a>0;a--);
- }
- void LineInput(uint dat) // 单列数据显示
- {
- uchar n;
- _RCLK = 0;
- for(n=0;n<16;n++)
- {
- _SRCLK = 0;
- _SER = (dat>>n)&0x01;
- _SRCLK = 1;
- }
- _RCLK = 1;
- }
- void DisplayTime(void)
- {
- uchar m,n,i,a,b;
- static uchar breathe = 255;
- static uchar sign = 0;
- n = 0;
- a = DS1302Read(0x85)&0x0f; // 读取小时的个位
- b = (DS1302Read(0x85)&0x70)>>4; // 读取小时的十位
- for(i=0;i<3;i++) // 显示小时的十位
- {
- LineInput(0x0000);
- P2 = ColScan[n];
- LineInput(Dis_num[b][i]);
- n++;
- m = light;
- while(m--); // 亮度调节
- LineInput(0x0000);
- }
- n++; // 空一行
- for(i=0;i<3;i++) // 显示小时的个位
- {
- LineInput(0x0000);
- P2 = ColScan[n];
- LineInput(Dis_num[a][i]);
- n++;
- m = light;
- while(m--);
- LineInput(0x0000);
- }
- for(i=0;i<2;i++) // 显示分割符 呼吸效果
- {
- LineInput(0x0000);
- P2 = ColScan[n];
- LineInput(0x0660);
- n++;
- if(sign == 0) // 渐渐变暗
- {
- breathe--;
- if(breathe == 0)
- {
- sign = 1;
- }
- }
- else
- {
- breathe++;
- if(breathe == 255)
- {
- sign = 0;
- }
- }
- m = breathe;
- while(m--);
- LineInput(0x0000);
- }
- a = DS1302Read(0x83)&0x0f; // 读取分钟个位
- b = (DS1302Read(0x83)&0x70)>>4; // 读取分钟十位
- for(i=0;i<3;i++) // 显示分钟十位
- {
- LineInput(0x0000);
- P2 = ColScan[n];
- LineInput(Dis_num[b][i]);
- n++;
- m = light;
- while(m--);
- LineInput(0x0000);
- }
- n++; // 空一行
- for(i=0;i<3;i++) // 显示分钟个位
- {
- LineInput(0x0000);
- P2 = ColScan[n];
- LineInput(Dis_num[a][i]);
- n++;
- m = light;
- while(m--);
- LineInput(0x0000);
- }
- }
- void TimeSetting(void)
- {
- uchar m,n,i,a,b,x;
- if(Key_1==0) // 按键进入时间设定
- {
- delay10ms();
- delay10ms();
- if(Key_1==0) // 确定按下按键
- {
- while(Key_1==0); // 松手检测
- a = DS1302Read(0x85)&0x0f; // 读取小时的个位
- b = (DS1302Read(0x85)&0x70)>>4; // 读取小时的十位
- x = 10*b+a; // 化成十进制数
- while(Key_1==1) // 首先设定小时
- {
- n = 0;
- for(i=0;i<3;i++) // 显示小时的十位
- {
- LineInput(0x0000);
- P2 = ColScan[n];
- LineInput(Dis_num[b][i]);
- n++;
- m = light;
- while(m--); // 亮度调节
- LineInput(0x0000);
- }
- n++; // 空一行
- for(i=0;i<3;i++) // 显示小时的个位
- {
- LineInput(0x0000);
- P2 = ColScan[n];
- LineInput(Dis_num[a][i]);
- n++;
- m = light;
- while(m--);
- LineInput(0x0000);
- }
- if(Key_2==0) // 按下另外一键使小时加一
- {
- delay10ms();
- delay10ms();
- if(Key_2==0)
- {
- while(Key_2==0);
- x++;
- if(x>23) // 小时的最大值为23
- {
- x = 0;
- }
- a = x%10;
- b = x/10;
- }
- }
- }
- delay10ms();
- delay10ms();
- while(Key_1==0); // 松手检测
- x = a+(b<<4);
- DS1302Write(0x8e,0x00); // 写保护关
- DS1302Write(0x84,x); // 保存更改
- DS1302Write(0x8e,0xff); // 开写保护
- a = DS1302Read(0x83)&0x0f; // 读取分钟的个位
- b = (DS1302Read(0x83)&0x70)>>4; // 读取分钟的十位
- x = 10*b+a; // 化成十进制数
- while(Key_1==1) // 然后设定分钟
- {
- n = 9;
- for(i=0;i<3;i++) // 显示分钟的十位
- {
- LineInput(0x0000);
- P2 = ColScan[n];
- LineInput(Dis_num[b][i]);
- n++;
- m = light;
- while(m--); // 亮度调节
- LineInput(0x0000);
- }
- n++; // 空一行
- for(i=0;i<3;i++) // 显示分钟的个位
- {
- LineInput(0x0000);
- P2 = ColScan[n];
- LineInput(Dis_num[a][i]);
- n++;
- m = light;
- while(m--);
- LineInput(0x0000);
- }
- if(Key_2==0) // 按下另外一键使分钟加一
- {
- delay10ms();
- delay10ms();
- if(Key_2==0)
- {
- while(Key_2==0);
- x++;
- if(x>59) // 分钟的最大值为23
- {
- x = 0;
- }
- a = x%10;
- b = x/10;
- }
- }
- }
- delay10ms();
- delay10ms();
- while(Key_1==0); // 松手检测
- x = a+(b<<4);
- DS1302Write(0x8e,0x00); // 写保护关
- DS1302Write(0x82,x); // 保存更改
- DS1302Write(0x8e,0xff); // 开写保护
- }
- }
- }
- void MyLove(void)
- {
- uchar m,i;
- int n;
- for(n=0;n<=256;n++)
- {
- for(i=0;i<16;i++)
- {
- LineInput(0x0000);
- P2 = ColScan[i];
- if(i <= n>>4)
- {
- LineInput(ILoveWenWen[0][i]|0x8000);
- }
- else
- {
- LineInput(ILoveWenWen[0][i]);
- }
- m = light;
- while(m--);
- LineInput(0x0000);
- }
- }
- for(n=256;n>=0;n--)
- {
- for(i=0;i<16;i++)
- {
- LineInput(0x0000);
- P2 = ColScan[i];
- if(i >= n>>4)
- {
- LineInput(ILoveWenWen[0][i]|0x8001);
- }
- else
- {
- LineInput(ILoveWenWen[0][i]|0x8000);
- }
- m = light;
- while(m--);
- LineInput(0x0000);
- }
- }
- for(n=0;n<=1024;n++)
- {
- for(i=0;i<16;i++)
- {
- LineInput(0x0000);
- P2 = ColScan[i];
- if((n>>6)>=13)
- {
- LineInput(ILoveWenWen[14][i]);
- }
- else
- {
- LineInput(ILoveWenWen[(n>>6)+1][i]);
- }
- m = light;
- while(m--);
- LineInput(0x0000);
- }
- }
- }
复制代码
全部资料下载地址:
程序.zip
(139.47 KB, 下载次数: 31)
原理图.zip
(106.39 KB, 下载次数: 38)
|