aaliyah1
- 13th April 2008, 15:22
Hi all
i am using a 18f452 with the 4 x4 keypad connected to portB
this is on the proton Development board and the connections are as the attachment below
All is get displayed on my lcd is
" Keypad Test "
"Press any key"
I have ran the program on micro studio ICD and the program seems to be struck
in this loop
==========================================
getkeyu:
' Wait for all keys up
PORTB = 0 ' All output pins low
TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop
Pause 50 ' Debounce
================================================== ====
Is there something i am missing
i have the complete code below and
================================================== ==============
DEFINE LOADER_USED 1 ' uses a bootloader
@ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H
Define OSC 20
clear
DEFINE LCD_DREG PORTD ' Use Portd for LCD Data
DEFINE LCD_DBIT 4 ' Use Upper(4) 4 bits of Port
' PORTD-4 thru PORTD-7 connects to
' LCD DB4 thru LCD DB-7 respectively
DEFINE LCD_RSREG PORTE ' PORTE for RegisterSelect (RS) bit
DEFINE LCD_RSBIT 0 ' PORTE-0 pin for LCD's RS line
DEFINE LCD_EREG PORTE ' PORTE for Enable (E) bit
DEFINE LCD_EBIT 1 ' PORTE-1 pin for LCD's E line
DEFINE LCD_BITS 4 ' Using 4-bit bus
DEFINE LCD_LINES 2 ' Using 2 line Display
DEFINE LCD_COMMANDUS 2000 ' Command Delay (uS)
DEFINE LCD_DATAUS 50 ' Data Delay (uS)
' ** Define LCD Control Constants **
I CON 254 ' Control Byte
Clr CON 1 ' Clear the display
Line1 CON 128 ' Point to beginning of line 1
Line2 CON 192 ' Point to beginning of line 2
Line3 CON 148 ' Point to beginning of line 3
Line4 CON 212 ' Point to beginning of line 4
'
' Initialise Hardware
' -------------------
TRISA=%00000000
TRISB=%00000000
TRISC=%10000000
TRISD=%00000000
INTCON2.7 = 1 ' Enable PORTB pullups
ADCON1 = 7 ' Make PORTA and PORTE digital
Low PORTE.2 ' LCD R/W low (write)
Pause 1000 ' Wait for LCD to start
lcdout I,Clr:Pause 30
lcdout I,Line1," Keypad TEST "
lcdout I,Line2,"..Power On.. !!"
' Define program variables
col var byte ' Keypad column
row var byte ' Keypad row
key var byte ' Key value
lcdout I,Clr:Pause 30
lcdout I,Line1," Keypad Test "
lcdout I,Line2, "Press any key" ' Display sign on message
loop: Gosub getkey ' Get a key from the keypad
lcdout I,Clr:Pause 30
lcdout I,Line3, #key
Pause 50
Goto loop ' Do it forever
' Subroutine to get a key from keypad
getkey:
Pause 50 ' Debounce
getkeyu:
' Wait for all keys up
PORTB = 0 ' All output pins low
TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
If ((PORTB >> 4) != $f) 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 != $f Then gotkey ' If any keydown, exit
Next col
Goto getkeyp ' No keys down, go look again
gotkey: ' Change row and column to key number 1 - 16
key = (col * 4) + (ncd (row ^ $f))
Return ' Subroutine over
End
Best Regards
Sabu
i am using a 18f452 with the 4 x4 keypad connected to portB
this is on the proton Development board and the connections are as the attachment below
All is get displayed on my lcd is
" Keypad Test "
"Press any key"
I have ran the program on micro studio ICD and the program seems to be struck
in this loop
==========================================
getkeyu:
' Wait for all keys up
PORTB = 0 ' All output pins low
TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
If ((PORTB >> 4) != $f) Then getkeyu ' If any keys down, loop
Pause 50 ' Debounce
================================================== ====
Is there something i am missing
i have the complete code below and
================================================== ==============
DEFINE LOADER_USED 1 ' uses a bootloader
@ __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H
Define OSC 20
clear
DEFINE LCD_DREG PORTD ' Use Portd for LCD Data
DEFINE LCD_DBIT 4 ' Use Upper(4) 4 bits of Port
' PORTD-4 thru PORTD-7 connects to
' LCD DB4 thru LCD DB-7 respectively
DEFINE LCD_RSREG PORTE ' PORTE for RegisterSelect (RS) bit
DEFINE LCD_RSBIT 0 ' PORTE-0 pin for LCD's RS line
DEFINE LCD_EREG PORTE ' PORTE for Enable (E) bit
DEFINE LCD_EBIT 1 ' PORTE-1 pin for LCD's E line
DEFINE LCD_BITS 4 ' Using 4-bit bus
DEFINE LCD_LINES 2 ' Using 2 line Display
DEFINE LCD_COMMANDUS 2000 ' Command Delay (uS)
DEFINE LCD_DATAUS 50 ' Data Delay (uS)
' ** Define LCD Control Constants **
I CON 254 ' Control Byte
Clr CON 1 ' Clear the display
Line1 CON 128 ' Point to beginning of line 1
Line2 CON 192 ' Point to beginning of line 2
Line3 CON 148 ' Point to beginning of line 3
Line4 CON 212 ' Point to beginning of line 4
'
' Initialise Hardware
' -------------------
TRISA=%00000000
TRISB=%00000000
TRISC=%10000000
TRISD=%00000000
INTCON2.7 = 1 ' Enable PORTB pullups
ADCON1 = 7 ' Make PORTA and PORTE digital
Low PORTE.2 ' LCD R/W low (write)
Pause 1000 ' Wait for LCD to start
lcdout I,Clr:Pause 30
lcdout I,Line1," Keypad TEST "
lcdout I,Line2,"..Power On.. !!"
' Define program variables
col var byte ' Keypad column
row var byte ' Keypad row
key var byte ' Key value
lcdout I,Clr:Pause 30
lcdout I,Line1," Keypad Test "
lcdout I,Line2, "Press any key" ' Display sign on message
loop: Gosub getkey ' Get a key from the keypad
lcdout I,Clr:Pause 30
lcdout I,Line3, #key
Pause 50
Goto loop ' Do it forever
' Subroutine to get a key from keypad
getkey:
Pause 50 ' Debounce
getkeyu:
' Wait for all keys up
PORTB = 0 ' All output pins low
TRISB = $f0 ' Bottom 4 pins out, top 4 pins in
If ((PORTB >> 4) != $f) 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 != $f Then gotkey ' If any keydown, exit
Next col
Goto getkeyp ' No keys down, go look again
gotkey: ' Change row and column to key number 1 - 16
key = (col * 4) + (ncd (row ^ $f))
Return ' Subroutine over
End
Best Regards
Sabu