View previous topic :: View next topic |
Author |
Message |
The FatBastard Guest
|
Counting time between clicks |
Posted: Thu Dec 30, 2004 6:53 am |
|
|
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 ! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 30, 2004 5:53 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
CCS newbee Guest
|
|
Posted: Sat Jan 01, 2005 5:10 am |
|
|
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 ? |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Sat Jan 01, 2005 9:50 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
CCS Newbee Guest
|
|
Posted: Mon Jan 03, 2005 6:15 am |
|
|
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.... |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Mon Jan 03, 2005 8:06 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
ljbeng
Joined: 10 Feb 2004 Posts: 205
|
|
Posted: Mon Jan 03, 2005 1:10 pm |
|
|
FatBastard is from Mike Meyer's movie Austin Powers. I thought it was clever. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jan 03, 2005 1:36 pm |
|
|
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](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
CCS newbee Guest
|
|
Posted: Mon Jan 03, 2005 1:41 pm |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Jan 03, 2005 1:52 pm |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
CCS Newbee Guest
|
|
Posted: Tue Jan 04, 2005 1:28 pm |
|
|
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 ?
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue Jan 04, 2005 1:33 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
CCS NewBee Guest
|
|
Posted: Wed Jan 05, 2005 12:01 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Jan 05, 2005 12:13 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|