51单片机音乐盒仿真图和代码
时间: 2023-11-22 16:04:30 浏览: 134
以下是一个简单的51单片机音乐盒仿真代码和电路图,你可以根据自己的需求进行修改和优化。
```c
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code music[]={
0x00,0x7F,0x00,0x7F,0x00,0x7F,0x00,0x7F,0x40,0x3F,0x40,0x3F,0x40,0x3F,0x40,0x3F,
0x20,0x5F,0x20,0x5F,0x20,0x5F,0x20,0x5F,0x10,0x6F,0x10,0x6F,0x10,0x6F,0x10,0x6F,
0x08,0x77,0x08,0x77,0x08,0x77,0x08,0x77,0x04,0x7B,0x04,0x7B,0x04,0x7B,0x04,0x7B,
0x02,0x7D,0x02,0x7D,0x02,0x7D,0x02,0x7D,0x01,0x7E,0x01,0x7E,0x01,0x7E,0x01,0x7E,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x3F,0x40,0x3F,0x40,0x3F,0x40,0x3F,
0x20,0x5F,0x20,0x5F,0x20,0x5F,0x20,0x5F,0x10,0x6F,0x10,0x6F,0x10,0x6F,0x10,0x6F,
0x08,0x77,0x08,0x77,0x08,0x77,0x08,0x77,0x04,0x7B,0x04,0x7B,0x04,0x7B,0x04,0x7B,
0x02,0x7D,0x02,0x7D,0x02,0x7D,0x02,0x7D,0x01,0x7E,0x01,0x7E,0x01,0x7E,0x01,0x7E,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x3F,0x40,0x3F,0x40,0x3F,0x40,0x3F,
0x20,0x5F,0x20,0x5F,0x20,0x5F,0x20,0x5F,0x10,0x6F,0x10,0x6F,0x10,0x6F,0x10,0x6F,
0x08,0x77,0x08,0x77,0x08,0x77,0x08,0x77,0x04,0x7B,0x04,0x7B,0x04,0x7B,0x04,0x7B,
0x02,0x7D,0x02,0x7D,0x02,0x7D,0x02,0x7D,0x01,0x7E,0x01,0x7E,0x01,0x7E,0x01,0x7E,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x3F,0x40,0x3F,0x40,0x3F,0x40,0x3F,
0x20,0x5F,0x20,0x5F,0x20,0x5F,0x20,0x5F,0x10,0x6F,0x10,0x6F,0x10,0x6F,0x10,0x6F,
0x08,0x77,0x08,0x77,0x08,0x77,0x08,0x77,0x04,0x7B,0x04,0x7B,0x04,0x7B,0x04,0x7B,
0x02,0x7D,0x02,0x7D,0x02,0x7D,0x02,0x7D,0x01,0x7E,0x01,0x7E,0x01,0x7E,0x01,0x7E
};
uchar code fre[]={
0xfd,0xf5,0xe1,0xd4,0xc9,0xc0,0xb8,0xb0,0xa9,0xa0,0x98,0x91,0x8a,0x84,0x7f,0x78,
0x73,0x6e,0x6a,0x65,0x61,0x5d,0x5a,0x56,0x53,0x50,0x4d,0x4a,0x48,0x45,0x43,0x41,
0x3f,0x3d,0x3b,0x39,0x38,0x36,0x35,0x33,0x32,0x31,0x2f,0x2e,0x2d,0x2c,0x2b,0x2a,
0x29,0x28,0x27,0x26,0x25,0x25,0x24,0x23,0x22,0x22,0x21,0x20,0x20,0x1f,0x1f,0x1e
};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
uchar i,j,k;
while(1)
{
for(i=0;i<80;i++)
{
j=fre[i];
k=music[i];
while(j--)
{
P1=k;
delay(1);
}
}
}
}
```
电路图如下:
![image](https://img-blog.csdn.net/20170223162507447?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYXJlbmF5X2Jsb2c=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/q/80)
阅读全文