#include <AT89X51.H>
void key1();
unsigned char temp;
unsigned char key;
unsigned char i;
unsigned char j;
unsigned char STH0;
unsigned char STL0;
unsigned char dis;
unsigned int code tab[]=
{64021,64103,64260,64400,
64524,64580,64684,64777,
64820,64898,64968,65030,
65058,65110,65157,65178};
unsigned char code table[]= //共阳极
{ 0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e,
0xbf};
void main(void){
TMOD=0x01;
ET0=1;
EA=1;
while(1){P0=table[dis];
dis=key;
P3=0xff;
key1();
}
}
void t0(void) interrupt 1 using 0 { //定时器T0中断服务函数
TH0=STH0;
TL0=STL0;
P1_0=~P1_0; //产生方波
}
void key1()
{ P3_4=0;
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f) { //从第一行开始扫描键盘
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f){
temp=P3;
temp=temp & 0x0f;
switch(temp){
case 0x0e:
key=0;
break;
case 0x0d:
key=1;
break;
case 0x0b:
key=2;
break;
case 0x07:
key=3;
break;
}
temp=P3;
P1_0=~P1_0;
STH0=tab[key]/256; //计算音符对应的定时器计数值
STL0=tab[key]%256;
TR0=1;
temp=temp & 0x0f;
while(temp!=0x0f){
temp=P3;
temp=temp & 0x0f;
}
TR0=0;
}
}
P3=0xff;
P3_5=0;
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f){ //扫描键盘第二行
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f){
temp=P3;
temp=temp & 0x0f;
switch(temp){
case 0x0e:
key=4;
break;
case 0x0d:
key=5;
break;
case 0x0b:
key=6;
break;
case 0x07:
key=7;
break;
}
temp=P3;
P1_0=~P1_0;
STH0=tab[key]/256;
STL0=tab[key]%256;
TR0=1;
temp=temp & 0x0f;
while(temp!=0x0f){
temp=P3;
temp=temp & 0x0f;
}
TR0=0;
}
}
P3=0xff;
P3_6=0;
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f){ //扫描键盘第三行
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f){
temp=P3;
temp=temp & 0x0f;
switch(temp){
case 0x0e:
key=8;
break;
case 0x0d:
key=9;
break;
case 0x0b:
key=10;
break;
case 0x07:
key=11;
break;
}
temp=P3;
P1_0=~P1_0;
STH0=tab[key]/256;
STL0=tab[key]%256;
TR0=1;
temp=temp & 0x0f;
while(temp!=0x0f){
temp=P3;
temp=temp & 0x0f;
}
TR0=0;
}
}
P3=0xff;
P3_7=0;
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f){ //扫描键盘第四行
for(i=50;i>0;i--)
for(j=200;j>0;j--);
temp=P3;
temp=temp & 0x0f;
if (temp!=0x0f){
temp=P3;
temp=temp & 0x0f;
switch(temp){
case 0x0e:
key=12;
break;
case 0x0d:
key=13;
break;
case 0x0b:
key=14;
break;
case 0x07:
key=15;
break;
}
temp=P3;
P1_0=~P1_0;
STH0=tab[key]/256;
STL0=tab[key]%256;
TR0=1;
temp=temp & 0x0f;
while(temp!=0x0f){
temp=P3;
temp=temp & 0x0f;
}
TR0=0;
}
} }
dianziqin.rar_电子琴
版权申诉
183 浏览量
2022-09-23
16:34:52
上传
评论
收藏 104KB RAR 举报
钱亚锋
- 粉丝: 88
- 资源: 1万+
最新资源
- 基于QT的地图可视化桌面系统后台数据库为MySQL5.7源码.zip
- 基于simulink的PLL锁相环系统仿真【包括模型,文档,参考文献,操作步骤】
- 基于EM-GMM模型的目标跟踪和异常行为检测matlab仿真【包括程序,注释,参考文献,操作步骤,说明文档】
- 2109010044_胡晨燕_选课管理数据库设计与实现.prj
- 帕鲁介绍的PPT备份没什么好下的
- demo1-202405
- 两种方式修改Intel网卡MAC地址
- 服务器搭建所需资源:static文件夹
- Vue02的源码学习资料
- Python 程序语言设计模式思路-行为型模式:访问者模式:在不改变被访问对象结构的情况下,定义对其元素的新操作
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