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 CCS Technical Support

Counting time between clicks
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
The FatBastard
Guest







Counting time between clicks
PostPosted: Thu Dec 30, 2004 6:53 am     Reply with quote

How to count time between first and second action ( button push )
I have to make action block between first and second action ( 3 hours ).
Until this time no other action can be taken...

e.g. on LCD:
displayed mess. action

Press first button -----> pressed !
3 hours -----> counting from 3 to 0 (displaying 3,2,1,0).
Finish ! -----> activate some warn signal until next click

----------------
After every next click(after 3 hours) the counter should start from the begining (repeating the whole action ).
-----------------------------------------------------
Im using 16f84 and real time functions in ccs...
p.s. If there is some topics ( i can't find it ) on this please let me now !
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 30, 2004 5:53 pm     Reply with quote

First, I'd suggest you try a different screen name. I think people
are ignoring your posts because if you don't respect yourself, then
why would someone help you ? Don't take it personally... It's just
a suggestion...
----------

With regard to your question, look at the CCS function called
"delay_ms()". If you use it with a parameter of 60000, then it will
delay for for 1 minute (60 seconds). Then you can use a for() loop
to call it repeatedly and thus create a larger delay.
CCS newbee
Guest







PostPosted: Sat Jan 01, 2005 5:10 am     Reply with quote

HI ! Im really sorry for the screen name ! I didn't know that this could be a problem. Anyway i have changed my screen name....

------------------------------
1.)
I will use external counter ( not PIC ), so tell me can i use the delay_ms(60000) on the same way or must i add something to make this work ?

2.) In the countdown time clicks will be disabled but after 3 hours yuo can make button clicks again. So, how to block button pressings in the countdown time ?
dyeatman



Joined: 06 Sep 2003
Posts: 1939
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Jan 01, 2005 9:50 am     Reply with quote

No, the delay_ms() is a function strictly internal to the PIC.

If you are using an external counter of some kind an interface routine will have to be written, what chip/module is it? Can you give us the number/model? How is it connected?
CCS Newbee
Guest







PostPosted: Mon Jan 03, 2005 6:15 am     Reply with quote

No, the delay_ms() is a function strictly internal to the PIC.
** OK. The external counter is off (sorry, not defined by me ) so i will use internal...
---------------------------
Now :--). We will take this option: PIC 16F84a -- PICVUE 2x16 LCD
two simple buttons.
------------------------------------------------------------------------------

I will go with the PCM Programmer solution for the countdown thru delay_ms(60000) and for loop but there is still a question regarding
button clicks.

1.) How can i save/register each button click ( so i can count them )
2.) How to take some action after button click?

p.s. sorry for so long replay time....
SherpaDoug



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

View user's profile Send private message

PostPosted: Mon Jan 03, 2005 8:06 am     Reply with quote

For short intervals I would just read a free running timer at each click and subtract to get the time between. For long intervals you will need to have some interrupt routine or polling function to make a very long, 24 bit or 32 bit, timer.
_________________
The search for better is endless. Instead simply find very good and get the job done.
ljbeng



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

PostPosted: Mon Jan 03, 2005 1:10 pm     Reply with quote

FatBastard is from Mike Meyer's movie Austin Powers. I thought it was clever.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 03, 2005 1:21 pm     Reply with quote

That may be, but he had a post here that sank down without anyone
answering it, so I suggested a name change and it seems to have worked.
http://www.ccsinfo.com/forum/viewtopic.php?t=21352
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 03, 2005 1:36 pm     Reply with quote

When my daughter was about 5, she thought that was a funny name too. She ran around saying it until I told her that it basturd wasn't really a nice thing to say and she instantly stopped saying it. Very Happy
CCS newbee
Guest







PostPosted: Mon Jan 03, 2005 1:41 pm     Reply with quote

O O
|

˘˘

-----------------
OK :--) The Austin Powers theme is over so let's get back to the problem (anyway thanx ljbeng and thanx PCM prog. for the whole stuff ).
----------------
Now , let's go one step at the time :-)
For short intervals I would just read a free running timer at each click and subtract to get the time between.
***
1.) first dump question: how to define "free running timer" and clicks?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 03, 2005 1:52 pm     Reply with quote

