Exemplo n.º 1
0
void  Task_KeyScan (void)
{
   static INT8U ucKeyCodeHolder = 0X00;
          INT8U ucKeyCode       = 0X00;
   
   CACTL1 = CARSEL + CAREF1 + CAON; 
   CACTL2 = P2CA0 + CAF;
   
   switch (g_sKey.ScanState)
    {
    case KEY_STATE_UP:                                    // See if need to look for a key pressed
        if (Key_Pressed())
        {			                                          // See if key is pressed 
            g_sKey.ScanState = KEY_STATE_DEBOUNCE;          // Next call we will have debounced the key
            ucKeyCodeHolder  = 0X00;
            }
        g_sKey.Time      = 0;         
        break;
    
    case KEY_STATE_DEBOUNCE:                              // Key pressed, get scan code and buffer
        if (Key_Pressed())
        {		                                             // See if key is pressed 
            ucKeyCode = Key_Decode();                       // Determine the key scan code 
            if (ucKeyCode != ucKeyCodeHolder)
            {   
                Key_PushKey(ucKeyCode);                      // Input scan code in buffer   
                ucKeyCodeHolder = ucKeyCode;
            }
            g_sKey.Time    += KEY_SCAN_ALT;
            g_sKey.Pressed  = 1;
        }
        else
        {
            g_sKey.ScanState  = KEY_STATE_UP;            // Key was not pressed after all! 
            g_sKey.Pressed    = 0;
        }
        break;
    default:
    Key_Init();
    break;   
    }
   CACTL1 &=~ (CAREF1 + CAREF0);//CAON);
   if (Key_Hit()) 
     EnableBackLight(30);
}
Exemplo n.º 2
0
void Print_Key_Pressed()
{
    Keycode key_code = 0;

    Print("Welcome to Caro!\n");
    while (!Should_Exit(key_code))
    {
        key_code = Wait_For_Key();
        if ( Key_Pressed(key_code) )
        {
            Print("%c",key_code);
        }
    }

    Print("\nGoodbye!\n");
}