I have one problem. I have to program this situation, but i have no idea how i can realize it. It should work so:
If i push a button AND i hold it pushed for 5 sec. a LED should start lighting.
Any suggestions?
Thank you. Dennis
inservi
Joined: 13 May 2007 Posts: 128
Posted: Mon Jul 30, 2007 2:12 am
Hello,
I think that a good way is to use an interrupt for counting the time.
For example, set one timer for about 0.76 second and use a int16 counter in the interrupt. when the counter count at least 380 the the 5 second are past
You can check if the button is pushed in he interrupt. If the button is not pushed then set the counter to 0.
In the main loop you can testing if the counter is greater than 380 then set the led on...
Code:
...
int16 sec5 = 0 ;
...
#INT_TIMERx
void interrupt_proc() { // called n time by sec (for example)
if (button_pushed) ++sec5 ;
else sec5 = 0 ;
}
...
void main() {
until(true) {
if ( sec5 >= ( n*5 ) ) { // n is the number of time that the interrupt is called by second
// your code for led ...
...
}
}
}
Witch pic do you use ? (i suppose that you use a pic16f873 ?)
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