Home > other >  Great god give directions of the code, burn in buzzer didn't go off, models is HC68800 - ES V2.
Great god give directions of the code, burn in buzzer didn't go off, models is HC68800 - ES V2.

Time:09-17


/*
Time: on April 6, 2020 11:43:17
Function: the doorbell, press the "ding dong" noise inside the K1
*/
# include & lt; Reg51. H>

Sbit K1=P3 ^ 1;//keys K1
Sbit beep=P1 ^ 5;//buzzer

Int ding, dong, flag, n;

Void delay (int I)
{
while(i--);
}


Void time0init initialization ()//timer 0
{
TMOD=0X01;//timer 0 way 1
TH0=0 XFF;
TL0=0 x06;//timer 250 us
//TR0=1;
EA=1;
ET0=1;
}

Void main ()
{
Time0init ();
While (1)
{
If (K1==0)
{
delay(1000);
If (K1==0)
{
TR0=1;//button press, open the timer
}
while(! K1);
}
}
}

Void time0 () interrupt 1
{
Initialise/* and */
250 microsecondsTH0=0 XFF;
TL0=0 x06;

Ding=0;
Dong=0;
Flag=0;
N=0;

N++;
If (n==2000)
{
If (flag==0)
{
Flag=1;
}
The else
{
Flag=0;
}
If (flag==1)//ding sound
{
Ding++;
If (ding==1)
{
Ding=0;
Beep=~ beep;
}
}
If (flag==0)//dong sound
{
Dong++;
If (dong==2)
{
Dong=0;
Beep=~ beep;
TR0=0;//off timer
}
}
}
}

CodePudding user response:

You'll be the first to make sure you use the buzzer is active buzzer or passive buzzer, both drivers in a different way, also have a look at the drive voltage and current is conform to the requirements, and amplifier when necessary

CodePudding user response:

Ding=0;
Dong=0;
Flag=0;
N=0;
The four variables initialization position error, put the initialization in the main () function, in the interrupt handler, each into an interrupt handler these variables will be reset,
  • Related