en:pfw:clavis
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
en:pfw:clavis [2025-06-22 00:23] – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | en:pfw:clavis [2025-06-22 00:23] (current) – ↷ Seite von pfw:clavis nach en:pfw:clavis verschoben mka | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== 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 '' | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | ===== 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 ==== | ||
+ | |||
+ | |||
+ | | ||
+ | configure pin as input | ||
+ | | ||
+ | check for falling edge at pin | ||
+ | |||
+ | |||
+ | ==== Forth implementation (noForth) ==== | ||
+ | |||
+ | The port pins are configured using registers. | ||
+ | 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 Schmitt-Trigger Input 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 | ||
+ | 022 P1DIR | ||
+ | 023 P1IFG | ||
+ | 024 P1IES | ||
+ | 025 P1IE Interrupt Enable | ||
+ | 026 P1SEL Port Select | ||
+ | 041 P1SEL2 | ||
+ | 027 P1REN | ||
+ | |||
+ | 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 | ||
+ | dup 022 *bic \ P1DIR | ||
+ | dup 023 *bic \ P1IFG | ||
+ | dup 024 *bic \ P1IES | ||
+ | dup 025 *bic \ P1IE Interrupt Enable, off | ||
+ | dup 026 *bic \ P1SEL Port Select, | ||
+ | dup 041 *bic \ P1SEL2 | ||
+ | 027 *bis \ P1REN | ||
+ | ; | ||
+ | | ||
+ | : 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:// | ||
+ | |||
+ | === What is a Port? === | ||
+ | |||
+ | In short: The " | ||
+ | |||
+ | See: Texas Instruments MSP430F2xx, MSP430G2xx Family User’s Guide - 8 Digital I/O, p.339ff | ||
+ | |||
+ | === How long is a key press? === | ||
+ | |||
+ | A manual short key press took around 120ms if I tapped the key only once. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | As you can see in the image, the key //bounces// briefly at the beginning until a stable LOW state is reached. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | In the second image, the bounce phase has been enlarged. After about 1ms, the bouncing was over. | ||
+ | |||
+ | The port pin reacts to the first falling edge. Subsequent edges, caused by bouncing, do not trigger anything. The next falling edge would only be registered once the interrupt flag has been reset by the program. | ||
+ | |||
+ | More on the [[pfw: | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== Contributions ===== | ||
+ | |||
+ | |||
+ | ===== Alternative Implementations ===== | ||
+ | |||
+ | You have another approach? | ||
+ | |||
+ | Please add it at the end of this document. | ||
+ | |||
+ | Sign in to post a comment. |