//主文件
#include "common.h"
uint code xSound[]={63624,63832,64019,64104,64260,64399,64523};
uchar keyValue[][2]={{0xfe,0},{0xfd,1},{0xfb,2},{0xf7,3},{0xef,4},{0xdf,5},{0xbf,6},};
uchar x;
sbit sound=P3^0;
void T0_Init()
{
TMOD=0X01;
ET0=1;
EA=1;
}
void main()
{
uchar keyS,i;
T0_Init();
while(1)
{
keyS=P1;
if(keyS!=0xff)
{
for(i=0;i<7;i++)
{
if(keyS==keyValue[i][0])
{
x=keyValue[i][1];
TH0=xSound[x]/256;
TL0=xSound[x]%256;
TR0=1;
while(P1!=0xff);
TR0=0;
}
}
}
}
}
void Timer0() interrupt 1
{
TH0=xSound[x]/256;
TL0=xSound[x]%256;
sound=!sound;
}
//common.c文件
#include "common.h"
void delayms(uint i)
{
uint j;
for(;i>0;i--)
for(j=120;j>0;j--)
;
}
|