Discussion in "8051 Discussion Forum" started by    tingting    Jan 3, 2008.
Thu Jan 03 2008, 08:53 pm
#1
Hello, can someone tell me how to write a programming to activate the function when i press and hold the button for some time afterward to activate the function. i am using Silicon miccrocontroller.

Thanks.
 DrNossberg like this.
Thu Jan 03 2008, 09:20 pm
#2
while(1)
{
    if(P1.1==0)
   
    {
        wait();  // hold time

        if(P1.1==0)
             abc(); // abc() is function which u want to call
     }
}


[ Edited Thu Jan 03 2008, 09:25 pm ]
Fri Jan 04 2008, 07:13 pm
#3
Excuse me, if i would like to press and hold the button for 3 sec, what should the programming be writen.
Thank you. :-)
Fri Jan 04 2008, 07:28 pm
#4
the wait() function can be adjusted for 3sec delay.. you can use the same program above...

but in above code once you press the button.. it will wait for 3 sec whether you have released it or still pressing it..

so you can do this same thing in other way too..
make use of timers..

// button = 0 active
// button = 1 inactive
if (!button){
	timeout = 0;
	//start some timer here...
	TR0 = 1;
	while((!timeout) && (!button));
        if(timeout && (!button)){
		function();
	}
	else{
		some_other_function();
		TR0 = 0;
	}
}


the above code works same as.. like in nokia keypad.. you press a key and release it. then you get a character displayed.. and when you keep it pressed for sometime it display numeric value of the key. i hope you understood..
the code above might need some testing.. so.. you can try it out...

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am
utaletxcyw
Wed Apr 17 2024, 10:21 am
Anthonyvab
Wed Apr 17 2024, 08:48 am
RobertCix
Wed Apr 17 2024, 06:46 am