Connecting pins of a switch to 2 port pins, simulating function of Ground(0V)

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by newbie on Mon Oct 07 06:33:47 MST 2013

Was trying to write Keypad interfacing, but failed to understand how a 0 at the row(output) ofa switch when pressed is available at the column too. So started with a single switch interface.

Code:-  Single switch
[color=#069]#include "lpc17xx.h"

#define pin1 ((1<<11)|(1<<10))
#define pin2 ((1<<13)|(1<<12))

void PinInit()
//Pin 0.21 - used as input - Connected to one pin of switch pair (tact switch used)
//pull up resistor enabled
LPC_PINCON->PINSEL1 |= ~(pin1);
LPC_GPIO0->FIODIR |= ~(1<<21);

//Pin 0.22 - used as output - connected to other end of the switch pair
//the same pin is grounded
LPC_PINCON->PINSEL |= ~(pin2);
LPC_GPIO0->FIODIR |= (1<<22);


int main(void)

int valuepin;


valuepin = ((LPC_GPIO0->FIOPIN)>>21);
//Switch Normal OPen Condition
else if(valuepin==0)
//Switch Normal Closed Condition


When Switch is pressed valuepin =0, values at both (FIOPIN) pins P0.21 and P0.22 will be zero
How do I Simulate the above ground function if  I connect pin 2 of the switch to port 0.22 pin of LPC1768

Tried: making FIOPIN of output as zero. But that has no effect on the input when key is pressed.

On the same lines the keypad interfacing program is written.
Columns are made input
Rows are made output and have a value of zero
A short between a column and a row is a result of a key press.

How to achieve the same result of a switch(1 pin connected to GND), if both pins of a switch are connected to port pins of LPC1768?
Unable to move further as i fail to understand this, hence keypad interfacing is also something i am failing to understand.

Kindly help. Thanks in advance for your valuable time and consideration for answering this query.