View Full Version : Keypad input.
Rooster
06-12-00, 08:59 AM
I recently purchased a NMIY-20 with keypad and LCD display. Being new to Forth programing, I'm having a terrible time geting keypad characters converted to a number. Would some one please send me code that will do this.I would also like to know where I can find examples of Max-Forth core words. I found examples of FP words at UA Canada. I have automated a tool by puting a gear-box and motor on it. I have a Max-Forth program that allows a operator to performs 6 different functions with the tool. I already have sales for the tool but can only run it from a PC. Please help.<br> Jerry
Here are some words from NMI:<p>( wait for a keypad key<br>: KP-KEY ( -- button )<br> BEGIN KP-?TERMINAL UNTIL KEYPAD C@ 2/ 2/ 2/ ;<p>CREATE ASCIIFY ( a table for keypad translation)<br> 52 C, 45 C, 53 C, 55 C, ( RTT Enro Stat Unav )<br> 41 C, 4F C, 41 C, 43 C, ( Ack On L Avai Clear)<br> 31 C, 34 C, 37 C, 55 C, ( 1 4 7 Down )<br> 32 C, 35 C, 38 C, 30 C, ( 2 5 8 0 )<br> 33 C, 36 C, 39 C, 44 C, ( 3 6 9 Up )<p>( return the ascii version of the keys, wait for key release<br>: PADKEY ( -- char )<br> KP-KEY ASCIIFY + C@ KP-RELEASE ;<p><br>( NUMBER INPUT VIA KEYPAD AND DISPLAY<p>( true if char is not a digit<br>: NOTDIGIT? ( char -- char flag )<br> DUP 30 < OVER 39 > OR ;<p>( wait for a single digit. reject any non-digit and continue waiting<br>( return the value of the digit 0--9<br>: 1DIGIT ( -- n )<br> BEGIN PADKEY NOTDIGIT? WHILE DROP REPEAT DUP DSP-EMIT 30 - ;<p>( wait for n digits, return the accumulated value<br>: DIGITS ( n -- n )<br> 0 SWAP 0 DO 0A * 1DIGIT + LOOP ;<p>( user input of a number<br>( : GET-NUMBER ( -- n )<br>( DSP-CLEAR ( 0 DSP-AT) DSP" INPUT? " 5 DIGITS ;<p>: LOOP-KEY HOME BEGIN PADKEY DSP-EMIT ?TERMINAL UNTIL ;<p>You'll have to change the table to match your keypad.<p>Steve
nmitech
06-12-00, 12:09 PM
Thanks steve for your prompt response.<p>I also found this appnote in this forum posted by Rob. Hope this will help. Check it out. <br>http://www.compusmart.ab.ca/rc/Pobox/FORTH/EXAMPLES/POBOX.F<p>
Rooster
06-19-00, 10:26 PM
Thanks Steve,<br>Sometimes you can't see the forest for the trees. Forth is great stuff once you figure out how it works. Thanks to you too New-Micro for NMIY-20.<br> Rooster
I switched two pair of wires at the connector to eliminate the need for a translation table. No soldering or crimping is needed - the terminals can be released from the connector body with a pointed tool. The resulting code isn't long, but it may not be readable in this format. Let me know if you want it emailed or posted on my web site. I can offer more code that way, too.<p>Jerry http://users.erols.com/jyavins<p>( Grayhill Keypad Series 86, marked 86JB2-202 G-97-059-J-9742 D$FPJ<br>( Leads H <-> J and L <-> M are interchanged to simplify decoding.<br>( NMI's Keypad.4th, as modified. JYA; 7Aug98<p>( KEYPAD ROUTINES )<p>B00A CONSTANT KEYPAD<p>( true if a keypad key is pressed<br>: ?KEYPAD ( -- flag ) B000 C@ 1 AND ;<p>( wait for keypad key to be released<br>: KP-RELEASE ( -- ) BEGIN ?KEYPAD 0= UNTIL ;<p>( wait for a keypad key<br>: KP-KEY ( -- button )<br> BEGIN ?KEYPAD UNTIL KEYPAD C@ U2/ U2/ U2/ ;<p>: >CHAR ( n -- c ) DUP 9 > 7 AND + 30 + ;<p>( Return the key number, wait for key release )<br>: KEY# ( -- n ) KP-KEY KP-RELEASE ;<p>( NUMBER INPUT VIA KEYPAD AND DISPLAY<p>( wait for a single digit. reject any non-digit and continue waiting<br>( return the value of the digit 0 to BASE 1-<br>: 1DIGIT ( -- n ) ( n -> LCD<br> BEGIN KEY# DUP BASE @ < NOT WHILE DROP REPEAT<br> DUP >CHAR LCD-EMIT ;<p>( wait for n digits, return the accumulated value<br>: DIGITS ( # -- n ) ( # digits -> LCD<br> 0 SWAP 0 DO BASE @ * 1DIGIT + LOOP ;<p>( Cheap user input of a number<br>: GET-NUMBER ( #digits -- n ) ( But n is garbage if too many digits. )<br> LCD-CLR DIGITS ;<br>
The code needs U2/ , an unsigned 2/ , the same as shift right. Here it is<p>CODE U2/ ( 48 cycles<br> 1864 , 00 C, ( LSR 0,Y<br> 1866 , 01 C, ( ROR 1,Y<br> 7E C, FE4A , ( JMP NEXT <br>END-CODE<p>I'm sorry for the omission. (That's not an apology, but an admission of embarrassment.)<p>Jerry<br>http://users.erols.com/jyavins<p><p>----------<br>Engineering is the art of making what you want from things you can get.<br>
Rooster
06-22-00, 06:36 PM
Thanks Guys for helping me with getting info from the keypad. I hope I am not wearing out my welcome but I also need help with prompting for information to the LCD. For instance how would I send info to the LCD to ask for MMI input. It's hard for a 62 year old to learn this Forth stuff. Please be patient. Jerry (Rooster) Lowery <br> <br>
OK. Here's my LCD code. It's for a two-line by 40 display, but other sizes are easily programmed. I just didn't see a reason to make it more general.<p>\ Support and demo for 2 line by 40 character display. Thanks with nod to NMI<br> B080 CONSTANT LCD-CMD B081 CONSTANT LCD-DAT<p>\ Wait until the LCD isn't busy.<br>: LCD-WAIT ( -- ) BEGIN LCD-CMD C@ 80 AND 0= UNTIL ;<p>\ Send command or data to LCD.<br>: LCD-CMD! ( C -- ) LCD-WAIT LCD-CMD C! ;<br>: LCD-EMIT ( C -- ) LCD-WAIT LCD-DAT C! ;<p>\ Make specific LCD command words.<br>: LCD-MAKE ( c -- ) CREATE , DOES> ( -- ) @ LCD-CMD! ;<p> 1 LCD-MAKE LCD-CLR 2 LCD-MAKE LCD-HOME 8 LCD-MAKE LCD-OFF<br> C LCD-MAKE LCD-ON ( On, no cursor ) E LCD-MAKE LCD-CUR ( On, with cursor )<p>: LCD-ATTR ( blink? cursor? display? -- ) \ Sets three display attributes<br> 0= 3 + 2* SWAP 0= 1+ OR 2* SWAP 0= 1+ OR LCD-CMD! ;<p>14 CONSTANT EMIT-CB-PTR FFA4 CONSTANT UART-TX-CB<p>CREATE LCD-CB ( EMIT control block for LCD ) LCD-CMD , 80 C, 80 C, LCD-DAT ,<br>\ There is no provision there for a driver to handle CR, LF, BS, etc.<p>\ The next 2 words translate cursor locations by number to and from LCD<br>\ data RAM addresses and add (on write) or strip (on read) the control bits.<p>: LCD-AT ( a -- ) 80 OR DUP A7 > 18 AND + LCD-CMD! ; \ Write cursor addr<br>\ Undocumented: FF LCD-CMD! resets the cursor, so BS doesn't need to check.<p>: LCD-AT? ( -- a ) LCD-CMD C@ DUP 27 > 18 AND - ; \ Get current cursor.<br>\ This supposes that the display isn't reading GC RAM. The supposition is<br>\ true if LCD-CG! hasn't been executed, or if LCD-AT was executed after it.<p>\ Set character-generator address. LCD-AT? reads CG RAM addresses after this.<br>: LCD-CG! ( a -- ) 3F AND 40 OR LCD-CMD! ;<p>\ Carriage return, line feed, backspace, ->, and <-. All but BS and CR wrap.<br>: LCD-CR ( -- ) LCD-AT? 27 > 28 AND LCD-AT ;<br>: LCD-LF ( -- ) LCD-AT? DUP 27 > IF 28 - ELSE 28 + THEN LCD-AT ;<br>: LCD-BS ( -- ) LCD-AT? 1- DUP LCD-AT BL LCD-EMIT LCD-AT ;<br>: LCD+ ( -- ) LCD-AT? 1+ LCD-AT ; \ Advances cursor position<br>: LCD- ( -- ) LCD-AT? 1- LCD-AT ; \ Backs cursor position<p>\ Smart LCD-EMIT that knows linefeed, carriage return, and backspace.<br>: >LCD ( terminal? c -- terminal? )<br> DUP 8 = IF OVER IF BL EMIT EMIT ELSE DROP THEN LCD-BS EXIT THEN<br> DUP A = IF DROP LCD-LF EXIT THEN<br> DUP D = IF DROP LCD-CR EXIT THEN<br> LCD-EMIT ;<p>There's more, but this will get you started.<p>Jerry<p>----------<br>Engineering is the art of making what you want from things you can get.<br>
Again, an embarrassing omission! The numbers in my code are Hexadecimal.<p>----------<br>Engineering is the art of making what you want from things you can get.<br>
vBulletin v3.0.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.