Quote:

1.) How can i save/register each button click ( so i can count them )

When you detect a "click", increment a variable. Its value represents the number of "clicks"

Quote:

2.) How to take some action after button click?


When you detect a "click", do something. It could be a function call or a simple if statement. Whatever the click handler is, that is where you can increment the variable to keep track of the count.


Now I suspect you real question is "How do I detect a button click?". Is this correct?
CCS Newbee
Guest







PostPosted: Tue Jan 04, 2005 1:28 pm     Reply with quote

1.) How can i save/register each button click ( so i can count them )
** what i meant is: what happens if battery falls down (or something like this) will the counter be set to reset 1.) How can i save/register each button click ( so i can count them ) ?

2.)Now I suspect you real question is "How do I detect a button click?". Is this correct?
** No (but nice try :-) My real question is in the counter part of this code:

Code:
#include <16F84a.h>
#use delay(clock=4000000)
#fuses INTRC_IO,NOWDT
#include <lcd.c>
#INT_EXT

short sleep;
void ext_isr()
{
   static short button_click=FALSE;
   int count_clicks = 0;
   if(!button_click)
   {
      lcd_init();
      button_click = TRUE;
      count_clicks = count_clicks + 1;
      lcd_putc("\fThis button was pressed",&count_clicks,"times");
      //-- if no button clicks for 1 min. shut down lcd

         while(button_click)
         {
            sleep = TRUE;

         else
         //-- start countdown for 3 hours
            long int i;  //-- 3 hours = 216000000 ms.
            for ( ...... )
            //--- if i use delay_ms here, then how can i "switch"
            //--- counted numbers to hours ( becuse u have to write
            //--- 3 h on LCD ) and how to count days on the
                    same way (32 bit timer)
            //--- is there no function for this ?
         }
       
 }
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Jan 04, 2005 1:33 pm     Reply with quote

Quote:
** waht i meant is: what happens if battery falls down (or something like this) will the counter be set to reset 1.) How can i save/register each button click ( so i can count them ) ?

Yes it will restart. You can store the value in the eeprom. On powerup, read that value and use it to initialize the counter.

Quote:
//-- start countdown for 3 hours
long int i; //-- 3 hours = 216000000 ms.
for ( ...... )
//--- if i use delay_ms here, then how can i "switch"
//--- counted numbers to hours ( becuse u have to write
//--- 3 h on LCD ) and how to count days on the
same way (32 bit timer)
//--- is there no function for this ?

Don't just sit there the whole time. Delay an hour. Increment the hours. After three of them then do whatever. Days, do the same thing. After hours hits 24, increment the days and reset the hours.
CCS NewBee
Guest







PostPosted: Wed Jan 05, 2005 12:01 pm     Reply with quote

OK. The counter is done but i have still one small problem.
Becuse im using multiple buttons (4) i want to make 3 function
calls on one button (e.g. button 4).

e.g.
activate main button (one) -- signal for countdown start
set main button value to 1
save MB_value to eeprom ( read_eeprom, write_eeprom )
start countdown
while eeprom value is true & !button_clicks for 60 sec.
sleep

if button_four is clicked 1X
restart lcd without main button click /show cdown or #of MB_but. clicks
start something
elif button_four is clicked 2x
start something else ...


1. question is how to detect how many times button_four was clicked (True,False all the time) ?
2. how to define and work with multiple buttons ?
3. question is how to retrive countdowned time and eeprom value after sleep.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Jan 05, 2005 12:13 pm     Reply with quote

CCS NewBee wrote:
1. question is how to detect how many times button_four was clicked (True,False all the time) ?
2. how to define and work with multiple buttons ?
3. question is how to retrive countdowned time and eeprom value after sleep.


1. Count it. You will have to poll this button and check it often if you want it to respond. You could also use an interrupt to detect it if it is on the right pin of the pic.

2. Whatever you do for one button, do it for the others.

3. You used a function to write the value. Use the read_eeprom() function to read the data back.

You orginal task was pretty basic. You are now adding more functionality. You will probably need to get rid of the delay_ms() functions and use one of the timers to keep track of the time so that in the main() loop you can poll for things.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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