keyboard_hex.hcc


//  keyboard_hex.hcc

/*
 *    Read characters from a keyboard attached to the PS2
 *    keybd port, and display their hex values on the seven
 *    segment displays.
 *
 *    Author: C. Vickery
 *    Fall 2003
 *
 */

#define PAL_TARGET_CLOCK_RATE 50000000

#include <pal_master.hch>
#include <pal_keyboard.hch>
#include <stdlib.hch>

PalKeyboard *kbd;

unsigned 1 b0,b1;
unsigned 4 msb=0b1010, lsb=0b0101;
unsigned 8 inChar = 0x5A;


//  main()
//  -------------------------------------------------------
void main( void )
{
  PalVersionRequire( 1, 2 );
  PalPS2PortRequire( 2 );
  PalSevenSegRequire( 2 );
  PalSwitchRequire( 2 );
  PalSevenSegEnable( PalSevenSegCT(0) );
  PalSevenSegEnable( PalSevenSegCT(1) );
  PalSevenSegWriteDigit( PalSevenSegCT(0), msb, 0 );
  PalSevenSegWriteDigit( PalSevenSegCT(1), lsb, 0 );

  par
  {
    PalKeyboardRun( &kbd, PalPS2PortCT( 1 ),
                          PAL_ACTUAL_CLOCK_RATE );
    seq
    {
      PalKeyboardEnable( kbd );
      while ( TRUE )
      {
        PalKeyboardReadASCII( kbd, &inChar);
        PalSevenSegWriteDigit( PalSevenSegCT( 1 ), inChar <- 4, 0 );
        PalSevenSegWriteDigit( PalSevenSegCT( 0 ), inChar \\ 4, 0 );
      }
    }

    while ( TRUE )
    {
      par
      {
        PalSwitchRead( PalSwitchCT( 0 ), &b0 );
        PalSwitchRead( PalSwitchCT( 1 ), &b1 );
        PalLEDWrite( PalLEDCT( 0 ), b0 );
        PalLEDWrite( PalLEDCT( 1 ), b1 );
      }
    }
  }
}