Hi all

Please would somebody be so kind as to shed some light on the problem I am experiencing.

I am busy re-kindling my hobby and interest in PIC programming, I think these forums are an excellent resource, somehow all roads lead back here after many a google search and reading post after post and numerous articles.
After 3 weeks of late nights and sore eyes and a lot of reading later I have finally gotten to a stage where I have a functional (perhaps a very under-utilized PIC 18F4530).
After having blinked LED's and read switches and getting my LCD working I would like to implement a keypad as opposed to a bank of dip switches.

I am trying to implement the keypad.bas file submitted by mister_e (Thanks mister e ... your code looks fantastic, I'm dying to use it properly :-)

So here's where I'm at now....

I am trying to connect a 4 x 4 matrix keypad to my 18F4520 PIC.

Ultimately I would like to be able to be able to type in a number, end it with a # to signify completed input and then transmit the inputted number to another pic either wired or wireless.

The keypad layout is as follows.
my keypad matrix

1 2 3 A
4 5 6 B
7 8 9 C
* 0 # D


I have connected the keypad to the pic as follows.

Keypad PIC

Column 0 PortA.0
Column 0 PortA.1
Column 0 PortA.2
Column 0 PortA.
Row 0 PortC.0
Row 1 PortC.1
Row 2 PortC.2
Row 3 PortC.3

10K pullups set on column inputs
100 Ohm resistors in series with rows

When I have the above configured my LCD just produces blocks

If I remove either the pullups and/or the series resistors I just get "Key Value" 20 continuously appearing on the LCD and if I press a key on the keypad I get the "key Value" changing on the LCD but it is not the correct value according to my keypad.

I could also use the whole of Port A but when I tried it but had the same results :-(

Initially I tried to connect on PortB and had the same results, so I assumed it was because I was getting inputs from pin 39 and pin 40 of the pic where the PICkit 2 is connected for ICSP.

I have attached my code below.

Please could someone advise as to where I am going wrong or what I could look at to fix the problem !

I think it could be a possible CONFIG problem or coding issue in my code.

Any help would be greatly appreciated.

Kind regards

Dennis

Code:
'*************************************
'LCD code for 16 X 2  HD4x lcd
'*************************************

'Ocsillator selections here
OSCCON = $70            'Int CLK 8MHz
OSCTUNE.6 = 1           'PLL 4x
ADCON1= %00001111       '$0F = disable A/D converter
'END of oscillator selections


'Port IO directions and presets for port pins begin here
'TRISA = %11111111       'All pins are outputs
TRISA.0 = 1
TRISA.1 = 1
TRISA.2 = 1
TRISA.3 = 1
TRISB = %00000000           
'TRISC = %00000000
TRISC.0 = 1           
TRISC.1 = 1
TRISC.2 = 1
TRISC.3 = 1

TRISD = %00000000
TRISE.0 = 0
TRISE.1 = 0
TRISE.2 = 0
'End of Port IO directions and presets for port pins begin here

'timer/oscillator defines 
DEFINE OSC 32            '4x 8MHz
'END of timer/oscillator defines
                      
'variables begin here
myvar var byte

'LCD defines begin here   
DEFINE LCD_BITS 4 	'defines the number of data interface lines (4 or 8) 
DEFINE LCD_DREG PORTD 	'defines the port where data lines are connected to
DEFINE LCD_DBIT 4 	'defines the position of data lines for 4-bit interface (0 or 4)
DEFINE LCD_RSREG PORTD 	'defines the port where RS line is connected to
DEFINE LCD_RSBIT 2 	'defines the pin where RS line is connected to 
DEFINE LCD_EREG PORTD 	'defines the port where E line is connected to 
DEFINE LCD_EBIT 3 	'defines the pin where E line is connected 
DEFINE LCD_RWREG 0 	'defines the port where R/W line is connected to (set to 0 if not used)
DEFINE LCD_RWBIT 0 	'defines the pin where R/W line is connected to (set to 0 if not used)
DEFINE LCD_COMMANDUS 2000 	'defines the delay after LCDOUT statement 
DEFINE LCD_DATAUS 200 		'delay in micro seconds
'END of LCD DEFINES

'KEYPAD 4x4 defines begin here
      DEFINE KEYPAD_ROW        4        ' 4 ROW keypad       
      DEFINE KEYPAD_ROW_PORT   PORTC    ' ROW port = PORTB
      DEFINE KEYPAD_ROW_BIT    0        ' ROW0 = PORTB.4
      DEFINE KEYPAD_COL        4        ' 4 COL keypad
      DEFINE KEYPAD_COL_PORT   PORTA    ' COL port = PORTB
      DEFINE KEYPAD_COL_BIT    0        ' COL0 = PORTB.0
      DEFINE KEYPAD_DEBOUNCEMS 200      ' debounce delay = 200 mSec
      DEFINE KEYPAD_AUTOREPEAT 1        ' use auto-repeat feature  
'End of KEYPAD defines

'*********************Includes******

include "C:\PBP\SAMPLES\KeyPad.bas"
'Includes end here

'Code begins here
   Pause 500       ' Wait for LCD to startup
 
start:
@ READKEYPAD _myvar
lcdout $fe, 1
lcdout " Key Value = ",DEC2 myvar
goto start