Sugiman
Joined: 12 Jan 2005 Posts: 15
|
Keyscan code |
Posted: Wed Apr 06, 2005 3:20 am |
|
|
I'm trying to shorten some of the routines in this program, specifically the keyscan ones as posted below. Is there any way to put it in a "for" loop and have it set the SCAN ports low and high once per cycle instead of having to list them all out? I tried to do it with a const array but the compiler gave me an error msg along the lines of "Expression must evaluate to a constant"
Here's the part of the header where SCAN_xx is initialized
Code: |
#define SCAN_01 PIN_A0 // k01,k02,k03,k04
#define SCAN_02 PIN_A1 // k05,k06,k07,k08
#define SCAN_03 PIN_A2 // k09,k10,k11,k12
#define SCAN_04 PIN_A3 // k13,k14,k15,k16
#define SCAN_05 PIN_A5 // k17,k18,k19,k20
#define SCAN_06 PIN_B0 // k21,k22,k23,k24
#define SCAN_07 PIN_B1 // k25,k26,k27,k28
#define SCAN_08 PIN_B2 // k29,k30,k31,k32
#define SCAN_09 PIN_B3 // k33,k34,k35,k36
#define SCAN_10 PIN_C0 // k37,k38,k39,k40
#define SCAN_11 PIN_C1 // k41,k42,k43,k44
#define SCAN_12 PIN_C3 // k45,k46,k47,k48
#define SCAN_13 PIN_C4 // k49,k50,k51,k52
#define SCAN_14 PIN_C5 // k53,k54,k55,k56
#define SCAN_15 PIN_C6 // k57,k58,k59,k60
#define SCAN_16 PIN_C7 // k61,k62,k63,k64
|
And here's the key_scan function I'm hoping to shorten
Code: |
void key_scan(void)
{
int n;
n = 0;
output_low(SCAN_01); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_01);
output_low(SCAN_02); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_02);
output_low(SCAN_03); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_03);
output_low(SCAN_04); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_04);
output_low(SCAN_05); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_05);
output_low(SCAN_06); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_06);
output_low(SCAN_07); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_07);
output_low(SCAN_08); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_08);
output_low(SCAN_09); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_09);
output_low(SCAN_10); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_10);
output_low(SCAN_11); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_11);
output_low(SCAN_12); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_12);
output_low(SCAN_13); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_13);
output_low(SCAN_14); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_14);
output_low(SCAN_15); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_15);
output_low(SCAN_16); delay_us(500);
gScanBuf[n++] = ~gScanIn;
output_high(SCAN_16);
}
|
Thanks for your help =) |
|