Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Functions for on/off

Status
Not open for further replies.

gauravkothari23

Advanced Member level 1
Joined
Mar 21, 2015
Messages
491
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Activity points
4,654
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
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
I can help you if you can use mikroC PRO 8051 Compiler. I don't use Keil C51.
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
Do you have mikroC PRO 8051 Compiler. If not, then download and install demo version Compiler.
 

gauravkothari23

Advanced Member level 1
Joined
Mar 21, 2015
Messages
491
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Activity points
4,654
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
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
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
Joined
May 9, 2015
Messages
212
Helped
82
Reputation
164
Reaction score
81
Trophy points
28
Location
127.0.0.1
Activity points
1,182
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.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top