Keypad.c with inverse logic and I/O

Any general or miscellaneous queries that do not fit into the other forum catagories

Moderators: Benj, Mods

Post Reply
User avatar
leonet99
Posts: 8
Joined: Fri Apr 10, 2009 1:30 am
Contact:

Keypad.c with inverse logic and I/O

Post by leonet99 »

Hi,

I have recently bought my Flowcode PRO and I have a board that I built to use for a AV switch using an arrow-keypad, enter and escape.
I was in the process of trying to learn C before I ran into flowcode.
Now, my keypad connections are similar to the keypad e-block, only that the rows are connected to outputs and columns are connected to inputs.
Also my logic is inverse: I was suppose to use 0 logic as active.
I thought that modifying the keypad.c in components would make the necessary adaptation so I went ahead and gave it a chance but something does not work.
Can anyone please look into my changes and point me into the right direction.
Thanks.
I am including my sch. and c file below:
Keypad_Code.c
(7.25 KiB) Downloaded 271 times
Key_multiplex.jpg
(77.01 KiB) Downloaded 1289 times

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Keypad.c with inverse logic and I/O

Post by Sean »

Hello,

MIAC scans its keypad in the way you require for your application. The example below might help you to develop your keypad code.

Note: the MIAC connections are fixed and do not use the '%x' substitutions required by the generic Keypad component. Also, the lat registers only apply to PIC18 series devices. The equivalent port register should be used for the other families.

char FCD_MIAC0_GetKeypad()
{
//get matrices for rows and columns

char kpad_col_select = 0x08;
char kpad_col_mask = 0x38;
char kpad_row_mask = 0x07;
char trisd_temp = trisd;
char iCol;
char iRow;
char c_ip;

//set up i/o of port (rows = inputs, columns = outputs)
trisd = (trisd | kpad_row_mask) & ~kpad_col_mask;

for (iCol=0; iCol<3; iCol++)
{
//output the appropriate column low
portd = (latd | kpad_col_mask) & ~(kpad_col_select);

//delay
delay_10us(2);

//read the port
c_ip = portd;

//check for a hit
for (iRow=0; iRow<3; iRow++)
{
if ((c_ip & 0x01) == 0)
{
//found it!
goto found_key;
}
c_ip >>= 1;
}
kpad_col_select <<= 1;
}

//if it gets here, it has not been found...
trisd = trisd_temp;
return (255);

found_key:
trisd = trisd_temp;
return (iCol * 3 + iRow);

}

User avatar
leonet99
Posts: 8
Joined: Fri Apr 10, 2009 1:30 am
Contact:

Re: Keypad.c with inverse logic and I/O

Post by leonet99 »

Thank you Sean.
I got it working now.
I appreciate your help.

Post Reply