我在用单片机编程,怎么才能使万年历和蜂鸣器同时运行。用的89C51芯片,C语言!求解答
我写的程序如下 不知道怎么修改 求教大神
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define ulong unsigned long
#define uint unsigned int
void time();
void player();
uchar top[]={0,0,0,0,':',0,0,':',0,0};
uchar tab[]={0,0,':',0,0,':',0,0};
uchar count=0,month=1,day=1,hour=0,minite=0,second=0;
uchar k,n,m;
uint year=2015;
uchar num=0;
sbit rs=P2^4;
sbit re=P2^5;
sbit key_H=P1^0;
sbit key_M=P1^1;
sbit key_D=P1^2;
sbit key_MON=P1^3;
sbit key_Y=P1^4;
sbit BUZZER=P1^5;
sbit key_S=P3^2;
sbit key_T=P3^3;
uint code table[16]={65521,64260,64400,64524,64580,64684,64777,64820,64898,64968,65030,65058,65110,65157,65178,65217};
uchar code music[32]={8,0,8,9,8,0xB,0xA,0,8,0,8,9,8,0xC,0xB,0,8,0,8,0xF,0xD,0xB,0xA,9,0xE,0,0xE,0xD,0xB,0xC,0xB,0x0};
uchar code music_L[32]={2,1,1,4,4,4,4,4,2,1,1,4,4,4,4,4,2,1,1,4,4,4,4,4,2,1,1,4,4,4,4,4};
uchar code music1[40]={4,5,6,4,4,5,6,4,6,7,8,0,6,7,8,0,8,0,9,8,0,7,6,4,8,0,9,8,0,7,6,4,8,1,4,0,4,8,4,0};
uchar code music_L1[40]={4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,2,1,1,2,1,1,4,4,2,1,1,2,1,1,4,4,4,4,4,4,4,4,4,4};
uint temp;
uchar a,b;
void delay(uint v)
{
while(v!=0) v--;
}
void delay1(uint j)
{
while(j!=0){j--;delay(200);}
}
void delay2(uint j)
{
while(j!=0){j--;delay1(80);}
}
void Tdelay(uint x)
{
ulong a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--)
{;}
}
void wzhiling(uchar zhiling)
{
rs=0;
re=0;
Tdelay(1);
P0=zhiling;
Tdelay(2);
re=1;
Tdelay(2);
re=0;
}
void wshuju(uchar shuju)
{
rs=1;
re=0;
Tdelay(2);
P0=shuju;
Tdelay(2);
re=1;
Tdelay(2);
re=0;
}
void INIT( )
{
wzhiling(0x38);
Tdelay(1);
wzhiling(0x0c);
Tdelay(1);
wzhiling(0x06);
Tdelay(1);
wzhiling(0x01);
Tdelay(1);
}
void Time0()interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count>=20)
{
count=0;
second++;
}
}
time1 () interrupt 3 using 3
{
TH1=a;
TL1=b;
BUZZER=!BUZZER;
}
void main()
{
while(1)
{
player();
time();
}
}
void time()
{ EA=1;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
IT0=1;
TR0=1;
INIT( );
while(1)
{
if(second==60)
{
{
minite++;
second=0;
}
if(minite==60)
{
{
hour++;
minite=0;
}
if(hour==24)
{
{
hour=0;
minite=0;
second=0;
day++;
}
if(day==30)
{
{
month++;
day=0;
}
if(month==12)
{
{
year++;
month=0;
}
}
}
}
}
}
if(key_M==0)
{
EA=0;
Tdelay(1);
if(key_M==0)
{while(key_M==0);
minite++; }
EA=1;
}
if(key_H==0)
{
EA=0;
Tdelay(1);
if(key_H==0)
{while(key_H==0);
hour++;}
EA=1;
}
if(key_D==0)
{
EA=0;
Tdelay(1);
if(key_D==0)
{while(key_D==0);
day++;}
EA=1;
}
if(key_MON==0)
{
EA=0;
Tdelay(1);
if(key_MON==0)
{while(key_MON==0);
month++;}
EA=1;
}
if(key_Y==0)
{
EA=0;
Tdelay(1);
if(key_Y==0)
{while(key_Y==0);
year++;}
EA=1;
}
top[8]=0x30+day/10;
top[9]=0x30+day%10;
top[5]=0x30+month/10;
top[6]=0x30+month%10;
top[0]=0x30+year/1000;
top[1]=0x30+year%1000/100;
top[2]=0x30+year%1000%100/10;
top[3]=0x30+year%10;
tab[6]=0x30+second/10;
tab[7]=0x30+second%10;
tab[3]=0x30+minite/10;
tab[4]=0x30+minite%10;
tab[0]=0x30+hour/10;
tab[1]=0x30+hour%10;
for(num=0;num<10;num++)
{
wzhiling(0x80+0x00+num);
wshuju(top[num]);
}
for(num=0;num<8;num++)
{
wzhiling(0x80+0x40+num);
wshuju(tab[num]);
}
}
}
void player()
{
TMOD=0x10;
ET1=1;
TR1=1;
IT0=1;
IT1=1;
if(key_S==0)
{
EA=1;
for(k=0;k<32;k++)
{
n=music[k];
m=music_L[k];
temp=table[n];
a=temp/256;
b=temp%256;
delay2(m);
if(key_T==0)
{EA=0;break;}
}
EA=0;
}
if(key_T==0)
{ EA=1;
for(k=0;k<40;k++)
{
n=music1[k];
m=music_L1[k];
temp=table[n];
a=temp/256;
b=temp%256;
delay2(m);
if(key_S==0)
{EA=0;break;}
}
EA=0;
}
}