Hi all
In a part of the project I am busy building I would like to type in a few numbers using a 4x4 matrix keypad ..for example the number 123
The keypad portion works well so far (I am using the example from mister_e in the code examples area of the forums)
What I am battling with is how to get the digits that are typed in to display on the LCD and then send them only after a # or * is keyed in.
This operation is very similar to the way a calculator or code entry system acts.
So let's say for example I type in the number 123#
If a mistake is made the * key could backspace or clear the display with a prompt to try again (I haven't yet worked out whether to use and array or a select case statement or a bunch of if then statements)
I would like all digits typed in to be displayed on the LCD (just like a calculator/phone/code entry system)
I store the 3 digits in an array datatx[3]
Then I add the three digits datatx[0]+datatx[1]+datatx[2]
(This should give me a single binary number right ?)
once I have that number I would like to send it to the PC using HSEROUT
Here's the code I have so far,
At this stage:Code:'************************************* 'Keypress display on LCD and TX to wherever '************************************* 'Ocsillator selections here OSCCON = $70 'Int CLK 8MHz OSCTUNE.6 = 1 'PLL 4x ADCON1= %00001111 '$0F = disable A/D converter cmcon = 7 INTCON2.7 = 0 'switch pull-ups ON 'END of oscillator selections 'timer/oscillator defines DEFINE OSC 32 '4x 8MHz 'END of timer/oscillator defines 'Port IO directions and presets for port pins begin here 'TRISX = %76543210 << tris bit order numbering 'TRISA = %11111111 'All pins are outputs '// Define port pins as inputs and outputs ... TRISA = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, TRISB = %11111111 'for 4x4 keypad all input TRISC = %10010000 TRISD = %00000000 TRISE.0 = 0 TRISE.1 = 0 TRISE.2 = 0 'End of Port IO directions and presets for port pins begin here 'variables begin here A0 var byte myvar var byte datatx var byte [3] datarx var byte counter var byte 'net var byte 'end of variables '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 'includes begin here INCLUDE "modedefs.bas" include "c:\pbp\samples\keypad.bas" 'end of includes DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0 DEFINE HSER_SPBRG 207 ' 2400 Baud @ 32MHz, 0.17% DEFINE HSER_CLROERR 1 ' Clear overflow automatically 'Keypad code begins here DEFINE KEYPAD_ROW 4 ' 4 ROW keypad DEFINE KEYPAD_ROW_PORT PORTB ' ROW port = PORTB DEFINE KEYPAD_ROW_BIT 0 ' ROW0 = PORTB.4 DEFINE KEYPAD_COL 4 ' 4 COL keypad DEFINE KEYPAD_COL_PORT PORTB ' COL port = PORTB DEFINE KEYPAD_COL_BIT 4 ' COL0 = PORTB.0 DEFINE KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec DEFINE KEYPAD_AUTOREPEAT 1 ' use auto-repeat feature 'end keypad code 'keypad capture code begins here Pause 2000 ' Wait for LCD to startup start: 'mister_e's keypad code lcdout "1=send 2=program 3= for counter = 0 to 3 @ READKEYPAD _myvar 'read keypress variable LOOKUP myvar,[0,"123A456B789C*0#D"],myvar 'use lookup table to diplay proper keypress datatx = myvar 'pass the variable to solve strange character problem lcdout "begin is ", dec datatx(0),dec datatx(1),dec datatx(2),dec datatx(3) 'display the variable on the LCD if datatx = "#" then goto TX 'if datatx = "*" then goto clearkeys pause 1000 Lcdout $fe,1 next counter if counter = 3 then goto clearkeys goto start TX: hserout ["i got this string of numbers",$0d,$0a] HSEROUT ["1st digit ", dec datatx(0),$0d,$0a] HSEROUT ["2nd digit ", dec datatx(1), $0d,$0a] HSEROUT ["3rd digit ", dec datatx(2), $0d,$0a] goto start clearkeys: datatx = 0 goto start end
The LCD shows the 3 digits but only the first one ever changes
Hserout sends the data to the PC but the values are always the same.
I would really appreciate it if someone could help point out where I am going wrong
Kind regards
Dennis
Bookmarks