Benutzer-Werkzeuge

Webseiten-Werkzeuge


pfw:togglealedwithsingletasto

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung
Vorhergehende Überarbeitung
pfw:togglealedwithsingletasto [2025-06-21 21:28] – angelegt mkapfw:togglealedwithsingletasto [2025-06-22 00:20] (aktuell) – geöscht mka
Zeile 1: Zeile 1:
-===== Switch LED on and off in a button  ===== 
  
-Hier wird eine LED sauber an- und wieder aus geschaltet. 
- 
-==== Idea ==== 
- 
-Als Modell diente der Taster, der auch schon in der Demo von tasto und clavis benutzt worden ist. Im Taster ist eine LED integriert. Die soll getoggle werden. 
- 
-bild 
- 
- 
-==== Implementation ==== 
- 
-It's assumed that a program periodically checks whether the switch has been pressed and then changes the state of the LED. 
- 
-The challenge is to eliminate switch bounce so that the user gets a smooth, reliable impression of the changes. The response should be fast enough to be instantaneous, but slow enough to allow for a safe switchover. 
- 
-==== Pseudo code for the DUMP implementation ==== 
- 
-//What [[en:pfw:pseudocode|Pseudo code]] is.// 
- 
-<code> 
-Function: dump-line ( address -- ) 
-  output address (possibly right aligned) 
-  output ":" and some space 
-   
-  LOOP i from 0 to 15: 
-     output byte in memory at (address+i) as two hexadecimal digits (or in another radix if desired) 
-     output some space 
-   
-  LOOP i from 0 to 15: 
-     output byte in memory at (address+i) as an ASCII character, "." if that character is a control character (byte<32) 
-      
-Function: dump ( address length -- ) 
-   WHILE length is positive: 
-        dump-line at address 
-        increase address by 16 
-        decrease length by 16 
-</code> 
- 
-==== Minimal Forth implementation of DUMP: ==== 
- 
- 
-You can find a [[https://github.com/Project-Forth-Works/Project-Forth-Works.github.io/blob/main/minimalforth.md|Minimal Forth]] implementation of DUMP in [[en:pfw:dump-minimal_forth.fs|dump-Minimal_Forth.fs]]. 
- 
-You can use it as follows: 
- 
-<code forth> 
-  ok 
-Create x 100 allot  ok 
-x 100 dump 
-03D694: 05 61 6C 6C 6F 74 08 00 DF 14 00 00 C1 00 08 00   .allot..?...?... 
-03D6A4: 1F 18 00 00 C1 00 08 00 6F 10 00 00 C1 00 08 00   ....?...o...?... 
-03D6B4: 4F 10 00 00 C2 00 08 00 1F 13 00 00 C2 00 08 00   O...?.......?... 
-03D6C4: 8F 30 00 00 C2 00 08 00 DF 14 00 00 C2 00 08 00   ?0..?...?...?... 
-03D6D4: 1F 18 00 00 C2 00 08 00 6F 10 00 00 C2 00 08 00   ....?...o...?... 
-03D6E4: 4F 10 00 00 C3 00 08 00 8F 30 00 00 C3 00 08 00   O...?...?0..?... 
-03D6F4: 5F 13 00 00                                       _... ok 
-</code> 
- 
-As the original Minimal Forth has no output facility other than ''emit'' and ''.s'' (specifically no number formatting and no ''.'' or ''.r'') 
-this implementation seems to be over complicated. 
- 
-We extended Minimal Forth to [[https://github.com/Project-Forth-Works/Project-Forth-Works.github.io/blob/main/minimalforth.md|GenericForth]] to get a 
-more useful small Forth. 
- 
-A DUMP utility in **GenericForth** can be found in [[en:pfw:dump-genericforth.f|dump-GenericForth.f]] 
-This example is factored using the pseudo code description. The character output has been factored into the useful word PEMIT ( char -- ) too. 
- 
- 
-==== Various DUMP Implementations ==== 
- 
-Other DUMP implementations can be found at the end of this description. 
- 
-Your system might lack right justified number output or even BASE for printing numbers in other radix systems. The sample implementation in [[pfw:twomoredumps.f|twomoredumps.f]] show how to circumvent this. 
- 
- 
-==== Background information ==== 
- 
-More about the DUMP utility can found at the [[https://en.wikipedia.org/wiki/Hex_dump|Wikipedia page for hexdump]] 
- 
-Some Forth DUMP implementations display a fixed amount of bytes and leave the updated address on the stack so that 
-you can invoke DUMP repeatedly to display successive regions of memory. 
- 
-==== Possible pitfalls with DUMP ==== 
- 
-Some systems have hardware memory protection that is triggered if you access memory outside the reserved area. 
-The dump utility can do so by trying to show this forbidden memory. Triggered memory protect might stop the current process and 
-terminate your session. If necessary a suitable test for the validity of used addresses might be reasonable on such systems so that 
-dump can issue a normal error message (or display dummy data) in theses cases and leave the system / session otherwise intact. 
- 
-==== Contributions ==== 
- 
-<html><h2 style="background-color:yellow">Alternative Implementations</h2></html> 
- 
-You have another approach to DUMP? 
- 
-Please add it at the end of this document. 
- 
-~~DISCUSSION~~ 
pfw/togglealedwithsingletasto.1750534109.txt.gz · Zuletzt geändert: 2025-06-21 21:28 von mka