Re: C Programming

Chris Michalak (cmich@CAM.ORG) Sat, 2 Dec 2000 03:35:35 -0500 (EST)


Date: Sat, 2 Dec 2000 03:35:35 -0500 (EST)
From: Chris Michalak <cmich@CAM.ORG>
Subject: Re: C Programming

William, Here is my rdkbd function, using a loops. Let me know if something is unclear. int rdkbd (void) /* waits for all keys on keypad to be released. Then waits for a key to be pressed and returns it's integer value */ { int dat; /* used to store raw input data */ int i,j; /* loop variables */ spoke(DATA_PORT,0xF); /* check all rows */ while ( speek(DATA_PORT) & 0xF ) { }; /* wait for all keys to be cleared */ while ( !(speek(DATA_PORT) & 0xF)) { } ; /* waits for a keypress */ for (i=0;i<=3;i++) { /* for each row */ spoke(DATA_PORT,1<<i); if (dat = speek(DATA_PORT) & 0xF) { /* true if a key in this row */ for (j=0;j<=3;j++) { /* for each colum */ if ((dat>>j) & 1) { return (j*4+i); } /* found it */ } } } } Chris Michalak On Fri, 1 Dec 2000, William Tse wrote: > I was study today and was trying to use some loops to > write the read keyboard part of the program of lab #2 > instead of using 16 "if" statements and I could not > get it to work. Can someone help, with an example > perhaps? > > William Tse > > __________________________________________________ > Do You Yahoo!? > Yahoo! Shopping - Thousands of Stores. Millions of Products. > http://shopping.yahoo.com/ >