Hello!
I have C2000 Piccolo LAUNCHXL-F28027 and 4x4 matrix keypad(they are connected by GPIO) and I want to scan the keypad by timer tick, so I set timer interruption(with interval: ConfigCpuTimer(&CpuTimer0, 60, 50000)) and the keypad will be scanned when timer will ticked, here is the code of the function which will be called by timer tick(I deliberately simplified it for the tests):
interrupt void cpu_timer0_isr(void) { CpuTimer0.InterruptCount++; PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; if(GpioDataRegs.GPADAT.bit.GPIO4 == 0){ GpioDataRegs.GPADAT.bit.GPIO0 = 1; DELAY_US(70); if(GpioDataRegs.GPADAT.bit.GPIO4 == 1){ ch = 'q'; } GpioDataRegs.GPADAT.bit.GPIO0 = 0; GpioDataRegs.GPADAT.bit.GPIO1 = 1; DELAY_US(70); if(GpioDataRegs.GPADAT.bit.GPIO4 == 1){ ch = 'w'; } GpioDataRegs.GPADAT.bit.GPIO1 = 0; } }
I have implemented the logic of the many keypad scanning samples (e.g. embedjournal.com/.../ ), but I get these problems:
- Scanning samples don't use delay after GPIO pin disabling, but I had to do this, because if I don't use it, then GPIO4 still equal to 0(the state does not have enough time to change). Is it right? How can I optimize it?
- After GPIO disabling I can't enable it again. "GpioDataRegs.GPADAT.bit.GPIO0 = 0;" command not seems like it's working. What am I doing wrong?
- If I will use the same algorithm, then my code will be very bulky. How can I optimize it?
So which mechanism I need to use for the right keyboard scanning?