How does this sound? In the CNI interrupt routine: if(!ALL_ROWS) // if key is pressed { disable CNI interrupt; // Or at least disable the key inputs, if using=20 CNI for other interrupts start timerX to time 20mS; enable timerX interrupt; } In timerX interrupt routine: enable CNI interrupt; This assumes you have a spare timer available. If not, do you have a=20 time keeping interrupt, or something similar? Kerry Andre Abelian wrote: > Hi all, > > I am reading a keypad that is connected to other board. I am using PIC24F= J256GB110 > with CCS PICC compiler. I am using CNI interrupt "port on change" and con= netced to all 4 rows. > any time any row goes low it create interrupt but also when it goes high = creates interrupt too. > the problem I am having is that I am getting duplicated key "debounce iss= ue". Normally=20 > I used a counter to deal with debouning or adding a delay. Since CNI inte= rrupt is not looping > is like one time shot unless there is a port change using a counter is no= t working. I also have option=20 > using columns but this will create interrupt every 1.5 ms none stop. usin= g rows will create interupt > only when keys are pushed. > > any idea? or suggestions will appreciate=20 > here is the code. > > > // Keypad layout:=20 > char const KEYS[4][4] =3D=20 > {{'1','2','3','A'},=20 > {'4','5','6','B'},=20 > {'7','8','9','C'},=20 > {'*','0','#','D'}};=20 > > // check all rows and return 1 when pushed else return 0 > int1 ALL_ROWS(void)=20 > {=20 > if((input(row0)) & (input(row1)) & (input(row2)) & (input(row3))) // if = any of them pushed return 1 > {=20 > return (0); > } =20 > else > {=20 > return (1); > }=20 > }=20 > > > > > // read keypad but from other board. keypad is connected to other PCB=20 > #int_cni //level=3D7 > void keypad_interrupt() > { > //int32 prg_counter=3D0,data_prg=3D0,read_index_counter[3]; // all = this is for other routine that is removed for now > restart_wdt(); > > delay_ms(5); // for debounce purpose=20 > > if((ALL_ROWS())&&(system_keypad_send_once =3D=3D 1)) // any of 4 = inputs are pressed? row0 & row1 & row2 & row3=20 > {=20 > redled_on; =20 > // col0 1,4,7,* > if((!input(row0))&&(!input(col0)))=20 > {=20 > row=3D0; col=3D0; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } =20 > if((!input(row1))&&(!input(col0))) > {=20 > row=3D1; col=3D0; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > }=20 > if((!input(row2))&&(!input(col0))) > {=20 > row=3D2; col=3D0; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > }=20 > if((!input(row3))&&(!input(col0))) > {=20 > row=3D3; col=3D0; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } =20 > =20 > =20 > // col1 2,5,8,0 =20 > if((!input(row0))&&(!input(col1))) > {=20 > row=3D0; col=3D1; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } =20 > > if((!input(row1))&&(!input(col1))) > {=20 > row=3D1; col=3D1; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > }=20 > =20 > if((!input(row2))&&(!input(col1))) > {=20 > row=3D2; col=3D1; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > }=20 > =20 > if((!input(row3))&&(!input(col1))) > {=20 > row=3D3; col=3D1; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } =20 > =20 > // col2 3,6,9,# > if((!input(row0))&&(!input(col2))) > {=20 > row=3D0; col=3D2; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } =20 > > if((!input(row1))&&(!input(col2))) > {=20 > row=3D1; col=3D2; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > }=20 > =20 > if((!input(row2))&&(!input(col2))) > {=20 > row=3D2; col=3D2; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > }=20 > =20 > if((!input(row3))&&(!input(col2))) > {=20 > row=3D3; col=3D2; > kbd_down =3D true;=20 > key_pressed =3DKEYS[row][col]; > system_keypad_send_once =3D 0; > } =20 > fprintf(ZBEE,"%c", key_pressed); // print for test normally= not used > > } > else > { > redled_off; =20 > kbd_down =3D false; //=20 > system_keypad_send_once =3D 1;=20 > } > > > thanks > > Andre=20 > =20 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .