problem with getkey function on 8051 in c

Status
Not open for further replies.

vacant34

Newbie level 3
Joined
Nov 25, 2012
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,316
hi everybody
im am building a lcd with a keypad it also has a software clock
i have a issue with using the getkey() function in c. I want to ignore the function unless the dav changes
but what iv tried has not worked so far and the program gets stuck on getkey() and messes up the clock.
I know I could use a timer to build the clock but for know id just like to ignore the getkey() until is need it
so could i get some idea how to do this or a simple code for a clock based in the timers.
thank you


while(DAV==1);
{
getkey(key);
}

*****************************************************************/
unsigned char getkey(unsigned char key)
{
//unsigned char key;
while(!DAV);
key=P1&0x0f;
while(DAV);
return key;
}
 

I'm not quite sure if I understand what you mean, but if you need to periodically check for button event try this:

Code:
unsigned char key_event(void)
{
[INDENT]static unsigned char LastState;
unsigned char pin_state;
unsigned char event = 0;

pin_state = P1 & 0x01;    // Or whatever is your port read methode

if(pin_state != LastState && pin_state)
{
[INDENT]event = 1;[/INDENT]
}

LastState = pin_state;

return event;[/INDENT]
}

If you place this function inside your loop you can check for button event not interrupting other stuff.
 

while(DAV==1);
{
getkey(key);
}

*****************************************************************/
unsigned char getkey(unsigned char key)
{
//unsigned char key;
while(!DAV);
key=P1&0x0f;
while(DAV);
return key;

}

I think the problem is in code :

you're returning "key", but where ??

it should be like :

dummy = getkey(key);

or

getkey(&key);

out of above to option you need to change the getkey function corresponding to the option you've chose.

for more detail please see this : (see the call be reference section - you should use that section in your case)
https://www.codingunit.com/c-tutorial-call-by-value-or-call-by-reference
 

hi i know that code looks pretty bad but iv been messing with it so long iv just ended up trying stuff.
that part of the code works but will wait for a kepress and i want to ignore it unless we get that keypress its slowing down my clock. it will return a value to the main.
but i think i will find it worth going over again to see where i have any logicial mistakes thank you

- - - Updated - - -

thank you that looks pretty good i try that as soon as i get home.hopefully the getkey will be ignored unless it gets the keypress
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…