- Keypad scan
- Posted by zebulon on May 15th, 2006
I cant detect anything with the following code (8051 and the keypad i
connected to the port 0)
#define K0_mask 0xED
#define K1_mask 0x7E
#define K2_mask 0x7D
#define K3_mask 0x7B
#define K4_mask 0xBE
#define K5_mask 0xBD
#define K6_mask 0xBB
#define K7_mask 0xDE
#define K8_mask 0xDD
#define K9_mask 0xDB
.....
unsigned char readKeyboard()
{
//Enter if a key has been pressed
if (portState!=0xFF)
{
//need a 21ms debounce period
timerWait25();
//check the key pressed
if (portState == K0_mask)
{
//Display the digit
writeToLCD(0,6);
//wait for the touch to be released
while (portState ==K0_mask);
return(0);
}
....
DOESNT WORK....why ??? thanks for any help
- Posted by Paul Burke on May 15th, 2006
zebulon wrote:
I assume portState is defined somewhere as the input port. If it's not,
you never read the port. You only display anything at all if you get the
right input, so how about displaying (somehow) whatever you do get, e.g.
using a serial port, and work on from there?
paul Burke
- Posted by martin griffith on May 15th, 2006
On Mon, 15 May 2006 05:08:13 -0500, in comp.arch.embedded "zebulon"
<lyoncfpl@hotmail.com> wrote:
port 0 needs pullup resistors, do you have them ?
martin
- Posted by zebulon on May 16th, 2006
sorry i forgot to put this...
//portState points to the port 1
sfr portState=0x90;
yep there are all electronic stuff that should make it running (dont as
me for electronics things , i'm just a trainee that should develop a phon
software...)
When i press a 0 , i should read 11101101 , i.e 0xED...no ?
- Posted by zebulon on May 16th, 2006
actually it's connected to port 1 ....
I always confuse , but anyways , doesnt change anything to m
problem...arghh embedded....
- Posted by Ark on May 16th, 2006
zebulon wrote:
- Ark
- Posted by Neil on May 16th, 2006
zebulon wrote:
Get a scope, voltmeter or logic probe and look at the port pin.
I assume you wrote 0xFF to the port to initialize it.
And, that somewhere you defined portState as P1.
- Posted by Paul Burke on May 16th, 2006
zebulon wrote:
Stuff I forgot: as well as the pullups someone else mentioned, you have
to set port 0 to 0xff (all high) when you iniyialise the system, as it's
a sort of open- collector output.
But seriously, you should be poking round with a scope probe more than
asking us, and printing out what the port actually reads. Check for
changes, and send out using the UART.
Paul Burke
- Posted by zebulon on May 17th, 2006
i changed the whole code , the new one , doesnt work too....i'm fed up wit
this...
for(i=0;i<4;i++)
{
//Put the i'th column to 0
P1 = 0xff & ~(1<<i);
delay(100);
//check the pin
if(P1^7==0)
{
timerWait25(); //debounce period
if (P1^7==0) //check again
{
//Switching to know what key was pressed...
if (i==0)
digit=1;
if (i==1)
digit=2;
if (i==2)
digit=3;
if (i==3)
digit=F1;
//Print the output , DIGIT only !
if (i!=3)
writeToLCD(digit,posToDisplay);
//Wait for the release
while (P1^7==0);
return(digit);
}
}
if(P1^6==0)
{
//timerWait25();
delay(100);
if(P1^6==0)
{
if (i==0)
digit=4;
if (i==1)
digit=5;
if (i==2)
digit=6;
if (i==3)
digit=F2;
if (i!=3)
writeToLCD(digit,posToDisplay);
while (P1^6==0);
return(digit);
}
}
if(P1^5==0)
{
// timerWait25();
delay(100);
if(P1^5==0)
{
if (i==0)
digit=7;
if (i==1)
digit=8;
if (i==2)
digit=9;
if (i==3)
digit=P;
//print the output , DIGIT only !
if (i!=3)
writeToLCD(digit,posToDisplay);
while (P1^5==0);
return(digit);
}
}
if(P1^4==0)
{
// timerWait25();
delay(100);
if(P1^4==0)
{
if (i==0)
digit=STAR;
if (i==1)
digit=0;
if (i==2)
digit=SHARP;
if (i==3)
digit=REDIAL;
//print the output , DIGIT only !
if (i==1)
writeToLCD(digit,posToDisplay);
while (P1^4==0);
return(digit);
}
}
}
return(0xFF);//code for no key pressed
- Posted by Peter Dickerson on May 17th, 2006
"zebulon" <lyoncfpl@hotmail.com> wrote in message
news:CMadnR6TyMYmDffZRVn-tw@giganews.com...
What do you expect this to do? (P1^7)==0 is the same as P1 == 7. For the
first three cycles you are pulling down one of these bits so its bound to
fail. Four the fourth cycle you'd need to press four keys to zero the top
four bits...
[snip similar]
Peter
- Posted by zebulon on May 17th, 2006
I cant understand what you're trying to tell me...
if(P1^7==0) : doesnt it check the value of the 7th pin ??? why should i
be like writting 7 to port 1 ????
i was told to put one bit (column) to 0 , everything else to 1 , the
check the rows to find a 0 which means thaht a key pressed whose value
will be determined both by col and rows...
so i dont understant your answer at al ???
- Posted by Peter Dickerson on May 17th, 2006
"zebulon" <lyoncfpl@hotmail.com> wrote in message
news:H-qdnX--QsSpZ_fZRVn-jg@giganews.com...
I think you need to spend some time learning the language instead of
worrying about hardware. Your code exors the value read from port 1 with the
value 7 and checks the result is 0. The only value of port 1 that when
exored with 7 gives 0 is 7.
Yes. Output scanning zeros on the bottom four bits and check the top four -
assuming a 4x4 matrix keypad.
My answer was that you code was gibberish, You said it didn't work, so I may
be right :-)
for (i=0; i<4; i++)
{
P1 = 0xFE<<i;
Wait();
switch (P1 & 0xF0)
{
case 0x70:
...
case 0xB0:
...
Peter
- Posted by zebulon on May 18th, 2006
I know that i'm not experimented , but i must understand...
where do you see XOR ??
P1 = 0xff & (~(1<<i));
This just put one of the 4 lower bits to 0
if(P1^7==0)
{
Then check the 7 th pin , no?
where is the error in this ?
- Posted by CBFalconer on May 18th, 2006
zebulon wrote:
If you quoted things properly it would be much easier. At any
rate, you have repeated the error in "if (P1 ^ 7 == 0) {". Why do
you want the xor of P1 (whatever that may be) and the constant 7?
BTW, there are no prizes given for obfuscating code by eliding
spaces.
--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
- Posted by Roberto Waltman on May 18th, 2006
On Wed, 17 May 2006 20:55:59 -0500, "zebulon" <lyoncfpl@hotmail.com>
wrote:
'^' is the exclusive-OR operator in C
'7' in binary is 0...000111
- Posted by Roberto Waltman on May 18th, 2006
"zebulon" <lyoncfpl@hotmail.com> wrote:
'^' is the exclusive-OR operator in C
'7' in binary is 0...000111
P1^7 just toggles P1's 3 lowest bits.
- Posted by zebulon on May 18th, 2006
From the Keil C51 help files... :
sbit name = sfr-name ^ bit-position;
The previously declared SFR (sfr-name) is the base address for the sbit
It must be evenly divisible by 8. The bit-position (which must be a numbe
from 0-7) follows the carat symbol ('^') and specifies the bit position t
access. For example:
........
btw , this version works :
for(i=0;i<4;i++)
{
//Put the i'th column to 0
P1 = 0xff & (~(1<<i));
timerWait25();
//check the pin
if(P1==0x7E || P1==0x7D || P1==0x7B || P1==0x77)
{
timerWait25(); //debounce period
if (P1==0x7E || P1==0x7D || P1==0x7B || P1==0x77) //check again
{
//Switching to know what key was pressed...
if (i==0)
digit=1;
if (i==1)
digit=2;
if (i==2)
digit=3;
if (i==3)
digit=F1;
//Print the output , DIGIT only !
if (i!=3)
writeToLCD(digit,posToDisplay);
//Wait for the release
while (P1==0x7E || P1==0x7D || P1==0x7B || P1==0x77);
return(digit);
}
}
Thanks everybody
- Posted by Meindert Sprang on May 18th, 2006
"zebulon" <lyoncfpl@hotmail.com> wrote in message
news:ZaudndOm96DBcfbZRVn-ug@giganews.com...
Correct, but this construct only works when you define an sbit, not in a
regular C expression.
sbit mypin = P1^7 /* this is a non-standard C */
defines mypin to be bit 7 of port 1 while
if (P1^7 == 0) /* standard C */
EXORs the contents of P1 with 7
Meindert
- Posted by zebulon on May 18th, 2006
i should have precised that i was working under Keil C51...sorry
- Posted by Peter Dickerson on May 18th, 2006
"zebulon" <lyoncfpl@hotmail.com> wrote in message
news:ze-dndMCV8sNpPHZ4p2dnA@giganews.com...
I doesn't matter. Even with the Keil compiler the 'if ( P1^7==0 )' code does
not have the interpretation you give it. sbit is a Keil extension and ^ does
not have this meaning elsewhere in C, even Keil C.
Peter