Functions for on/off

Status
Not open for further replies.

gauravkothari23

Hi.
I am trying to make an password based locker for which i i am using 89s52, 4x3 matrix keypad and an 16x2LCD display. i want to write a function which runs in background or it checks if a specific key(Key assigned for that function say A) if pressed whenever or anytime even if in the middle of the whole program, it will execute that function. say suppose i want to write a function to on/off an led which is connected to port 2 of controller. and button A of keypad is assign to do that. i want if button 'A' is pressed anytime the led should turn on or off.
if this thing is possible than plz can anyone help me....

milan.rajik

Banned
I can help you if you can use mikroC PRO 8051 Compiler. I don't use Keil C51.

gauravkothari23

no problem sir...
atleast we will make a try

milan.rajik

Banned
Do you have mikroC PRO 8051 Compiler. If not, then download and install demo version Compiler.

gauravkothari23

no i dont... actually the code i asked from you is just a small part of it... actual code i have already written it in keil which is quite big and also not possible to rewrite again using microc

- - - Updated - - -

atleast if possible then u plz give me some ideas.. i will execute them in keil... and let see if it works

milan.rajik

Banned
Zip and post your complete Keil Project files. I will see how I can add code to control LEDs based on button press.

Lets assume that your variable key holds the value of the button pressed like '0', '1', '2', ... Now make a switch statement like

Code C - [expand]1
2
3
4
5
6
7
8
9
switch(key) {
case '0':
//do thing 1
break;
case '1':
//do thing 2
break;
...
};

Last edited:

xenos

Full Member level 4
Easy way:
If you have a frequent check on keyboard, then it should be placed there.

A little more difficault (If not such a frequent check):
Use an interrupt of 100msec or faster and add a check for key A in there.
If Key A is pressed, and just have to set some pins, it's ok to call the required function from within interrupt.
If the job to be done on A pressed is time consuming, then you should mark a bit flag and when you reach your idle loop, execute the function (and reet this bit flag).

The 100% correct approatch:
you should use a task loop (like RTOS) and add a task to periodically check the keyboard and act.
This design, probably require the modification of your code developing technique...

Status
Not open for further replies.