Link here

Keypad Display C Demo


This section presents the ANSI C version of the demonstration program source code. This program shows how the keypad and LCD display can work together for a simple yet efficient human interface. You can expand your instrumentation to include human feedback and control using this source code as an example.

Keypad Display C Demo

// This is a demonstration program for the Keypad/Display Wildcard.
 
// Copyright 2009 Mosaic Industries, Inc.  All Rights Reserved.
//  Disclaimer: THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT ANY
//  WARRANTIES OR REPRESENTATIONS EXPRESS OR IMPLIED, INCLUDING, BUT NOT
//  LIMITED TO, ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
//  FOR A PARTICULAR PURPOSE.
 
#include  <mosaic\allqed.h>    // all examples include the standard library functions
 
#ifdef __GNUC__
#include <wkpd.h>
 
#else
// be sure to load "install.txt" before sending the *.dlf file!
#include "library.h"
#include "library.c"
#endif
 
 
#define KP_DISPLAY_MODULENUM 0
// KP/Display Wildcard MUST use module0 on Wildcard bus for V4.xx kernel platforms
 
// Modulenum 0 corresponds to a WildCard plugged into Module Port 0 with no jumpers set.
// A WildCard plugged directly into a QCard is plugged into Module Port 0.
// Ordinarily, WildCards can be configured for module addresses 0 to 7;
// but the Keypad/Display WildCard MUST be set to module address 0 for the
// built-in software drivers on the QCard to work.
// On a PDQ Board, any module address can be specified using Set_Display_Modulenum
// The 16-bit value at Wildcard offset 0 is a security key;
// bits at Wildcard offset 02 control the beeper (bit0, lsb) and backlight (bit 1);
// bit0 (lsb) at Wildcard offset 0x0E configures the I/O direction:
// of the lower nibble I/O (accessed at bits 0-3) at Wildcard offset 0x0D;
//        bit0 of offset 0x0E=1:output; bit0=0: input, default=input.
// The upper nibble (bits 4-7) at Wildcard offset 0x0D are 4 general purpose inputs.
 
// beeper, backlight, and extra I/O bits are controlled by drivers defined in this file:
 
 
_Q void ShowMessage(void)
{  STRING_TO_DISPLAY("Welcome! Press any  ", 0, 0);
   STRING_TO_DISPLAY("keypad button to see", 1, 0);
   STRING_TO_DISPLAY("how the display and ", 2, 0);
   STRING_TO_DISPLAY("keypad work together", 3, 0);
   UpdateDisplay();
}
 
_Q void idRatherBe( char* string_to_show)
{    ClearDisplay();
    STRING_TO_DISPLAY("I'd rather be...  ", 0, 0);
   STRING_TO_DISPLAY(string_to_show, 1, 0);
   UpdateDisplay();
}
 
_Q void ManageKeypad(void)
{  int current_key, done = 0;
   while(!done)
   {  current_key = (int) Keypad();
       Chirp(1000);
        switch(current_key / 4)
      {  case 0: idRatherBe("Sky Diving");   break; // col 0
         case 1: idRatherBe("Traveling"); break; // col 1
         case 2: idRatherBe("Watching TV");  break; // col 2
         case 3: idRatherBe("Eating");    break; // col 3
         case 4: idRatherBe("Done with this test.");
         done = 1;            break; // col 4
      }
   }
}
 
int main (void)
{  Set_Display_Modulenum(KP_DISPLAY_MODULENUM);    // needed for PDQ line, does nothing on V4.xx
   Backlight_On();            // Turn on the backlight
   Character_4x20();          // Define char display: 4 rows, 20 columns, text mode,
   InitDisplay();                // Initializes & clears display
     ShowMessage();                // display welcome message
   ManageKeypad();            // run interactive demo
   return 0;
}





See also → Keypad Display Wildcard Users Guide


 
This page is about: Embedded Keypad Display Example, Simple C Demonstration Program – Example program shows how to control a Keypad and Display module attached to a SBC with simple questions and answers. LCD Display, String to display, controlled, drivers, Keypad input, Keypad HMI
 
 
Navigation