Hello.   I'm a HCS08 beginner and I would ask an easy que... - MC9S08AW60

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hello.   I'm a HCS08 beginner and I would ask an easy que... - MC9S08AW60

3,377 Views
dar77
Contributor I
Hello.
 
I'm a HCS08 beginner and I would ask an easy question. I'm using a MC9S08AW60 MCU in a 44-pin LQFP package.
The problem is: I need to handle eight push-buttons and I thought to use the KBI module pins but I saw that it has only six pins in the package I'm using. 
The question is: Can I use normal I/O port pins to handle these buttons? and above all
Can I define interrupts connected with I/O port pins?
 
Thanks.
 
 
 
 
 
 
 
 
 
Added p/n to subject.


Message Edited by NLFSJ on 2008-01-29 03:29 PM
Labels (1)
0 Kudos
7 Replies

554 Views
Encoder
Contributor I
As Jim Don I too scan my keyboard on a timely interrupt. I have a clock timer which upgrades hour counter each 1ms, 10ms, etc.
 
On the 10ms tick I scan the keyboard to see if any key is pressed: if positive I scan each key to determine which is pressed. To debounce the key I need a two time sequentially positive identical response (i.e. the second 10ms later).
 
My keys and the rotating encoder are multiplexed on the same lines which interface the 8bit data bus of the LCD alfanumeric display; only the sense line (PTC5 in my drawing) is dedicated. Diodes in series to each line isolate them from cross conduction if more than one key is pressed at once. The rotating encoder may be equipared to 3 keys, so I may control up to 8 keys with only one dedicated sense line.
 
Another control may use two common lines of the previous ones and another dedicated one (the strobe) to deserialize slow signals with a shift register to drive leds or the contrast line of the LCD display.
 
The sample drawing I enclose is cut from a bigger experimental circuit driven by a MC9S08AW60DEMO board which has 40 lines as "expansion port" but may be easily driven by a 44 pin -AW16/60. I do not use any keyboard interrupt: so the design may be ported on any even smaller uC, even up to 16 or 20 pin ones. In this drawing MOSI and SPSCK are SPI dedicated lines which I have here available but may be replaced by any couple of PTA0 to PTA7 already used on keyboard and LCD driver.
 
Hope this may give you some suggestion.
 
Encoder


Message Edited by Encoder on 2008-01-29 09:59 PM
0 Kudos

554 Views
JimDon
Senior Contributor III
Encoder,

Very NICE schematic. Too many schematics these day look bad, but that one is nice. I recall the days when they were drawn by people - some were true works of art. Also colors don't belong on a schematic. It's ok on the screen for layout, but it does not print nicely.

I like the way you deal with the encoder as just another switch. I also just scan (and debounce) my mechanical encoders with no interrupts. Optical ones (which have zero bounce) which are connected to a motor must use edge interrupts.

But I hate to point out - you are using 8 lines - you can scan 16 switches and lose the diodes with a 4x4 matrix. Of course you can't really press two at once with the 4x4. Perhaps you need this.

0 Kudos

554 Views
tonyp
Senior Contributor II
You could:

1. Use a 3x3 matrix configuration to form a 9 button maximum keyboard.
2. Use a single A/D channel for all 8 buttons (not useful if multiple keys may be pressed at once but very good and pin-cost-effective if keys are always pressed individually).
3. Use extra general-purpose I/O pins.

For case 1, you need a routine that drives each row (or column) separately and tests the corresponding column (or row) for a key press.

For case 3, not all pins have an interrupt associated with them.  But, you could easily OR all keyboard pins to the /IRQ pin (for example), and start the keyboard scanner task from inside the IRQ ISR.

0 Kudos

554 Views
dar77
Contributor I
Thanks.
 
Could you give me more hints about the 3x3 matrix, please?
I should use three pins as output and three pins as KBI input. Then, when I get a KBI interrupt I should find the button which is pressed. Right?
Is there an AN or C sample code ?
 
Thank you.
 
0 Kudos

554 Views
peg
Senior Contributor IV
Hi, dar77,

This old manual has quite a good description of doing a matrix keypad along with a lot of other good stuff for beginners. It's all in assembler, but is good for understanding how it should all be done.

0 Kudos

554 Views
bigmac
Specialist III
Hello, some further comments about the switch matrix method -
 
Your requirement could be met with any one of the following configurations,
2 inputs, 4 outputs
3 inputs, 3 outputs
4 inputs, 2 outputs
 
If you really require to use interrupts, perhaps because you first need to wakeup the MCU from STOP mode, only the inputs require to be part of the KBI block.  The outputs can use other GPIO pins.  Assuming active low input configuration, you might use the following process -
  1. Prior to entering STOP mode, set all outputs to low state.  This will ensure that wakeup and interrupt will occur if any key is pressed.
  2. After wakeup, you have a choice whether to handle the key scanning (and debounce) process within the ISR code, or within the main loop.  I would probably opt for the latter.
  3. The scanning method I would possibly use would be to -
       a) Set all outputs to high state,
       b) wait 20-50ms debounce delay,
       c) Identify the row and column of the switch closure by progressively setting each output low, and examining the input status.  Perhaps the KBI needs to be disabled during this process, if within main loop.
With some additional complexity to the code, it would also be possible to prioritize multiple key presses.
 
If two simultaneous key presses should occur that happen to use the same input, but different outputs, it may be possible for excessive current to occur during the scanning process (3c above).  A high output will become shorted to a low output.  To avoid this, either use series (Schottky) diodes, as Encoder has done, or alternatively, do not drive the outputs active high.  This is achieved by setting each output to an input with pullup, when a high state is required.
 
Regards,
Mac
 


Message Edited by bigmac on 2008-01-30 05:23 PM
0 Kudos

554 Views
JimDon
Senior Contributor III
Well, I always scan buttons from the foreground anyway - I never us an interrupt for switches and it works fine.

0 Kudos