标题:
16键单片机电子琴电路图+程序
[打印本页]
作者:
111222QQ
时间:
2018-12-17 21:20
标题:
16键单片机电子琴电路图+程序
电路原理图如下:
22a17d58b6ad1cdd41d2c3e23f9051b.png
(48.59 KB, 下载次数: 15)
下载附件
2018-12-17 21:19 上传
单片机源程序:
/******心形流水灯******/
/**********************/
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table1[]={
0x01,0x02,0x04,0x08,
0x10,0x20,0x40,0x80};
uchar code table2[]={
0x01,0x02,0x04,0x08,
0x10,0x20};
uchar code table3[]={
0x80,0xc0,0xe0,0xf0,
0xf8,0xfc,0xfe,0xff};
uchar code table4[]={
0x00,0x01,0x03,0x07,
0x0f,0x1f,0x3f};
void loudou_0(); //左右流水递增
void loudou_1(); //左右流水
void loudou_2(); //左右流水
void shanshuo(); //加减速闪烁
void quanliang(); //全量
void banshan(); //左右半闪
void liushui_vleft(); //逆时针加速转
void liushui_vright(); //顺时针加速转
void liushui_left(); //逆时针
void liushui_right(); //顺时针
void delay(uint z)
{
uint i,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
void main()
{
while(1)
{
loudou_0();
loudou_1();
loudou_2();
loudou_0();
banshan();
quanliang();
shanshuo();
liushui_right();
liushui_vright();
liushui_left();
liushui_vleft();
}
}
/**********************/
/*半闪*/
void banshan()
{
uint x;
for(x=0;x<=3;x++)
{
P1=0xff;
P3=0x00;
delay(1000);
P1=0x81;
P3=0x3f;
delay(1000);
}
}
/**********************/
/**********************/
/*流水左右分往下*/
void loudou_0()
{
uint i,j,z;
for(z=1;z<=8;z++)
{
i=1;
for(j=6;j>=z;j--)
{
P1=(table1[i])|(table3[z-1]);
P3=(table2[j-1])|(table4[z-1]);
delay(800);
i++;
}
}
}
/**********************/
/**********************/
/*流水左右分往下*/
void loudou_2()
{
uint i,j,z;
for(z=0;z<=1;z++)
{
i=1;
P1=0x01;
delay(600);
for(j=6;j>=1;j--)
{
P1=table1[i];
P3=table2[j-1];
delay(600);
i++;
}
P3=0x00;
P1=0x00;
P1=0x80;
delay(600);
}
}
/**********************/
/**********************/
/*流水左右分往下*/
void loudou_1()
{
uint i,j,z;
for(z=0;z<=2;z++)
{
i=1;
P1=0xfe;
delay(600);
for(j=6;j>=1;j--)
{
P1=~table1[i];
P3=~table2[j-1];
delay(600);
i++;
}
P3=0xff;
P1=0xff;
P1=0x7f;
delay(600);
}
}
/**********************/
/**********************/
/*流水右转*/
void liushui_right()
{
uint i,j;
// for(x=0;x<=1;x++)
// {
for(j=6;j>=1;j--)
{
P3=~table2[j-1];
P1=0xff;
delay(800);
}
P3=0x00;
for(i=8;i>=1;i--)
{
P1=~table1[i-1];
P3=0xff;
delay(800);
}
P1=0x00;
// }
}
/**********************/
/**********************/
/*流水左转*/
void liushui_left()
{
uint i,j;
// for(x=0;x<=1;x++)
// {
for(i=0;i<=7;i++)
{
P1=~table1[i];
P3=0xff;
delay(800);
}
P1=0x00;
for(j=0;j<=5;j++)
{
P3=~table2[j];
P1=0xff;
delay(800);
}
P3=0x00;
// }
}
/**********************/
/**********************/
/*流水加速*/
void liushui_vleft()
{
uint i,j,y;
// for(x=0;x<=1;x++)
// {
y=900;
for(i=0;i<=7;i++)
{
P1=~table1[i];
P3=0xff;
delay(y);
y=y-100;
}
P1=0x00;
for(j=0;j<=5;j++)
{
P3=~table2[j];
P1=0xff;
delay(y);
y=y+150;
}
P3=0x00;
// }
}
/**********************/
/**********************/
/*流水加速*/
void liushui_vright()
{
uint i,j,y;
// for(x=0;x<=1;x++)
// {
y=900;
for(j=6;j>=1;j--)
{
P3=~table2[j-1];
P1=0xff;
delay(y);
y=y-100;
}
P3=0x00;
for(i=8;i>=1;i--)
{
P1=~table1[i-1];
P3=0xff;
delay(y);
y=y+150;
}
P1=0x00;
// }
}
/**********************/
void quanliang()
{
P1=0xff;
P3=0xff;
delay(1000);
}
/**********************/
void shanshuo()
{
uint i,j=1000;
uchar aa=0xff;
for(i=20;i>0;i--)
{
P1=aa;
P3=aa;
delay(j);
j=j-50;
aa=~aa;
}
for(i=20;i>0;i--)
{
P1=aa;
P3=aa;
delay(j);
j=j+50;
aa=~aa;
}
}
/**********************/
复制代码
全部资料51hei下载地址:
1.rar
(737 Bytes, 下载次数: 32)
2018-12-17 21:19 上传
点击文件名下载附件
hex文件
下载积分: 黑币 -5
作者:
admin
时间:
2018-12-17 22:39
补全仿真文件或者详细说明一下电路连接即可获得100+黑币
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1