First paragraph under schematic.
Notes & Eratta:
First paragraph under schematic I state: Also, it's worth while noting that the 4MHz crystal isn't critical, you could if you wish use an RC oscillator. You'll save a few bucks. <hr/>*This assumes that you won't be connecting the keypad to the serial port. A crystal is mandatory if you intend to build the project entirely as presented.
Need to capture several button presses ending in a #
Hi All
I would like to pronpt the user on my LCD for input ...
capture several key presses followed by a hash # signifying input is complete ...for example 123#
Display it on the LCD
Then transmit the number 123
I'm guessing something like
Code:
newkey VAR byte ' this would equal keypress1 , 2,3 etc
Pause 500 ' Wait for LCD to startup
main:
Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Enter key followed by #" ' prompt user for input # denotes end of input
HERE"S where I'm struggling << how do i get the keypresses into one VAR
Lcdout "Input successful"
SEROUT RX_To_PC, N2400, [newkey]
pause 2000
Lcdout "Code sent"
goto main
So would i alter (if I may and can) Steves keypad code to somthing like
Instead of the Serout in the program send the first keypress to something like
Key_Press1 then Key_Press2 then Key_Press3 etc ...
and keep doing it until a # input is observed ?
Is this possible ?
Any help would be appreciated
Kind regards
Dennis
1 Attachment(s)
Re: Complete Keypad Example
No more posts here...but hope to find help :) !
I try to build this device ; on pushing on different button - having one different result !
But...nothing happens :( ... Something's wrong ! Any advice ? Thanks !
Code:
@ DEVICE pic16F628A, INTRC_OSC, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_ON, LVP_OFF, CPD_OFF, PROTECT_OFF
Include "modedefs.bas" ' Serial Protocol
Define OSC 4 ' 4MHz crystal used
CMCON = 7 ' Disable on-chip comparator, PORTA in digital mode
'// Define port pins as inputs and outputs ...
TRISA = %00001000
TRISB = %00001100
'// Declare Variables...
Col_A VAR PORTB.1
Col_B VAR PORTA.2
Row_A VAR PORTA.3
Row_B VAR PORTB.3
Row_C VAR PORTB.2
Buzzer VAR PORTB.5
Scan_Col VAR BYTE ' Counter - denoting current col in scan
Key_Press VAR BYTE ' Contains value of key (0-9) & * + #
Key_Down VAR BYTE ' Flag set true when key is depressed
Allow_Key VAR BYTE ' Flag - disallow multiple keys being pressed
I VAR byte ' General working var
Scan_Keypad:
'// Scan cols
@ incf _Scan_Col, 1 ' Inc col pos...
SELECT CASE Scan_Col ' Col (1-2)
CASE 1
Col_A = 0 ' Switch on col (active low)
Col_B = 1 ' Col off
'// 3 Key
IF Row_A = 0 THEN ' Key down? ...
IF Allow_Key = 0 THEN ' Any other key down?
Key_Press = 3 ' Load var w/value of key
Allow_Key = 1 ' Disallow other keys
ENDIF
ENDIF
'// 6 Key
IF Row_B = 0 THEN
IF Allow_Key = 0 THEN
Key_Press = 6
Allow_Key = 1
ENDIF
ENDIF
'// 9 Key
IF Row_C = 0 THEN
IF Allow_Key = 0 THEN
Key_Press = 9
Allow_Key = 1
ENDIF
ENDIF
CASE 2
Col_A = 1
Col_B = 0
'// 2 Key
IF Row_A = 0 THEN
IF Allow_Key = 0 THEN
Key_Press = 2
Allow_Key = 1
ENDIF
ENDIF
'// 5 Key
IF Row_B = 0 THEN
IF Allow_Key = 0 THEN
Key_Press = 5
Allow_Key = 1
ENDIF
ENDIF
'// 8 Key
IF Row_C = 0 THEN
IF Allow_Key = 0 THEN
Key_Press = 8
Allow_Key = 1
ENDIF
ENDIF
Scan_Col = 0
END SELECT
'// Ouput key
IF Key_Down <> Key_Press THEN ' Key already been sent?
IF Key_Press <> 255 THEN ' 255 denotes no key press
IF Key_Press = 42 OR Key_Press = 35 THEN ' Numerical key?
'// Brief chrip of the piezo & flash of the LED
for i = 0 to 20
toggle buzzer
pause 5
next
gosub result_key
ENDIF
Key_Down = Key_Press ' Copy of key just sent
Buzzer = 0 ' Make sure LED is off
ENDIF
endif
'// Check for key release, all cols on (active low) ...
Col_A = 0
Col_B = 0
'// Reset flags allowing other keys to be processed if no keys are depressed
IF Row_A = 1 THEN
IF Row_B = 1 THEN
IF Row_C = 1 THEN
Allow_Key = 0
Key_Down = 0
Key_Press = 255
ENDIF
ENDIF
ENDIF
GOTO Scan_Keypad ' Loop back
Result_key :
SELECT CASE key_press
case 3
high buzzer
pause 1000
low buzzer
case 6
high buzzer
pause 2000
low buzzer
case 9
high buzzer
pause 3000
low buzzer
end select
return
Re: Complete Keypad Example
Solved in another way... Thanks to Mr.Mister_e and Mr.Darrel !!!
The hardware is now : col_0 = portB.0 ; col_1 = portB.1 ; row_1-3 = portA.0-2
Code:
@ DEVICE pic16F628A, INTRC_OSC, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_ON, LVP_OFF, CPD_OFF, PROTECT_OFF
Include "modedefs.bas" ' Serial Protocol
Define OSC 4 ' 4MHz crystal used
CMCON = 7 ' Disable on-chip comparator, PORTA in digital mode
'// Define port pins as inputs and outputs ...
TRISA = %00000111
TRISB = %00000000
Buzzer VAR PORTB.5
include "c:\pbp\keypad2.pbp" ' see http://www.picbasic.co.uk/forum/showthread.php?t=3250
main:
gosub keypadscan
gosub check
goto main
check:
select case key
case 1
high buzzer
pause 1000
low buzzer
case 2
high buzzer
pause 2000
low buzzer
case 3
high buzzer
pause 3000
low buzzer
case 4
high buzzer
pause 4000
low buzzer
case 5
high buzzer
pause 5000
low buzzer
case 6
high buzzer
pause 6000
low buzzer
end select
Return
end 'of story !
Maybe it's useful for somebody !