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(); } }
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
Yes.
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
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!