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

IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am
HenryLaf
Mon Apr 22 2024, 03:50 pm