用51单片机实现简单电子琴音乐播放
利用51单片机控制模拟音乐播放器,通过程序设计将不同音调转化成二进制频率信号发出,实现简单电子琴音乐播放。具体实现包括按键扫描、光栅音调计算、PWM波发生及输出等。代码示例如下:
include
sbit BUZZ = P1^6;
sbit KEY_IN_1 = P2^4;
sbit KEY_IN_2 = P2^5;
sbit KEY_IN_3 = P2^6;
sbit KEY_IN_4 = P2^7;
sbit KEY_OUT_1 = P2^3;
sbit KEY_OUT_2 = P2^2;
sbit KEY_OUT_3 = P2^1;
sbit KEY_OUT_4 = P2^0;
unsigned int code NoteReload[] = { 65536 - (11059200/12) / (5232), 65536 - (11059200/12) / (5872), 65536 - (11059200/12) / (6592), 65536 - (11059200/12) / (6982), 65536 - (11059200/12) / (7842), 65536 - (11059200/12) / (8802), 65536 - (11059200/12) / (988*2) };
用户评论