When I paste my Buzzer code in the main(), it works. But when I made a buzzer() to have this function execute in the main(), it didn't work. However,I want to use the buzzer function to execute in the main(). How? please help me!!
#pragma DEBUG OBJECTEXTEND CODE #pragma PL (60) #pragma PW (120) #define FOREVER 1 #include <89c51rd2.h> #include <stdio.h> void Delay(void); void Buzzer(void); sbit Buzer = P0^3; void Buzzer() { int i=0; P2=0x00; Buzer=0; while(i<6000) { TMOD=0x01; TH0=0x0D8; //if it is not flashing change it to 00 for TH0 and Tl0 TL0=0x0F0; TR0=1; while(TF0==0){} TR0=0; TF0=0; Buzer=~Buzer; i++; } } void main() { while (FOREVER) { Buzzer(); } }
Soryy You are right It is still bad style They should match.
I had suceeded. I used the step over the instruction of TF0 flag. I found it can't execute this line. then I switcthed the TF0 to test TF0==1. Of course it didn't work as well. But laterally when I switched it back, the timer starts beeping. I did it. Thank you, everyone!
hi, so the buzzer should go on and off. But it didn't. It go beep for a long time Sure, it is exactly what you have programmed. Look at main() and see that you call function Buzzer() in infinite loop (called FOREVER). As this loop does never end so you hear "beep for a long time" Try next:
void main() { Buzzer(); while (FOREVER) { } }
Here's another idea. You connect the buzzer to P0. Do you have pull-ups on P0? Jon
Really? That's 300 changes per second. Are you sure the buzzer you use can be switched on and off that quickly? Most of the buzzers I've used can't be switched anywhere NEAR that fast. Jon
Yes.
According to my quick and dirty calculations, timer T0 times-out in about 0.003 seconds. So, the buzzer is on for 0.003 secs and then off for 0.003 secs. Are you sure you can hear changes to the buzzer that happen that quickly? Jon
I had tried the method, but still didn't work. I will pump in a frequency into the buzzer, so the buzzer should go on and off. But it didn't. It go beep for a long time. That's what I mean it didn't work. Sorry!
the declration an prototype do not match Incorrect. The prototype declration with (void) as the argument specifically does match a function defined to have no arguments, i.e. the argument list () in a function definition.
the declration an prototype do not match. void Buzzer(void); void Buzzer() {
What exactly do you mean when you say "it didn't work"? It's nearly impossible to help with such little information to work on.
View all questions in Keil forum