Download Print this page

Advertisement

Quick Links

Electronics Prototyping, Custom Design, Product Development
MEMKey
Keypad Encoder
*4X5 Matrix
*Programmable Rows & Columns
*PC/AT or Serial Output
AN-303 A Simple Calculator Using a Basic Stamp II
This application demonstrates the use of a MEMKey in a 7 digit decimal
calculator consisting of a 2x8 LCD screen and a Grayhill 4x4 keypad. The LCD,
operating in 4-bit mode, is driven by a Basic Stamp II while a MEMKey serial
keypad encoder interfaces to the keypad.
The calculator performs binary addition and subtraction. Subtraction is
accomplished by taking the 9's complement of one operand and adding it to
another. The keypad, a Grayhill 96 series, has four function keys. "A" (location
3) is the addition key, "B" (location 7) is the subtraction key, "C" (location 11) is
the equals key, while "D" (location 15) serves as a reset button.
When overflow occurs (result is greater than 7 digits), "OVERFLOW" appears at
the top of the screen and the calculator waits for a reset signal.
The MEMKey's row and column configuration defaults to the low cost Grayhill 96
series keypads, which are available from both Parallax and Digi-Key. The 2x8
LCD screen (Optrex DMC-50448N) that this application uses is also available
from Digi-Key. A hardware schematic follows:
Phone
(530) 891-8045
Fax
(530) 891-1643
e-mail
solcubed@solutions-cubed.com
SOLUTIONS CUBED
Come visit our Web Site www.solutions-cubed.com
256 East First Street
Chico, CA 95928

Advertisement

loading
Need help?

Need help?

Do you have a question about the MEMKey and is the answer not in the manual?

Questions and answers

Summary of Contents for SOLUTIONS CUBED MEMKey

  • Page 1 This application demonstrates the use of a MEMKey in a 7 digit decimal calculator consisting of a 2x8 LCD screen and a Grayhill 4x4 keypad. The LCD, operating in 4-bit mode, is driven by a Basic Stamp II while a MEMKey serial keypad encoder interfaces to the keypad.
  • Page 2 SOLUTIONS CUBED Electronics Prototyping, Custom Design, Product Development AN-303 Simple Calculator code listing ‘ Authors: Mark Rutger Jansen, ‘ Michael Walton ‘ ' Variable and Constant Declarations ‘ ' Calculator Variables: Operand1 Nib(8) ' First operand in binary addition (Bottom line of...
  • Page 3 ' Read key value command Default ' Resets MEMKey to default values Rbuffer ' Read key in buffer '******************************************************************************************* ' This routine initializes the Basic Stamp, LCD, and MEMKey. ' Initialize the BS2 BS2_ini: DirH = %01111111 ' set pins 8-15 direction...
  • Page 4 MEMKey_ini: HIGH ' Make sure FM is high PAUSE 2000 ' Let the system power settle SEROUT FM,Baud,[PConfig,Config] ' Configure MEMKey for Polled Mode PAUSE ' Pause 10ms for EEPROM access SEROUT FM,Baud,[PDBounce,DBounce] ' Program debounce value PAUSE ' Pause 10ms for EEPROM access...
  • Page 5 GOSUB LCDwr ' Write ASCII character to LCD Next RETURN '******************************************************************************************* ' The Reset subroutine returns the MEMKey to it's initial settings. It also ' resets the LCD display values. Reset: SEROUT FM,Baud,[Default] ' Reset MEMKey to default settings PAUSE...
  • Page 6 SOLUTIONS CUBED Electronics Prototyping, Custom Design, Product Development Next ' Reset display values For Index = $00 to $07 ' Loop through positions 0 - 7 in Lookup Table LOOKUP Index,[15,15,15,15,15,15,15,0], B_3 Operand1(Index) = B_3 ' Store values from table to Operand1...
  • Page 7 SOLUTIONS CUBED Electronics Prototyping, Custom Design, Product Development ShiftDisplay: If OpIndex < 7 then TestZero ' Test if Operand is greater than 7 digits RETURN TestZero: If OpIndex <> 0 then ValidShift ' Test if no digits have been entered yet...
  • Page 8 SOLUTIONS CUBED Electronics Prototyping, Custom Design, Product Development '******************************************************************************************* ' This function converts Operand1 to a negative number using the 9's compliment number system NegateOperand1: For Index = 1 to 7 ' Loop through positions 1 - 7 in Operand1...
  • Page 9 SOLUTIONS CUBED Electronics Prototyping, Custom Design, Product Development DisplayOverflow: Char ' Display line one GOSUB LCDcmd For Index = $00 to $07 Operand2(Index) = 15 ' Place " " to clear Op1 ' Write "OVERFLOW" to display LOOKUP Index,["O","V","E","R","F","L","O","W"],Char GOSUB LCDwr...
  • Page 10 SOLUTIONS CUBED Electronics Prototyping, Custom Design, Product Development Operand2Continue: Carry = 0 ' Initialize Carry indicator to 0 For Index = 7 to 0 ' Loop backwards through digits of Operands Debug "Index: " Debug dec Index, cr Debug "Operand1: "...
  • Page 11 SOLUTIONS CUBED Electronics Prototyping, Custom Design, Product Development Debug " Carry: " Debug dec Carry, cr Operand2(Index) = Char//10 ' Write digit to Operand2 Operand1(Index) = 15 ' Place " " to clear Op1 Next NoSubOverflow: ' Check to see if Operand1 is negative If Operand1(0) <>...
  • Page 12 ' buffer size of 8 bytes. It is likely that only one key value will be returned since the typematic rate ' has been truned off in the MEMKey. The SERIN "escape clause" has been set to 50ms to ensure that ' the serial communication does not hang up the program.