Hi,

I am a recent convert from the easy-to-use Picaxe to the much more powerful PBP3 .

My progress is inconsistent: with one step back for every two forward!

The latest project scans a 3 column by 4 row keypad, ouputs to a 2 X 16 OLED display and crunches some maths. The code has been cobbled together from the Melabs examples and performs flawlessly.

Until I come to the simple task of reading a push-button and lighting an led! Every time I press a key on the keypad, it shows correctly on the OLED but blinks the led as well. Whereas the push-button on D.0 will not blink the led. I have stripped the code down in an effort to debug it, but the problem persists. At one stage I had the push-button blinking the led - but it nadgered the keypad scanning as a bonus ...

I suspect that the configuration is at the heart of this. All of the keypad scanning is done on Port B; the OLED display is split between Port C and D;
the push-button is on D.0; the led on D.4;

Any help would be appreciated - thank you!

; define OLED connections
Define LCD_DREG PORTC
Define LCD_DBIT 0
Define LCD_RSREG PORTD
Define LCD_RSBIT 3
Define LCD_EREG PORTD
Define LCD_EBIT 2
Define LCD_BITS 8
Define LCD_LINES 2
Define LCD_COMMANDUS 1500
Define LCD_DATAUS 44


; define program variables
col var byte ' Keypad column
row var byte ' Keypad row
key var word ' Key value


gosub init ; initialise
gosub welcome ; OLED splash

mainloop:
gosub getkey
lcdout 254, 192, "key=",#key, " " ; line 2
if portD.0 = 0 then gosub flash
goto mainloop


init:
ANSEL = 000000 ; AN0-AN7 digital
ANSELH= 000000 ; AN8-AN13 digital
OPTION_REG.7 = 0 ; Port B pullups
TRISB = 0 ; Port B all outputs
TRISD = 000011 ; Port D all output except D0 & D1 PBT inputs
PORTD = 000000 ; setport PortD ouputs low
pause 1000 ; await OLED power-up
return


welcome:
lcdout 254, 1 ; CLS
pause 200
lcdout 254, 128 , "Hello "
pause 2500
lcdout 254, 1 ; CLS
pause 200
return


flash:
portD.4=1
pause 500
portD.4=0
return

getkey:
pause 50 ;debounce


getkeyu:
' Wait for all keys up
PORTB = 0 ;all output pins low
TRISB = 110000 ;bottom 4 pins out, top 4 pins in
If ((PORTB >> 4) != 001111) Then getkeyu ' If any keys down, loop
Pause 50 ;debounce


getkeyp:
' Wait for keypress
For col = 0 To 3 ' 4 columns in keypad
PORTB = 0 ' All output pins low
TRISB = (dcd col) ^ $ff ' Set one column pin to output
row = PORTB >> 4 ' Read row
If row != 001111 Then gotkey ' If any keydown, exit
Next col
Goto getkeyp ' No keys down, go look again


' Change row and column to key number 1-12
gotkey:
key = (col * 3) + (ncd (row ^ 001111)) ;4RX3C matrix
return