我想要能在hours==3,minutes==0(这个时间可以在程序中改)的时候蜂鸣器能响,而且不影响时间的运行。
“void baojing()” 这部分程序运行要会使我时分秒不能准确运行,直接出现空白。
#include<reg51.h>
#define SEG P2
#define SCANP P1
#define uchar unsigned char
#define uint unsigned int
unsigned int x;
sbit P30=P0^0;
sbit P32=P0^2;
sbit P34=P0^4;
sbit P37=P0^7;
sbit beep=P3^7;
uchar count_T0=0;
uchar code tab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar disp[8]={0x3f,0x3f,0x40,0x3f,0x3f,0x40,0x3f,0x3f};
uchar scan[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar seconds=0;
uchar minutes=0;
uchar hours=0;
void delayms(uint x)
{
uint i,j;
for(j=0;j<x;j++)
for(i=0;i<100;i++);
}
void baojing()
{
unsigned char x,i;
if(hours==3)
{
if(minutes==1)
{
for(i=0;i<500;i++)
{
for(x=0;x<100;x++);
P37=~P37;
}
for(i=0;i<250;i++)
{
for(x=0;x<100;x++);
P37=~P37;
}
}
}
}
void display()//显示函数
{
uchar i;
baojing();
for(i=0;i<8;i++)
{
SCANP=scan[i];//送出秒数段码
SEG=disp[i];
delayms(8);
}
}
void main()
{
TMOD=0x11;
TL0=15536%256;
TH0=15536/526;
IE=0x82;
TR0=1;
EX0=1;
EX1=1;
IT0=1;
IT1=1;
P37=1;
while(1)
{
display();
}
}
void timer0() interrupt 1
{
count_T0++;
TL0=45536%256;
TH0=45536/256;
while(count_T0==20)
{
count_T0=0;
seconds++;
while(seconds==10)
{
seconds=0;
minutes++;
while(minutes>=5)
{
minutes=0;
hours++;
while(hours==24)
{
hours=0;
}}}
disp[1]=tab[seconds/10];
disp[0]=tab[seconds%10];
disp[4]=tab[minutes/10];
disp[3]=tab[minutes%10];
disp[7]=tab[hours/10];
disp[6]=tab[hours%10];
}
}
void intx0() interrupt 0
{
if(minutes>=5)
{
minutes=0;
hours++;
}
else
{
minutes++;
}
}
void intx1() interrupt 2
{
if(hours<24)
{
hours++;
}
else
{
hours=0;
}
}
|