User Tools

Site Tools


en:pfw:tasto

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
en:pfw:tasto [2025-06-22 00:26] – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1en:pfw:tasto [2025-06-22 00:26] (current) – ↷ Seite von pfw:tasto nach en:pfw:tasto verschoben mka
Line 1: Line 1:
 +====== TASTO? ======
 +
 +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.
 +
 +{{:pfw:weissertaster.png?100|The small white button is on the breadboard at the bottom right of the picture.}}
 +
 +At [[en:pfw:clavis|CLAVIS?]] you can find out more about it.
 +
 +
 +===== 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 ====
 +
 +<code>
 +Function:  PININ ( mask -- ) 
 +           configure pin as input
 +Function:  TASTO? ( mask -- f )  \ flag is true if the key is not pressed (high level at pin)
 +           check digital voltage level 
 +</code>
 +
 +
 +==== 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.
 +No interrupt should occur, so it is disabled. 
 +The pin is used in the I/O function.
 +
 +Try more or fewer than five queries to eliminate the bouncing. (More on the [[pfw:topicofbouncing|topic of bouncing]].)
 +
 +<code>
 +\ test button
 +\ TI MSP430G2553 Launchpad with noForth mv 2553 240101 
 +
 +(* 
 +History
 +20250609 P1.7 digital input
 +
 +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 
 +
 +     Pin1.7--<---R---Button---GND
 + R=47K
 +*)
 +
 +hex
 +
 +80 constant pin7 \ mask for pin7 of port
 +    
 +: PININ ( 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, is irrelevant here.
 +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
 +  ;
 +  
 +
 +: TASTO? ( mask -- f )  \ Query button. debounced
 +  >r
 +  r@ 020 bit* 3 ms 
 +  r@ 020 bit* 3 ms
 +  and
 +  r@ 020 bit* 3 ms
 +  and  
 +  r@ 020 bit* 3 ms
 +  and
 +  r@ 020 bit* 3 ms
 +  and  
 +  r> =
 +  ;
 +
 +\ test  mk
 +: tt ( -- )
 +  pin7 pinin 
 +  begin  ( 100 ms )  \ add more ms if you like
 +  pin7 tasto? .
 +  key? until 
 +  ;
 +
 +shield nn\
 +freeze
 +( finis)
 +</code>
 +
 +==== Background information ====
 +
 +You can find them there: [[en:pfw:clavis|CLAVIS?]]
 +
 +
 +===== Contributions =====
 +
 +
 +===== Alternative Implementations =====
 +
 +You have another approach?
 +
 +Please add it at the end of this document.
 +
 +Sign in to post a comment.