求助!!单片机电子琴
帮忙看看下面有错吗??硬件咋连??还有中断咋用?
/*单片机c语言
电子琴
1应用中断
2键盘检测(整体键盘检测)
3蜂鸣器原理掌握
*/
//声明部分
#include <reg52.h>
#define unint unsigned int
#define unchar unsigned char
sbit keyport= P1;
sbit sound =P0^1; //蜂鸣器j45
unchar keyvalue;
unchar music[]={63628,63835,64021,64103,64260,64400,64524,64580,64684,64777,64820,64898,64968,65030,65058,65110,65157,65178,65217,65252,65283};
/*code unint music0 [8]={0xF8,0xF8,0xF9,0xFA,0xFA,0xFA,0xFB,0xFB};
code unint music1 [8]={0x8C,0xF3,0x5B,0xB8,0x15,0x67,0xB9,0x04}; */
unchar keyvalue;
unchar MUSICTH0;
unchar MUSICTL0;
unchar dat;
void delay(); //
//键盘检测函数
void keyscan()
{
if (keyport!=0xff)
{
delay();
if(keyport!=0xff)
{
keyvalue=keyport;
while(keyport!=0xff);
switch (keyvalue)
{
case 0xfe: dat=7;break;
case 0xfd: dat=1;break;
case 0xfb: dat=0;break;
case 0xf7: dat=3;break;
case 0x7f: dat=4;break;
case 0xbf: dat=5;break;
case 0xdf: dat=6;break;
case 0xef: dat=2;break;
default: dat=8;break;
}
MUSICTH0=music[dat]/256;
MUSICTL0=music[dat]%256;
TR0=1;
}
}
}
//按键处理函数
/*void keyproc()
{
MUSICTH0=music[dat]/256;
MUSICTL0=music[dat]%256;
TR0=1;
} */
void delay()
{
unint i,j;
for(i=5;i>0;i--)
for(j=110;j>0;j--);
}
//主函数
void main ()
{
TMOD=0x01;
ET0=1;
TR0=0;
EA=1;
while(1)
{
keyscan();
}
}
//中断判断子函数
void time0 ()interrupt 1
{
sound=!sound;
TH0=MUSICTH0;//重新装入初值
TL0=MUSICTL0;
}
帮忙看看下面有错吗??硬件咋连??
还有中断咋用?