TTP229BSF WITH STM8S003F3

 #define SCL_PIN PC4

#define SDO_PIN PC3

char keypad[16];

int key;

void setup()

{

  Serial_begin(38400);

  pinMode(SCL_PIN, OUTPUT);

  pinMode(SDO_PIN, INPUT);

  digitalWrite(SCL_PIN, HIGH);

  Serial_print_c('h');

  delay(1000);

}

void loop()

{

  readKeypad();

}

void readKeypad()

{

  WaitForTouch();

  for (int i = 0; i < 16; i++)

  {

    digitalWrite(SCL_PIN, LOW);

    delayMicroseconds(10);

    //Serial.print(digitalRead(SDO_PIN));

    keypad[i] = (1 - digitalRead(SDO_PIN)) + 0x30;

    //  Serial.print(keypad[i]);

    digitalWrite(SCL_PIN, HIGH);

    delayMicroseconds(10);

  }

  for (int i = 0; i < 16; i++)

  {

    if ( (keypad[i] - 0x30) == 1)

    {

      key = i;

      Serial_print_c(key / 10 + 0x30);

      Serial_print_c(key % 10 + 0x30);

      Serial_print_c(0XD);

      break;

    }

  }

  delay(200);


}

void WaitForTouch(void)

{

  while (digitalRead(SDO_PIN));

  while (!digitalRead(SDO_PIN));

  delayMicroseconds(10); // Tw

}