Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).
Keypad problems - paulwilliam_pwilliams - Dec 10 7:48:46 2007
I am having trouble with the operation of a 4x4 keypad. i am using a
mc9s12d64 with ICC12.
the bulk of the program works fine even the character capture. that
is, when a button is pressed the correct button is recognized.
the problem that occurs is when i try and distinguish between two
buttons. the MCU appears to stall or halt in the operation.
the section of code that appears to be causing the problem is provided
below:
// Start Code
do{
key=0;
do{
key=scan_Keypad(); // Determines the Key pressed by polling
}while(key==0);
if(key>='0'&&key<='9'){
lcd_data(key);
temp=(temp*10)+(key-'0');
}
}while(key!='A'||key!='C');
// End Code
the problem appears to be within the capture of the 'A' or 'C' while
loop, but the recognition of the '1' thru to '9' work OK. the MCU
seems to be held within an infinite loop no matter if i press 'A' or 'C'.
if i remove the OR operator and either of the statements the program
works OK.
any suggestions would be greatly appreciated,
Paul

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
Re: Keypad problems - =?ISO-8859-1?Q?Ruben_J=F6nsson?= - Dec 10 8:38:55 2007
You need to do:
while(key!='A' && key!='C')
otherwise the expression will always be true. (If you press 'A' you don't press
'C' and vice versa so one of them will always be true).
/Ruben
> I am having trouble with the operation of a 4x4 keypad. i am using a
> mc9s12d64 with ICC12.
>
> the bulk of the program works fine even the character capture. that
> is, when a button is pressed the correct button is recognized.
>
> the problem that occurs is when i try and distinguish between two
> buttons. the MCU appears to stall or halt in the operation.
>
> the section of code that appears to be causing the problem is provided
> below:
>
> // Start Code
> do{
> key=0;
> do{
> key=scan_Keypad(); // Determines the Key pressed by polling
> }while(key==0);
> if(key>='0'&&key<='9'){
> lcd_data(key);
> temp=(temp*10)+(key-'0');
> }
> }while(key!='A'||key!='C');
> // End Code
>
> the problem appears to be within the capture of the 'A' or 'C' while
> loop, but the recognition of the '1' thru to '9' work OK. the MCU
> seems to be held within an infinite loop no matter if i press 'A' or 'C'.
>
> if i remove the OR operator and either of the statements the program
> works OK.
>
> any suggestions would be greatly appreciated,
>
> Paul
==============================
Ruben Jönsson
AB Liros Electronic
Box 9124, 200 39 Malmö, Sweden
TEL INT +46 40142078
FAX INT +46 40947388
r...@pp.sbbs.se
==============================
______________________________
controlSUITE software. Comprehensive. Intuitive. Optimized.
Real-world software for real-time control. Details Here!

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )RE: Keypad problems - Anders Friberg - Dec 10 8:58:01 2007
>
> the section of code that appears to be causing the problem is provided
> below:
>
> // Start Code
> do{
> key=0;
> do{
> key=scan_Keypad(); // Determines the Key pressed by polling
> }while(key==0);
> if(key>='0'&&key<='9'){
> lcd_data(key);
> temp=(temp*10)+(key-'0');
> }
> }while(key!='A'||key!='C');
> // End Code
>
> the problem appears to be within the capture of the 'A' or 'C' while
> loop, but the recognition of the '1' thru to '9' work OK. the MCU
> seems to be held within an infinite loop no matter if i press
> 'A' or 'C'.
>
> if i remove the OR operator and either of the statements the program
> works OK.
>
> any suggestions would be greatly appreciated,
>
> Paul
>
This bug probably often happens due to the similarity with the spoken frase
"while the key is not A or C"!
The statement "key!='A'||key!='C'" will always be TRUE (if one term key!='A'
if FALSE the other one will always be TRUE)!
Should be for example while(!(key =='A' || key =='C'))
Or while(key!='A'&& key!='C') but I think the former is more readable.
De Morgan's theorem is nice to use when checking such statements.
Regards,
Anders

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )
Re: Keypad problems - paulwilliam_pwilliams - Dec 12 7:11:03 2007
--- In 6...@yahoogroups.com, "Anders Friberg"
wrote:
>
>
>
> >
> > the section of code that appears to be causing the problem is provided
> > below:
> >
> > // Start Code
> > do{
> > key=0;
> > do{
> > key=scan_Keypad(); // Determines the Key pressed by polling
> > }while(key==0);
> > if(key>='0'&&key<='9'){
> > lcd_data(key);
> > temp=(temp*10)+(key-'0');
> > }
> > }while(key!='A'||key!='C');
> > // End Code
> >
> > the problem appears to be within the capture of the 'A' or 'C' while
> > loop, but the recognition of the '1' thru to '9' work OK. the MCU
> > seems to be held within an infinite loop no matter if i press
> > 'A' or 'C'.
> >
> > if i remove the OR operator and either of the statements the program
> > works OK.
> >
> > any suggestions would be greatly appreciated,
> >
> > Paul
> > This bug probably often happens due to the similarity with the
spoken frase
> "while the key is not A or C"!
>
> The statement "key!='A'||key!='C'" will always be TRUE (if one term
key!='A'
> if FALSE the other one will always be TRUE)!
>
> Should be for example while(!(key =='A' || key =='C'))
>
> Or while(key!='A'&& key!='C') but I think the former is more readable.
>
> De Morgan's theorem is nice to use when checking such statements.
>
> Regards,
> Anders
>
Thanks for the replies,
I think you both are correct. My logic was wrong when working it out
I was using:
A C A+C !(A+C)
0 0 0 1
0 1 1 0
1 0 1 0
1 1 1 0
But the logic table should be:
A C A+C !A+!C !A*!C
0 0 0 1 1
0 1 1 1 0
1 0 1 1 0
1 1 1 0 0
Which should work correctly.
Thanks for your help
Paul

(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )