how to detect a keyboard press event?--about MC13211

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

how to detect a keyboard press event?--about MC13211

1,464 次查看
Beijing2008
Contributor I
Hi all:
 
   I'm using MC13211 and SMAC codebase, I need to detect keyboard event when key was pressed down or release. My understanding is via interrupt handler deal with it.
   But I don't know its detail ,especially  in software C code level,What need I to do?
  Please give me some hints!
 
Thanks and best regards!
 
Charly
 
标签 (1)
0 项奖励
回复
1 回复

802 次查看
RSteger
Contributor II
Hi,

You probably want to use the KBI module, that uses pins shared with portA. We can assume that you will enable internal pullups on the pins, and design the hardware so pressing a key will connect that pin to ground.

Basically you need to initialize some registers that are defined in your include file. In C the initialization could look something like this:


PTADD = 0x00; // Configure PORTA pins as inputs
PTAPE = 0xFF; // Enable pullups
KBISC |= 0x04; // Clear interrupt flag
KBIPE = 0xFF; // Enable all the KBI pins
KBISC = 0x02; // Configure for falling edge and edge only interrupts, enable interrupts
// Don't forget to enable general CPU interrupts in your application!


You also need to define the interrupt handler, like this:


void interrupt KeyboardInterruptHandler(void)
{
  byte Keys;

  KBISC |= 0x04; // Clear interrupt flag

  // read pin values here to detect what key was pressed
  Keys = ~PTAD;

  // write code here to take action in regards to the keyboard event
}


Last, but not least, you need to set up the corresponding entry in your interrupt vector table. If you aren't using processor expert, you can do this in your .PRM file directly:


VECTOR ADDRESS 0xFFD2 KeyboardInterruptHandler


I recommend looking up all of the registers involved in this code in your reference manual (MC1321xRM.pdf), so you can check for any bugs and configure the KBI module for it to work exactly the way you want it to.

Best regards,

Ron


Message Edited by RSteger on 2008-11-10 01:31 PM
0 项奖励
回复