下面的程序仿真没有声音该如何修改,有图,求大神指点
时间:10-02
整理:3721RD
点击:
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/ksohtml/wps151.tmp.jpg
#include <reg51.h>#include"intrins.h"
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^2;
sbit key2=P3^3;
sbit fm=P3^7;
uchar count;
uchar timeh,timel,i,x,num;
uchar code DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
uchar code qnzl[]={ 0x32,0x52,0x32,0x31,0x21,0x32,0x62, 0x32,0x31,0x21,0x32,0x83,0x82,0x71,0x72,0x02,
0x63,0xA1,0xA2,0x62,0x92,0x82,
0x42,0x63,0x83,0x83,0x91,0x9,0xff
};
uchar code jmszl[]={ 0x12,0x12,0x22,0x32,0x31,0x22,0x21,0x22,
0x32,0x32,0x81,0x81,0x81,0x81,0x91,0x81,0x61,0x81,0x61,0x51,0x31,0x51,0x34, 0xff
};
uchar code hlw[]={ 0x83,0x63,0x51,0x61,0x03,0x81,0x61,0x51,0x81,0x63,0x01,0x81,0x61,0x63,0x51,0x63,0x01};
uchar code tzdn[]={
0x56,0x56,0x32,0x42,0x52,0x76,0x66,0x56,0x52,0x22,0x32,0x46,0x16,0x26,0x04};
uchar code cuzhi[]={
0xff,0xff,
0xFC,0x8E,
0xFC,0xED,
0xFD,0x43,
0xFD,0x6A,
0xFD,0xB3,
0xFD,0xF3,
0xFE,0x2D,
0xFE,0x47,
0xFE,0x76,
0xFE,0xA1 ,
0xFE,0xC7,
0xFE,0xD9,
0xFE,0xF9,
0xFF,0x16 };
void Delay1(uint z);
void Delay(uint z);
void song();
void beep();
void main()
{
P0=0X3F;
P2=0X3F;
EA=1;
EX0=1;
IT0=1;
EX1=1;
IT1=1;
TMOD=0x11;
ET0=1;ET1=1;
TR0=0;TR1=0;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
while(1)
{
if(key2==0){
song();
Delay1(1000);
}
}
}
void int0() interrupt 0
{
EA=0;
Delay1(1);
if(key1==0) {
count=0;
TR0=0;
num=0;
TR1=0;
P0=0X3F;
P2=0X3F;
}
EA=1;
}
void int1() interrupt 2
{
EA=0;
Delay1(1);
if(key2==0)
{
TR0=1;
TR1=1;
i=0;
count++;
if(count==5)
count=1;
}
EA=1;
}
void timer0() interrupt 1
{
TH0=timeh;
TL0=timel;
fm=~fm;
}
void timer1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
if(++x==20)
{
x=0;
++num;
P0=DSY_CODE[num/10]; P2=DSY_CODE[num%10];
if(num==59)
num=0;
}
}
void song()
{
uint temp;
uchar jp;
i=0;
while(1)
{
if(count==0)
{
break;
if(count==1)
temp=qnzl;
if(count==2)
temp=jmszl;
if(count==3)
temp=hlw;
if(count==4)
temp=tzdn;
if(temp==0xff)
break;
jp=temp/16;
if(jp!=0) {
timeh=cuzhi[jp*2]; timel=cuzhi[jp*2+1];
}
else{
TR0=0;
fm=1;
}
Delay(temp%16);
TR0=0;
fm=1;
Delay1(10);
TR0=1;
i++;
}
TR0=0;
fm=1;
}
}
void Delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=19000;y>0;y--);
}
void Delay1(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=112;y>0;y--);
}
void beep()
{
uchar i;
for(i=0;i<50;i++){
fm=~fm;
Delay1(1);
}
fm=1;
}
没看到电路图,光一个程序怎么看?
附上电路图才能看啊
void song()
{
uint temp;
uchar jp;
i=0;
while(1)
{
if(count==0)//不管count的值是多少,对于这个if语句都不好使,仔细看看,
{
break; //这样下面能运行到吗
if()………………
}
//-----------
TR0=0; //这个是在上面的循环中的,定时器0关掉中,fm就不会变
fm=1;
//-------------
}
}
非常感谢,问题已解决