digilord
- 29th December 2005, 21:33
Hello All,
I have a Storm 1000 12 key keypad. It's setup as a matrix. I setup my PIC (16F88) with port A as 3 outputs and 4 inputs. Here is my code:
'************************************************* ***************
'* Name : Keypad.BAS *
'* Author : Daniel Morrigan *
'* Notice : Copyright (c) 2005 Daniel Morrigan *
'* : All Rights Reserved *
'* Date : 12/29/2005 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
' Boot loader is used
DEFINE LOADER_USED 1
' Oscilator timing is set for 8Mhz
DEFINE OSC 8
' Set Baud Rate
DEFINE HSER_BAUD 9600
' Clear UART overflow error
DEFINE HSER_CLROERR 1
' Enable transmit and receive
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
' Set port A for digital inputs & outputs
ANSEL=0
CMCON=0
trisa.2=1
trisa.3=1
trisa.4=1
trisa.0=0
trisa.1=0
trisa.6=0
trisb.0=0
' Setup Rows & Cols for the keypad reader
C1 VAR porta.4
C2 VAR porta.3
C3 VAR porta.2
RA VAR porta.0
RB VAR portb.0
RC VAR porta.6
RD VAR porta.1
' Setup a var to store the value of the key pressed
key var word
' Set the columns to be low
Low c1
low C2
Low C3
Pause 500
loop:
High C1 ' Bring col 1 high & look for each key
pause 100
IF RA then key="7"
if RB then key="4"
if RC then key="1"
if RD then key="*"
Low c1
hserout [key]
High C2 ' Bring col 2 high & look for each key
pause 100
IF RA then key="8"
if RB then key="5"
if RC then key="2"
if RD then key="0"
Low c2
hserout [key]
pause 100
High C3 ' Bring col 3 high & look for each key
IF RA then key="9"
if RB then key="6"
if RC then key="3"
if RD then key="#"
Low c3
hserout [key]
hserout [10,13]
gosub blink ' Blink to let me know we went through an interation
goto loop
end
blink:
High PORTB.3 ' Turn on LED connected to PORTB.3
Pause 1000 ' Delay for 1 seconds
Low PORTB.3 ' Turn off LED connected to PORTB.3
Pause 1000
return
I am not getting what I expected in the output. I am getting random keys. I looked for a similar solution here thinking someone else may have done this in the past.
The rows and cols are setup to interface directly to the buttons.
Any insights?
I have a Storm 1000 12 key keypad. It's setup as a matrix. I setup my PIC (16F88) with port A as 3 outputs and 4 inputs. Here is my code:
'************************************************* ***************
'* Name : Keypad.BAS *
'* Author : Daniel Morrigan *
'* Notice : Copyright (c) 2005 Daniel Morrigan *
'* : All Rights Reserved *
'* Date : 12/29/2005 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
' Boot loader is used
DEFINE LOADER_USED 1
' Oscilator timing is set for 8Mhz
DEFINE OSC 8
' Set Baud Rate
DEFINE HSER_BAUD 9600
' Clear UART overflow error
DEFINE HSER_CLROERR 1
' Enable transmit and receive
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 20h
' Set port A for digital inputs & outputs
ANSEL=0
CMCON=0
trisa.2=1
trisa.3=1
trisa.4=1
trisa.0=0
trisa.1=0
trisa.6=0
trisb.0=0
' Setup Rows & Cols for the keypad reader
C1 VAR porta.4
C2 VAR porta.3
C3 VAR porta.2
RA VAR porta.0
RB VAR portb.0
RC VAR porta.6
RD VAR porta.1
' Setup a var to store the value of the key pressed
key var word
' Set the columns to be low
Low c1
low C2
Low C3
Pause 500
loop:
High C1 ' Bring col 1 high & look for each key
pause 100
IF RA then key="7"
if RB then key="4"
if RC then key="1"
if RD then key="*"
Low c1
hserout [key]
High C2 ' Bring col 2 high & look for each key
pause 100
IF RA then key="8"
if RB then key="5"
if RC then key="2"
if RD then key="0"
Low c2
hserout [key]
pause 100
High C3 ' Bring col 3 high & look for each key
IF RA then key="9"
if RB then key="6"
if RC then key="3"
if RD then key="#"
Low c3
hserout [key]
hserout [10,13]
gosub blink ' Blink to let me know we went through an interation
goto loop
end
blink:
High PORTB.3 ' Turn on LED connected to PORTB.3
Pause 1000 ' Delay for 1 seconds
Low PORTB.3 ' Turn off LED connected to PORTB.3
Pause 1000
return
I am not getting what I expected in the output. I am getting random keys. I looked for a similar solution here thinking someone else may have done this in the past.
The rows and cols are setup to interface directly to the buttons.
Any insights?