\ morse-code-release.txt \ Morse Code Generator for the STM32F0 Discovery Board running Mecrisp-Stellaris (by Matthias Koch) \ The Disco Board LED's blink, green = Dot, Blue = Dash and PA4 can drive a Piezo loud speaker to hear the Morse Code as it's generated \ All Register names are CMSIS SVD compliant \ Registers Used: \ GPIOA , GPIOC \ \ ------------------------------------------------------------------------------------------------------ \ 1) Essential - Create and load a Memory Map file to provide the Memory Mapped Register Words used in this program \ (see Registers Used: above).To do this painlessly, see: http://128.199.141.78/_downloads/svd2forth-v2.zip \ 2) Then load this file: morse-code-release.txt \ I recommend using the e4thcom Terminal to do the above: http://128.199.141.78/serial-terminals.html \ ------------------------------------------------------------------------------------------------------ \ init must be run first, then morse, and send your message .... \ By quaak.haak@gmx.com, and terry@tjporter.com.au Feb 2016 \ Project licensed under the terms of the GNU General Public License as published by the Free Software Foundation, either version \ 3 of the License, or (at your option) any later version. : init ( -- ) \ Configure I/O, must be run first %01 8 2* lshift %01 9 2* lshift or GPIOC_MODER bis! \ Set PC8 and PC9 as output for LEDS %01 8 lshift GPIOA_MODER bis! \ Set PA4 to General purpose output mode. it drives a Piezo loud speaker to hear the Morse Code ; : green-on 1 9 lshift GPIOC_BSRR ! ; \ LED=green = DOT : green-off 1 9 lshift GPIOC_BRR ! ; : blue-on 1 8 lshift GPIOC_BSRR ! ; \ LED=blue = DASH : blue-off 1 8 lshift GPIOC_BRR ! ; : PA4-H %1 4 lshift GPIOA_BSRR ! ; \ Set PA4 "HIGH" around 2.8 volts : PA4-L %1 20 lshift GPIOA_BSRR ! ; \ Reset PA4 "LOW" around 0 volts : DELAY 300 0 DO LOOP ; \ 2597 Hz : TONE PA4-H DELAY PA4-L DELAY ; \ Generate one cycle to power the Piezo : WAVE 0 DO TONE LOOP ; \ one cycle only : WAIT * 125000 0 DO LOOP ; \ Dit/Dah delay : dit 250 WAVE ; \ Dit tone period : dah 650 WAVE ; \ Dah tone period : dot green-on dit green-off 1 WAIT ; : dash blue-on dah blue-off 1 WAIT ; : morseemit ( -- ) \ Ascii list of available Morse Code characters to emit case 32 OF ." -space- " 100000 0 DO LOOP ENDOF 39 OF ." ' " dot dash dash dash dash dot ENDOF 40 OF ." ( " dash dot dash dash dot ENDOF 41 OF ." ) " dash dot dash dash dot dash ENDOF 42 OF ." * " dot dash dash dot dash dot ENDOF 43 OF ." + " dot dash dot dash dot ENDOF 44 OF ." , " dash dash dot dot dash dash ENDOF 45 OF ." - " dash dot dot dot dot dash ENDOF 46 OF ." . " dot dash dot dash dot dash ENDOF 47 OF ." / " dash dot dot dash dot ENDOF 48 OF ." 0 " dash dash dash dash dash ENDOF 49 OF ." 1 " dot dash dash dash dash ENDOF 50 OF ." 2 " dot dot dash dash dash ENDOF 51 OF ." 3 " dot dot dot dash dash ENDOF 52 OF ." 4 " dot dot dot dot dash ENDOF 53 OF ." 5 " dot dot dot dot dot ENDOF 54 OF ." 6 " dash dot dot dot dot ENDOF 55 OF ." 7 " dash dash dot dot dot ENDOF 56 OF ." 8 " dash dash dash dot dot ENDOF 57 OF ." 9 " dash dash dash dash dot ENDOF 58 OF ." : " dash dash dash dot dot dot ENDOF 61 OF ." = " dash dot dot dot dash ENDOF 63 OF ." ? " dot dot dash dash dot dot ENDOF 64 OF ." @ " dot dash dash dot dash dot ENDOF 97 OF ." a " dot dash ENDOF 98 OF ." b " dash dot dot dot ENDOF 99 OF ." c " dash dot dash dot ENDOF 100 OF ." d " dash dot dot ENDOF 101 OF ." e " dot ENDOF 102 OF ." f " dot dot dash dot ENDOF 103 OF ." g " dash dash dot ENDOF 104 OF ." h " dot dot dot dot ENDOF 105 OF ." i " dot dot ENDOF 106 OF ." j " dot dash dash dash ENDOF 107 OF ." k " dash dot dash ENDOF 108 OF ." l " dot dash dot dot ENDOF 109 OF ." m " dash dash ENDOF 110 OF ." n " dash dot ENDOF 111 OF ." o " dash dash dash ENDOF 112 OF ." p " dot dash dash dot ENDOF 113 OF ." q " dash dash dot dash ENDOF 114 OF ." r " dot dash dot ENDOF 115 OF ." s " dot dot dot ENDOF 116 OF ." t " dash ENDOF 117 OF ." u " dot dot dash ENDOF 118 OF ." v " dot dot dot dash ENDOF 119 OF ." w " dot dash dash ENDOF 120 OF ." x " dash dot dot dash ENDOF 121 OF ." y " dash dot dash dash ENDOF 122 OF ." z " dash dash dot dot ENDOF endcase ; : morsetype ( addr len -- ) 0 do dup i + c@ morseemit loop drop ; : morse ( -- ) cr ." Type a message and press Enter: " query 0 parse \ Get a fresh line and parse everything inside, as character 0 never appears in input cr ." Sending morse code... " morsetype cr ; \ ................................................................................................................................... \ \ Note from Matthias \ \ I like your morse example, it is very readable and a good piece to show on how Forth works. But I have a hint: Morse code characters are delimited by small delays \ - instead you give a continuous stream of dashes and dots, without any character delays at all. Just insert a small pause after endcase, as morse is not a binary code :-) \ And, perhaps, define a “basis time” constant from which all timings are generated. Then, I will insert it into the mainstream release. \ \ The word PARIS is the standard for determing CW code speed. Each dit is one element, each dah is three elements, intra-character spacing is one element, \ inter-character spacing is three elements and inter-word spacing is seven elements. The word PARIS is exactly 50 elements. \ \ See: http://www.kent-engineers.com/codespeed.htm