**Dies ist eine alte Version des Dokuments!**
Inhaltsverzeichnis
CLAVIS?
A key (Italian tasto, Latin clavis) or a button is a control element that is operated by pressing and automatically returns to its original position when released.
Forth has KEY?
and KEY
to query the computer's keyboard. I therefore call the query of a different individual key something else. Figure below shows such a key.
Implementation for MSP430G2553
Here, the button is connected to pin 7 of port 1 of the MSP430G2553 microprocessor MCU. See circuit diagram in code.
I/O
This circuit provides a digital input, with the pin itself being the voltage source.
Pseudo code
Function: CONF ( mask -- ) configure pin as input Function: CLAVIS? ( -- f ) \ flag f is true or false check for falling edge at pin
Forth implementation (noForth)
The port pins are configured using registers. (see Manual) The configuration register table is specified in the code. The interrupt register indicates whether a falling edge was present.
In the direction register, P1.7 is set to digital IN. The integrated pull-up resistor is activated to support the high level. The integrated Schmidt trigger is set to the falling edge. However, no interrupt should occur, so it is disabled. The pin is used in the I/O function.
\ Query single button. \ TI MSP430G2553 Launchpad with noForth mv 2553 240101 (* History 20250614 P1.7 digital input; test falling edge. Port 1 addr acronym registername 020 P1IN Input 021 P1OUT Output 022 P1DIR Direction 023 P1IFG Interupt Flag 024 P1IES Interrupt Edge Select 025 P1IE Interrupt Enable 026 P1SEL Port Select 041 P1SEL2 Port Select2 027 P1REN Resistor Enable circuit diagram P1.7---R---C\_---GND R=47K *) \ asm\ ( include if assembler is your latest shield ) hex 80 constant pin7 \ mask for pin7 of port : CONF ( mask -- ) ( -- ) \ make pin to input ( 020 ) \ P1IN Input, read only dup 021 *bis \ P1OUT Output, pullup resistor set dup 022 *bic \ P1DIR Direction to IN dup 023 *bic \ P1IFG Interupt Flag, cleared dup 024 *bic \ P1IES Interrupt Edge Select, falling \_ dup 025 *bic \ P1IE Interrupt Enable, off dup 026 *bic \ P1SEL Port Select, I/O dup 041 *bic \ P1SEL2 Port Select2, I/O 027 *bis \ P1REN Resistor Enable, set ; : CLAVIS? ( mask -- f ) \ Query button. dup 023 bit* \ test for edge = ( true ) \ button has been pressed ( pin7 023 *bic ) \ clear edge detection in your app. ; (* Simple Test Wait for a key on the keyboard to be pressed so you can press the button first. \ *) \ uncomment for testing : tt ( -- f ) pin7 conf key drop pin7 clavis? .s ; shield nn\ freeze *) ( finis)
Background information
BIT** ( mask addr -- x ) \ AND mask with cell in addr
In noForth the bit manipulaton words with one star operate on the lower half of a cell.
See: https://home.hccnet.nl/anij/nof/noforth%20documentation.pdf
What is a Port?
See: Texas Instruments MSP430F2xx, MSP430G2xx Family User’s Guide - 8 Digital I/O, p.339ff
In short: The „port“ is formed by 9 registers. The registers are 8 bits wide. Each bit operates on „its“ pin. In its basic function, the pin can be used as a digital I/O. The direction register determines whether it is an input or output pin. The interrupt flag register is used here. It can detect a voltage edge and store it as an event bit. The functions of the other registers are described in more detail in the User’s Guide.
Contributions
Alternative Implementations
You have another approach?
Please add it at the end of this document.
Sign in to post a comment.