#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
//sbit KEY1=P3^2;
//sbit KEY2=P3^3;
//char count1;
//char count2;
uchar code anjian[]=
{0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xc0};
uint code T[]=
{63628,63835,64021,64103,64260,64400,64463,64524,64580,64684,64777,64820,64898,64968,65000,65030};
sbit speaker=P3^0;
uchar KEY;
//char count1;
//char count2;
void saomiao()
{
uchar n,k;
P1=0x0F;
n=P1^0x0F;
switch(n)
{
case 1:k=0;break;
case 2:k=1;break;
case 4:k=2;break;
case 8:k=3;break;
default:return;
}
P1=0xF0;
n=(P1>>4)^0x0F;
switch(n)
{
case 1:k+=0;break;
case 2:k+=4;break;
case 4:k+=8;break;
case 8:k+=12;break;
default:return;
}
KEY=k;
}
void play() interrupt 1
{
TH0=T[KEY]/256;
TL0=T[KEY]%256;
speaker=~speaker;
}
void main()
{
/*uchar x;
count1=0;
count2=1;
EA=1://开总中断
EX0=1;//开外部中断0
IT0=1;//外部中断0下降沿触发方式
EX1=1;//开外部中断1
IT1=1;//外部中断1下降沿触发方式
TMOD=0x01;//定时器0工作在方式1
TH0=0;
TL0=0;
ET0=1;*/
TMOD=0x0l;
IE=0x82;
while(1)
{
P1=0xF0;
if(P1!=0xF0)
{
saomiao();
P0=anjian[KEY];
TR0=1;
}
else
{
TR0=0;
}
}
}
|