CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

BUZZER

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Joaquim
Guest







BUZZER
PostPosted: Thu Apr 28, 2005 7:47 am     Reply with quote

Hello,

i wanted to know how i could do to switch on a buzzer 2 seconds and then switch it off, every 2 seconds during 1 minute and then after this 1 minute
do the same thing every 30 seconds instead of every 2 second...

I hope this is clear.

during 60s
{
BUZZER ON
2s
BUZZER OFF
}

then

every 30 s
{
BUZZER ON
2s
BUZZER OFF
}

Many thanks !!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Apr 28, 2005 9:11 am     Reply with quote

This sounds like a school homework assignment and you don't know where to start.

1) Find out how to turn an I/O pin on and off using output_high(pin) and related functions.
2) Learn how to wait lengths of time using delay_ms(time).
3) Learn how to loop using while().
4) Use a combination of slow loops to set you buzzer control pin.

That is all there is to it.

Also, look at a few of the example programs that come with the compiler. When you have time it pays to read the manual cover to cover. You will find all sorts of neat stuff.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Joaquim
Guest







PostPosted: Thu Apr 28, 2005 9:24 am     Reply with quote

My main problem is to delay in a delay...

I don't know how to do that ....

During 60 s do something every 2 s ...

Could someone help me to write that ?
Joaquim
Guest







PostPosted: Thu Apr 28, 2005 9:59 am     Reply with quote

I'll try this way.

Any other suggestion ?

Thank you ! Wink
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 28, 2005 12:12 pm     Reply with quote

Use a for() loop to control this. Since you know the total amount
of time that you want your action to occur, and you know the amount
of time for one sequence, just divide the total time by the sequence
time. This gives you the number of loops that you want to do.

In your example:
The buzzer is on for 2 and off for 2 seconds. Total = 4 seconds
for the sequence.

The total time for the action is 60 seconds. Divide 60 by 4, which
gives 15. This is the number of loops that you need.

Then use a for() loop to do this:

Code:
#define BUZZER_PIN  PIN_B0

main()
{
int8 i;

for(i = 0; i < 15; i++)
   {
    output_high(BUZZER_PIN);   // Turn on the buzzer
    delay_ms(2000);                 // Wait for 2 seconds

    output_low(BUZZER_PIN);   // Turn off the buzzer
    delay_ms(2000);                // Wait for 2 seconds
   }

while(1);   // Don't let PIC fall off the end and go to sleep.
}

Do you understand the math and the concept here ?
Joaquim
Guest







PostPosted: Fri Apr 29, 2005 1:53 am     Reply with quote

Thank you !!!

It is what i wanted !

Many thanks !!! Wink
fuzzy



Joined: 26 Feb 2005
Posts: 64

View user's profile Send private message

PostPosted: Thu May 05, 2005 12:43 pm     Reply with quote

I think you better use internal PIC counter... it's more useful and precise.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group