历史上的今天
今天是:2024年10月23日(星期三)
2019年10月23日 | 基于51单片机的简易电子琴源码
2019-10-23 来源:51hei
用到了数码管显示,矩阵键盘,蜂鸣器,适合新接触51的朋友们,只是程序,一看就明白
c语言程序
单片机源程序如下:
/*********************************************************************************************
程序名: 8键电子琴C程序
编写人: 杜洋
编写时间: 2009年5月18日
硬件支持: STC系列单片机 12MHz
接口说明:
修改日志:
NO.1-
/*********************************************************************************************
说明:
/*********************************************************************************************/
#include #define uchar unsigned char #define KEY P3 #define LED P1 sbit dula=P2^6; //段选信号的锁存器控制 sbit wela=P2^7; //位选信号的锁存器控制 sbit SPEAKER = P2^3; bit flag; //标志音乐输出脚电平的高低 uchar ptr = 0x00; //取音符 uchar high; //计数器高位 uchar low; //计数器低位 unsigned char KeyValue; unsigned char KeyValue2; unsigned char STH0; unsigned char STL0; unsigned char i; unsigned char lednum=0; /*unsigned int code tab[]={ 64021,64103,64260,64400,//低音3开始 64524,64580,64684,64777, 64820,64898,64968,65030, 65058,65110,65157,65178 }; */ unsigned int code tab[]={ /*10000,64103,64260,64400,//低音3开始 */ 64580,64633,64684,64732, 64777,64820,64860,64898, 64934,64968,64994,65030 }; unsigned int code music[] ={ 4 ,6 ,8, 9 ,11,13,15 }; unsigned char code music2[] = { // 1 _ 1_ 1 .5 0xFC,0x44,0x7F, 0xFC,0x44,0x7F, 0xFC,0x44,0xFF, 0xFA,0x68,0xFF, // 3 _ 3_ 3 1 0xFD,0x23,0x7F, 0xFD,0x23,0x7F, 0xFD,0x23,0xFF, 0xFC,0x44,0xFF, // 1_ 3_ 5 5 0xFC,0x44,0x7F, 0xFD,0x23,0x7F, 0xFD,0x82,0xFF, 0xFD,0x82,0xFF, // 4_ 3_ 2 - 0xFD,0x23,0x7F, 0xFD,0x23,0x7F, 0xFC,0xAC,0xFF, 0xFF,0xFF,0xFF, // 2_ 3_ 4 4 0xFC,0xAC,0x7F, 0xFD,0x23,0x7F, 0xFD,0x34,0xFF, 0xFD,0x34,0xFF, // 3_ 2_ 3 1 0xFD,0x23,0x7F, 0xFC,0xAC,0x7F, 0xFD,0x23,0xFF, 0xFC,0x44,0xFF, // 1_ 3_ 2 .5 0xFC,0x44,0x7F, 0xFD,0x23,0x7F, 0xFC,0xAC,0xFF, 0xFA,0x68,0xFF, // .7_ 2_ 1 - 0xFC,0x0C,0x7F, 0xFC,0xAC,0x7F, 0xFC,0x44,0xFF, 0xFF,0xFF,0xFF, 0x00//结束 }; unsigned char code music_num[] ={ 1,20,1,20,1,1,5,5, 3,20,3,20,3,3,1,1, 1,20,3,20,5,5,5,5, 4,20,3,20,2,19,2,19, 2,20,3,20,4,4,4,4, 3,20,2,20,3,3,1,1, 1,20,3,20,2,2,5,5, 7,20,2,20,1,19,1,19} ; unsigned int code key_num[] ={1,1,2,2,3,4,4,5,5,6,6,7 } ; unsigned int code key2_num[] ={0,16,1,16,2,3,16,4,16,5,16,6 } ; /*unsigned int code twotiger[] ={ 1,2,3,1,1,2,3,1,3,4,5,5,3,4,5,5,5,6,5,4,3,3,1,1,5,6, 5,4,3,3,1,1,2,2,5,5,1,1,0,0,2,2,5,5,1,1,0,0 }; unsigned int code twotiger2[] = { 1,1,5,5,6,6,5,5,4,4,3,3,2,2,1,1 ,5 ,5,4,4,3,3,2,2,5 ,5,4,4,3,3,2,2,1,1,5,5,6,6,5,5,4,4,3,3,2,2,1,1 }; */ unsigned char code num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71, 0x00,0x76,0x40,0x40,0x08}; //0-F,,,19,,20的码表 unsigned char code numb[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; unsigned char i3; //0-7数码管 void Init(void); //初始化函数 void DelayMs(unsigned int time); //毫秒级延时函数 /*void Delay (unsigned int a);*/ void newmusic(void); void keyy(void); void led8(void); void main(void){ TMOD=0x01; ET0=1; EA=1; KEY = 0xf0; LED=0xff; while(1){ KeyValue=15; if(KEY != 0xf0){ DelayMs(10);//?óê±10ms??DD???? if(KEY!=0xf0)//?ù′??ì2a?ü?ìê?·?°′?? { KEY=0X0F; switch(KEY) { case(0X0e): KeyValue=0;LED=0xfe;break; case(0X0d): KeyValue=1;LED=0xfd;break; case(0X0b): KeyValue=2;LED=0xfb;break; case(0X07): KeyValue=3;LED=0xf7;break; } //2aê?DD KEY=0XF0; switch(KEY) { case(0Xe0): KeyValue=KeyValue;break; case(0Xd0): KeyValue=KeyValue+4;break; case(0Xb0): KeyValue=KeyValue+8;break; case(0X70): KeyValue=KeyValue+12;break; } } } if( KeyValue<12){ high=tab[KeyValue]/256; low=tab[KeyValue]%256; TR0=1; led8(); } else if(KeyValue==12) {KeyValue=0; while(KeyValue!=12){ keyy(); if (KeyValue2==15){KeyValue=0;break;} else if (KeyValue2==0){break;} high=tab[KeyValue]/256; low=tab[KeyValue]%256; TR0=1; DelayMs(160); led8(); SPEAKER = 1; TR0=0; DelayMs(600);
史海拾趣
|
本人刚学VB,在写一个串口数据采集大的小软件,刚开始就遇到了问题,以下代码,我在调试时都正常运行,能正确获得返回数据,可是生成exe文件后,程序却没反应,也没有错误信息出现!就是没有数据,求高手帮忙! Public gSend As Boolean &nb ...… 查看全部问答> |
|
wince5.0中如何捕捉鼠标位置,实现全屏书写,实时显示书写的轨迹? wince5.0中如何捕捉鼠标位置,实现全屏书写,实时显示书写的轨迹?在自己建立的窗口中已经可以书写,显示轨迹了。但是出来自己创建的窗口就没办法书写了。困恼了很久了,高手、专家指点啊。最好能给点实例代码参考 邮箱echenxi@163.com … 查看全部问答> |
|
我现在在测试zigbee加密问题,协调器不使用加密,而路由器使用机密的时候,发现路由加入不了网络,不知到为什么。请哪位高手指教一下。 哦,我加密的时候只在f8Config.cfg上面把DSECURE设成1.… 查看全部问答> |
|
最近朋友让我给他弄一个市电检测电路,用在工业上的,要求在市电200V以上的时候输出一个脉冲,并且脉冲宽度在有限的时间内可调,各位大虾有没有做过类似电路的?望指点一二。以下是我个人设计的电路,在我个人的系统中测试的结果还算理想,经过几天 ...… 查看全部问答> |
|
有两个待测电压A,B, B的功率比A大;两块g2553; 现象:测电压A,用万用表可以测得出,一接到板子上用g2553A测就不行;换上g2553B就行了.程序是一样。 测电压B,用用万用表跟g2553A B都可以测得出。 ...… 查看全部问答> |




