#include\r\n#include\r\n//本例采用89C52,晶振为11.0592MHZ\r\n//关于如何编制音乐代码,其实十分简单,各位可以看以下代码.\r\n//频率
常数即音乐术语中的音调,而
节拍常数即音乐术语中的多少拍\r\n//所以拿出谱子,试探编吧!\r\nsbitBeep=P1^5\r\n\r\nunsignedcharn=0//n为节拍常数变量\r\nunsignedcharcodemusic_tab[]={\r\n0x18,0x30,0x1C,0x10,//格式为:频率常数,节拍常数,频率常数,节拍常数,\r\n0x20,0x40,0x1C,0x10,\r\n0x18,0x10,0x20,0x10,\r\n0x1C,0x10,0x18,0x40,\r\n0x1C,0x20,0x20,0x20,\r\n0x1C,0x20,0x18,0x20,\r\n0x20,0x80,0xFF,0x20,\r\n0x30,0x1C,0x10,0x18,\r\n0x20,0x15,0x20,0x1C,\r\n0x20,0x20,0x20,0x26,\r\n0x40,0x20,0x20,0x2B,\r\n0x20,0x26,0x20,0x20,\r\n0x20,0x30,0x80,0xFF,\r\n0x20,0x20,0x1C,0x10,\r\n0x18,0x10,0x20,0x20,\r\n0x26,0x20,0x2B,0x20,\r\n0x30,0x20,0x2B,0x40,\r\n0x20,0x20,0x1C,0x10,\r\n0x18,0x10,0x20,0x20,\r\n0x26,0x20,0x2B,0x20,\r\n0x30,0x20,0x2B,0x40,\r\n0x20,0x30,0x1C,0x10,\r\n0x18,0x20,0x15,0x20,\r\n0x1C,0x20,0x20,0x20,\r\n0x26,0x40,0x20,0x20,\r\n0x2B,0x20,0x26,0x20,\r\n0x20,0x20,0x30,0x80,\r\n0x20,0x30,0x1C,0x10,\r\n0x20,0x10,0x1C,0x10,\r\n0x20,0x20,0x26,0x20,\r\n0x2B,0x20,0x30,0x20,\r\n0x2B,0x40,0x20,0x15,\r\n0x1F,0x05,0x20,0x10,\r\n0x1C,0x10,0x20,0x20,\r\n0x26,0x20,0x2B,0x20,\r\n0x30,0x20,0x2B,0x40,\r\n0x20,0x30,0x1C,0x10,\r\n0x18,0x20,0x15,0x20,\r\n0x1C,0x20,0x20,0x20,\r\n0x26,0x40,0x20,0x20,\r\n0x2B,0x20,0x26,0x20,\r\n0x20,0x20,0x30,0x30,\r\n0x20,0x30,0x1C,0x10,\r\n0x18,0x40,0x1C,0x20,\r\n0x20,0x20,0x26,0x40,\r\n0x13,0x60,0x18,0x20,\r\n0x15,0x40,0x13,0x40,\r\n0x18,0x80,0x00\r\n}\r\n\r\nvoidint0()interrupt1//采用中断0控制节拍\r\n{TH0=0xd8\r\nTL0=0xef\r\nn--\r\n}\r\n\r\nvoiddelay(unsignedcharm)//控制频率延时\r\n{\r\nunsignedi=3*m\r\nwhile(--i)\r\n}\r\n\r\nvoiddelayms(unsignedchara)//豪秒延时子
程序\r\n{\r\nwhile(--a)//采用while(--a)不要采用while(a--)各位可编译一下看看汇编结果就知道了!\r\n}\r\n\r\nvoidmain()\r\n{unsignedcharp,m//m为频率常数变量\r\nunsignedchari=0\r\nTMOD&=0x0f\r\nTMOD|=0x01\r\nTH0=0xd8TL0=0xef\r\nIE=0x82\r\nplay:\r\nwhile(1)\r\n{\r\na:p=music_tab[i]\r\nif(p==0x00){i=0,delayms(1000)gotoplay}//如果碰到结束符,延时1秒,回到开始再来一遍\r\nelseif(p==0xff){i=i+1delayms(100),TR0=0gotoa}//若碰到休止符,延时100ms,继续取下一音符\r\nelse{m=music_tab[i++],n=music_tab[i++]}//取频率常数和节拍常数\r\nTR0=1//开定时器1\r\nwhile(n!=0)Beep=~Beep,delay(m)//等待节拍完成,通过P1口输出音频(可多声道哦!)\r\nTR0=0//关定时器1\r\n}\r\n}\r\n\r\n你参考这个吧
显示子程序和T0中断程序有错。程序修改如下
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit LSA=P2^2
sbit LSB=P2^3
sbit LSC=P2^4
sbit led1=P2^0
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}
void delayms(uint)
void display()//显示程序不用带参数
uchar shi,ge,num,num1,num2
void main()
{
TMOD=0x11
TH0=(65535-45872)/256
TL0=(65535-45872)%256
TH1=(65535-45872)/256
TH1=(65535-45872)%256
EA=1
ET0=1
ET1=1
TR0=1
TR1=1
while(1)
{
display()
}
}
void display()//显示程序不用带参数
{
shi=num/10
ge=num%10
LSA=0LSB=0LSC=0
P0=table[shi]
delayms(5)
LSA=1LSB=0LSC=0
P0=table[ge]
delayms(5)
}
void delayms(uint zms)
{
uint i,j
for(i=zmsi>0i--)
for(j=110j>0j--)
}
void T0_time()interrupt 1
{
TH0=(65535-45872)/256
TL0=(65535-45872)%256
num1++//不是num
if(num1==4)
{
num1=0led1=~led1
}
}
void T1_time()interrupt 3
{
TH1=(65535-45872)/256
TL1=(65535-45872)%256
num2++
if(num2==20)
{
num2=0num++
if(num==60) num=0
}
}
仿真结果
你是要读出stc89c52单片机里面的程序吗?
这是不可能的,STC单片机只能下载程序,即烧录程序,是不能读回程序的。
有的单片机,破解后是可以读出里面的程序的。但读出的是机器码,即二进制代码程序,需要反汇编成汇编程序。如果你对汇编程序不太懂,就是反汇编出来也没有用啊。
评论列表(0条)