具体笔记参考我的Notion:
Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
这里贴一个代码,详细笔记见我的Notion
具体实现代码:
#include "reg51.h"
sbit P2_0=P2^0;
unsigned char code TABLE[]={0x42,0x82,0x82,0x82,0x84,0x02,0x72,
0x62,0x72,0x62,0x52,0x48,
0x0B2,0x0B2,0x0B2,0x0B2,0x0B4,0x02,0x0A2,
0x12,0x0A2,0x0D2,0x92,0x88,
0x82,0x0B2,0x0B2,0x0A2,0x84,0x02,0x72,
0x62,0x72,0x62,0x52,0x44,0x02,0x12,
0x12,0x62,0x62,0x52,0x44,0x02,0x82,
0x72,0x62,0x52,0x32,0x48,
0x72,0x62,0x52,0x32,0x48,0x00};
unsigned int code TABLE1[]={64021,64103,64260,64400, 64524,64580,64684,64777, 64820,64898,64968,65030, 64934} ;
unsigned char th0_temp,tl0_temp;
void SING(unsigned char hi);
void DELAY(unsigned char lo);
main()
{
unsigned char i,hi,lo,coute;
TMOD=0X01;
ET0=1;
EA=1;
TR0=1;
while(1)
{
P2_0=1;
coute=0;
while(TABLE[coute]!=0)
{
i=TABLE[coute];
coute++;
lo=i&0x0f;
hi=(i&0xf0)>>4;
if(hi>0)
SING(hi);
else
TR0=0;
DELAY(lo);
}
}
}
void SING(unsigned char hi)
{
th0_temp=(TABLE1[hi-1]/256);
TH0=th0_temp;
tl0_temp=(TABLE1[hi-1]%256);
TL0=tl0_temp;
TR0=1;
}
void DELAY(unsigned char lo)
{
unsigned char temp1,temp2;
do
{
for(temp1=0;temp1<150;temp1++)
for(temp2=0;temp2<200;temp2++);
}while(lo--);
}
void INTT0() interrupt 1 //定时器0中断函数
{
TH0=th0_temp;
TL0=tl0_temp;
P2_0=~P2_0;
}