PS2 keyboard

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
madhavan
Posts: 19
Joined: Fri May 21, 2021 1:22 am

PS2 keyboard

Post by madhavan »

i am trying to connect ps2 keyboard with blue pill .

the same code working with UNO and i have modified little for blue pill.

nothing is coming out as output. please check the code and correct the code if there is any error .

Additionally one information : after flashing the program into blue pill . Computer is disconnecting usb connection for this program . if i run rest of the program it's working proper . if know working lib for ps2 keyboard for blue pill then please suggest .

using the http://dan.drown.org/stm32duino/package ... index.json core

Code: Select all


#define InterruptPinA     PC13
#define InterruptPinB     PC14



char ScancodeToASCII[2][128] = {
  { 0,0,0,0,0,27,27,0,         0,0,0,0,0,9,96,0,         0,0,0,0,0,113,49,0,       0,0,122,115,97,119,50,0,    // w/o SHIFT or ALT(GR)
    0,99,120,100,101,52,51,0,0,32,118,102,116,114,53,0,0,110,98,104,103,121,54,0,0,0,109,106,117,55,56,0,
    0,44,107,105,111,48,57,0,0,46,47,108,59,112,45,0,  0,0,39,0,91,61,0,0,     0,0,10,93,0,124,0,0,
    0,60,0,0,0,0,8,0,        0,49,0,52,55,0,0,0,          0,46,50,53,54,56,27,0,         0,43,51,45,42,57,0,0  },
  { 0,0,0,0,0,0,0,0,         0,0,0,0,0,0,126,0,        0,0,0,0,0,81,33,0,        0,0,90,83,65,87,64,35,       // with SHIFT
    0,67,88,68,69,36,35,0,    0,32,86,70,84,82,37,0,     0,78,66,72,71,89,94,0,    0,0,77,74,85,38,42,0,
    0,60,75,73,79,41,40,0,   0,62,63,76,58,80,95,0,   0,0,34,0,123,43,0,0,      0,0,0,125,0,92,0,0,
    0,62,0,0,0,0,0,0,        0,0,0,0,0,0,0,0,          0,0,0,0,0,0,0,0,          0,0,0,0,0,0,0,0  } };


void setup()
{
   pinMode(InterruptPinA,   INPUT);
   pinMode(InterruptPinB,   INPUT);

  attachInterrupt(InterruptPinA, readcoderIntA,CHANGE);
//  attachInterrupt(InterruptPinB, readcoderIntB,CHANGE);
  
  //noInterrupts();//arduino uno
   // PCICR = 0b00000010;   // enable Port C pin change interrupt PCI "PCINT1"
   // PCMSK1 = 0b00010000;  // unmask Pin A4 pin change interrupt PCI
  //interrupts();//arduino uno
  Serial.begin(9600);
}

void loop() {}

//ISR(PCINT1_vect)      // interrupt service routine//arduino uno
void readcoderIntA()
{
  int val = 0;
  for(int i=0; i<11; i++)
  {
    while(digitalRead(PC13) == true);
    val |= digitalRead(PC14)<<i;
    while(digitalRead(PC13) == false);
    //while(bitRead(PINC, 4) == true);//arduino uno
    //val |= bitRead(PINC, 3)<<i;//arduino uno
    //while(bitRead(PINC, 4) == false); //arduino uno   
  }
  val = (val>>1) & 255;

  static bool shiftIsActive = false;      // state of the SHIFT key
  static bool nextIsReleased = false;     // indicating that the next key was released

  switch (val)
  {
    case 18: case 89: shiftIsActive = !nextIsReleased; nextIsReleased = false; break;  // SHIFT LEFT, SHIFT RIGHT     
    case 240: nextIsReleased = true; break;                                            // key release indicator      
    default:                                                                           // any other key
      if (!nextIsReleased)                // is it a 'key pressed' event?
      {
        Serial.print(ScancodeToASCII[shiftIsActive][val & 127]);                       // do lookup raw -> ASCII
      }
      nextIsReleased = false;
      break;
  }
  //PCIFR = 0x02; //arduino uno                 // clears the PCI flag 1
}
Post Reply

Return to “General discussion”