单片机制作PS⼀2键盘如何初始化?

2024-11-02 09:17:23
推荐回答(1个)
回答1:

  /*********************************************************************/
  /************************PS2 Command Process**************************/
  /*********************************************************************/
  void receive_process ( )
  {
  uchar command;

  if ( !Check_command( ) ) return;

  command = PS2_Recbyte ( );

  if ( !command ) return;

  switch( command )
  {
  case 0xff: // reset command
  ps2_send ( 0xfa );
  reset ( );
  break;
  case 0xfe: // re-send command
  ps2_send ( 0xfa );
  re_send ( );
  break;
  case 0xf6: // Set default
  ps2_send ( 0xfa );
  scan_on=1;
  break;
  case 0xf5: // Set default and Disable Keyboard
  LED_ALARM = 0;
  ps2_send ( 0xfa );
  scan_on=0;
  break;
  case 0xf4: // Enable Keyboard
  ps2_send ( 0xfa );
  scan_on=1;
  break;
  case 0xf3: // Set Typematic Rate/Delay
  ps2_send ( 0xfa );
  break;
  case 0xf2: // Read ID
  ps2_send ( 0xfa );
  ps2_send ( 0xAB );
  ps2_send ( 0x83 );
  break;
  case 0xee: // respond command
  ps2_send ( 0xee );
  case 0xed: // set/reset led status command
  ps2_send ( 0xfa );
  receive_led ( );
  break;
  case 0x00:
  ps2_send ( 0xfe );
  break;
  default:
  ps2_send ( 0xfa ); // other command, just send a response of 0xFA
  break;
  }
  }