Read Pull Up Inputs - Low Current Method

Version 1
    Question: How can I achieve low current consumption by configuring a push button in pull up mode?



    Following is the logic.
    1. Put the port pins to pull up mode which are connected to external switches
    2. Read the port data
    3. Put back to High-Mode

    The internal pull up resistance of PSoC is 5.6k. So if when a user presses the push button there will be small current consumption. This method configures the port to pull up only while reading the port pins and all other time remains in High-Z. So if the user press the key for 50 or 100ms, the switch will draw current only for the short time when the PSoC is reading the pins.

    There is also a debouncing logic for the same function

    BYTE bScanButtons(void)
        static BYTE bPrevious = 0x00;

        BYTE bCurrent = 0x00;
        BYTE bTemp = 0x00;

        //Set all buttons to pullup.  This function would write to the
        //PRTxDMx registers

        //Read the status of the pins
        bCurrent = ReadPRTDR ();

        //Set all buttons to Hi-Z Analog

        //The state of pins in pull up is active low. Change to Active High
        bCurrent = ~bCurrent;

        //Set unused bits to 0
        bCurrent &= ~UNUSED_BITS;

        //Bitwise AND to determine active buttons
        bTemp = bCurrent & bPrevious;

        //Store the current status for use as previous status
        bPrevious = bCurrent;

        return bTemp;

    The same logic may be applied to Pull Down inputs as well.