Simplified Morse Code ID/Beacon Generator 08M2

radiosparks

Active member
The ease at which to program the PICAXE is truly astounding. I thought a Morse code generator would be a “NO BRAINER” but was caught off guard. There are so many different ways to create this type of code.

Most programs need the user to map the ASCII to a binary code to create the data string. “That hurt my head.” I just wanted to enter a string of ASCII and let the MCU handle the mapping.

This was cobbled together from some interesting snippets of code found by scanning around the forum and READING all things of interest.

QUOTE: mrburnette: “It is by evolving concepts and existing code bases that code evolution occurs”

Discovering new ways to optimize my code to fit in a restricted microcontroller environment, like the PICAXE, is helping me to become a better programmer.

The RC network you see on the breadboard acts as a low pass filter to remove the harmonics and is just to soften the harsh tone from the piezo transducer.

There is more than enough memory to add more features. All the code doesn't fit in the post see part 2.


Code:
#REM
-----------------------------------------------------------------------

    PICAXE-08M2 Simplified Morse Code Generator - rhb.20230913

     NOTE: Only alpha and numerals are used in this demonstration.
          Other characters included are commented out.

          This was to made to fit into an old 08M,
          which was the original CW IDer for my 1W QRP rig.

-----------------------------------------------------------------------

    NOTES: Physical Connections

        pin C.1 LED output, or TR key out with transistor (2N3904) driver
        pin C.2 SIDE-TONE output is a simple piezo speaker

-----------------------------------------------------------------------
    Morse Code Alphanumeric Character Encoding
-----------------------------------------------------------------------

    Each character to be generated is programmed as a number whose
    binary equivalent then generates Morse code.

    Test the MSB (Most Significant Bit) to represent dits and dahs.

     dot = dit = 0
    dash = dah = 1

    One (1) bit on the end of the Morse Character to detect a stop
    shifting left until the byte equals 128 ($80)

    Example Letter Conversion:

      k = -.-         Morse pattern
      k = 101         Replace dash and dots with binary 1 and 0
      k = 1011        Add 1 bit to end
      k = 10110000    Pad with 0 bits to make a 8 bit BYTE
      k = %10110000   Defined data as binary value
      k = $B0         Defined data as HEX value
      k = 176         Defined data as Decimal value

-----------------------------------------------------------------------
    Visual Table of Morse Code HEX Values
-----------------------------------------------------------------------

  ASCII             Shift-Left Code
  Letter   Morse    Binary       HEX

    A      .-       0110 0000    $60
    B      -...     1000 1000    $88
    C      -.-.     1010 1000    $A8
    D      -..      1001 0000    $90
    E      .        0100 0000    $40
    F      ..-.     0010 1000    $28
    G      --.      1101 0000    $D0
    H      ....     0000 1000    $08
    I      ..       0010 0000    $20
    J      .---     0111 1000    $78
    K      -.-      1011 0000    $B0
    L      .-..     0100 1000    $48
    M      --       1110 0000    $E0
    N      -.       1010 0000    $A0
    O      ---      1111 0000    $F0
    P      .--.     0110 1000    $68
    Q      --.-     1101 1000    $D8
    R      .-.      0101 0000    $50
    S      ...      0001 0000    $10
    T      -        1100 0000    $C0
    U      ..-      0011 0000    $30
    V      ...-     0001 1000    $18
    W      .--      0111 0000    $70
    X      -..-     1001 1000    $98
    Y      -.--     1011 1000    $B8
    Z      --..     1100 1000    $C8

-----------------------------------------------------------------------

  ASCII             Shift-Left Code
  Number   Morse    Binary       HEX

    0      -----    1111 1100    $FC
    1      .----    0111 1100    $7C
    2      ..---    0011 1100    $3C
    3      ...--    0001 1100    $1C
    4      ....-    0000 1100    $0C
    5      .....    0000 0100    $04
    6      -....    1000 0100    $84
    7      --...    1100 0100    $C4
    8      ---..    1110 0100    $E4
    9      ----.    1111 0100    $F4

-----------------------------------------------------------------------
    Punctuation
-----------------------------------------------------------------------

    e.g. (SK) Digraph are sent together without a character space

    word space           [space key]    1000 0000    $80
    exclamation mark (KW)[!]  -.-.--    1010 1110    $AE
    quotation mark       ["]  .-..-.    0100 1010    $4A
    hashtag              [#]
    dollar sign      (SX)[$]  ...-..-   0001 0011    $13
    percent              [%]
    ampersand        (AS)[&]  .-...     0100 0100    $44
    apostrophe           [']  .----.    0111 1010    $7A
    parenthesis open (KN)[(]  -.--.     1011 0100    $B4
    parenthesis closed   [)]  -.--.-    1011 0110    $B6
    asterisk             [*]
    plus             (RN)[+]  .-.-.     0101 0100    $54
    comma                [,]  --..--    1100 1110    $CE
    hyphen minus         [-]  -....-    1000 0110    $86
    full stop (period)   [.]  .-.-.-    0101 0110    $56
    forward slash    (DN)[/]  -..-.     1001 0100    $94

    colon                [:]  ---...    1110 0010    $E2
    semicolon            [;]  -.-.-.    1010 1010    $AA
    less than            [<]
    equal sign       (BT)[=]  -...-     1000 1100    $8C
    greater than         [>]
    question mark        [?]  ..--..    0011 0010    $32

    at-sign (commat) (AC)[@]  .--.-.    0110 1010    $6A
    underscore           [_]  ..--.-    0011 0110    $36

-----------------------------------------------------------------------
    Procedural
-----------------------------------------------------------------------

    Start of work        (CT)  -.-.-    1010 1010    $AA
    End of work          (SK)  ...-.-   0001 0110    $16

    Invitation to transmit (K)  -.-     1011 0000    $B0

    Invitation for a particular
    station to transmit
                         (KN)  -.--.    1011 0100    $B4

    End of message       (AR)  .-.-.    0101 0100    $54
    Wait                 (AS)  .-...    0100 0100    $44

    Understood           (SN)  ...-.    0001 0100    $14
    Error (8 dits)       (HH)  ........ 1111 1111    $FF

-----------------------------------------------------------------------
    Traditional Timing
-----------------------------------------------------------------------

           1 dit = 1 dit
           1 dah = 3 dits
    letter space = 3 dits
    word spacing = 7 dits

-----------------------------------------------------------------------
    Farnsworth Timing
-----------------------------------------------------------------------

    letter space = 9 dits
    word spacing = 21 dits

-----------------------------------------------------------------------

#ENDREM
PICAXE_08M2_Simplified_Morse_Code_Generator_20230823.JPG
 

radiosparks

Active member
Code:
#REM
-----------------------------------------------------------------------

    PICAXE-08M2 Simplified Morse Code Generator - rhb.20230913

     NOTE: Only alpha and numerals are used in this demonstration.
          Other characters included are commented out.

          This was to made to fit into an old 08M,
          which was the original CW IDer for my 1W QRP rig.

-----------------------------------------------------------------------

    NOTES: Physical Connections

        pin C.1 LED output, or TR key out with transistor (2N3904) driver
        pin C.2 SIDE-TONE output is a simple piezo speaker
-----------------------------------------------------------------------
#ENDREM

#PICAXE 08M2

;#terminal 4800     ; Used only for Morse speed test ; remove to save bytes
;pause 3000         ; Used only for Morse speed test ; remove to save bytes

' ---------------------------------------------------------------------
'     Constants
' ---------------------------------------------------------------------

symbol        tone = 96                ; sets the tone frequency ( ~750 Hz )
symbol      silent = 0                 ; set silent tone (or QRSS tone 118/122)
symbol    dit_time = 9                 ; set length of a dot (mS) approx. ~12wpm
                                       ; tone timing and overhead of interpreted BASIC

symbol    dah_time = dit_time * 3      ; set length of a dash (3 dits)
symbol letter_time = dit_time * 3      ; set space between letters (3 dits)
symbol   word_time = dit_time * 7      ; set space between words (7 dits)
                                       ; NOTE:
                                       ; Because after each letter is a letter_time (3 dits),
                                       ; the actual word_time is (10 dits)

' ---------------------------------------------------------------------
'     Port Assignments
' ---------------------------------------------------------------------

symbol    LED_TR_OUT = c.1             ; LED output or TR key out
symbol SIDE_TONE_OUT = c.2             ; SIDE-TONE output is a simple piezo speaker

' ---------------------------------------------------------------------
'     Variables
' ---------------------------------------------------------------------

symbol    character = b0               ; BIT register for Morse Code character

symbol            i = b4               ; ASCII value from MESSAGE string
symbol            j = b5               ; pointer to ASCII character in MESSAGE string
symbol            k = b6               ; pointer Morse Code offset in defined string MORSE_A2Z

symbol            m = b7               ; use only for speed test ; remove or reuse variable
symbol            z = b8               ; use only for speed test ; remove or reuse variable

' ---------------------------------------------------------------------
'     MACRO Directives
' ---------------------------------------------------------------------

' STANDARD Message
#DEFINE MESSAGE_0 "CQ CQ CQ DX DE VE3XRM VE3XRM VE3XRM [ K"
' Note: The [ is an extended character to send End of message (AR)

' SPEED TEST - put in a loop and count how many in a minute
#DEFINE MESSAGE_2 "PARIS "

' PANGRAM Holoalphabetic Sentence
#DEFINE MESSAGE_Z "A QUICK BROWN FOX JUMPS OVER THE LAZY DOG 1234567890 "
#DEFINE MESSAGE_Y "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 "

#DEFINE MORSE_A2Z $80,$FC,$7C,$3C,$1C,$0C,$04,$84,$C4,$E4,$F4,$60,$88,$A8,$90,$40,$28,$D0,$08,$20,$78,$B0,$48,$E0,$A0,$F0,$68,$D8,$50,$10,$C0,$30,$18,$70,$98,$B8,$C8,$54

#MACRO SendMORSE( string )
    
    j = 0
    do
        lookup j, ( string, 0 ), i
        if i = 0 then exit
        call MORSE
    loop

#ENDMACRO

' ---------------------------------------------------------------------
'     Main Program Start
' ---------------------------------------------------------------------

MAIN:     

    ' e.g. Send Morse from a quoted string
    'SendMORSE("CQ CQ CQ DX DE VE3XRM VE3XRM VE3XRM AR K")
    
    #REM This is what is placed inline everytime you use SendMORSE()

        j = 0
        do
            lookup j, ( string, 0 ), i
            if i = 0 then exit
            call MORSE
        loop

    #ENDREM

    ' Send Morse from a pre-defined symbol
    'SendMORSE(MESSAGE_0)

    ' All letters and numbers
    'SendMORSE(MESSAGE_Y)

    ' Sample Morse Pangram
    SendMORSE(MESSAGE_Z)

    ' Used only to estimate PICAXE timing ; remove to save bytes
    ' call MORSE_SPEED_TEST

    ' IDer Timer - use with a short message as above e.g.
    'for i = 0 to 9     ; wait ten (10) minutes for next CW ID
    '    pause 60000    ; wait a minute, then repeat bacon message
    'next i

goto MAIN

'----------------------------------------------------------------------
'   Subroutines
'----------------------------------------------------------------------

MORSE_SPEED_TEST:  ' NOTE: remove subroutine to save bytes

    ' Morse Speed Test - Effect of increased clock speed

    ' The time function will increment
    ' at 4 MHz or 16 MHz once every second
    ' at 2 MHz and 8 MHz will be 2s
    ' at 32 MHz will be 0.5s

    ' e.g.
    ' 32 MHz     0.5s     
    ' 16 MHz     1s     
    ' 8  MHz     2s     
    ' 4  MHz     1s

    z = 0
    m = time + 60
    sertxd ("START: ", #time, CR, LF)
    do
        SendMORSE(MESSAGE_2)
        inc z
    loop until time > m
    sertxd ("END: ", #time, CR, LF)
    sertxd ("WPM: ", #z, CR, LF)

return

MORSE:

    if i = 32 then
        k = 0   
    elseif i < "A" then     ; maybe a number if less than 65
        k = i - 47          ; i - 48 + 1 calc offset to numbers
    else   
        k = i - 54          ; calc offset to letters
    end if

    lookup k, ( MORSE_A2Z ), character

    if character = $80 then
        gosub word_space
    else
        do until character = $80

            ' Testing a bit is equivalent to
            ' bit_value = character & %10000000 ; mask left most bit to test
            ' Then Test MSB of element
            ' if bit_value = $80 then
            ' character variable must be in one of the bit registers - here using b0

            if bit7 = 1 then
                gosub dah       ; if bit 1 do dah sub-routine
            else
                gosub dit       ; else it's 0 do dit sub-routine
            endif

            ' Left shift on all the bits in character.
            ' 08M & 08M2 doesn't have a shift function.

            'character = character * 2           ; multiply shift
            character = character + character    ; addition shift

        loop
        gosub char_space
    end if

    inc j    ; same as j = j + 1 ; inc counter to point at next character

return

dit:
    high LED_TR_OUT
    sound SIDE_TONE_OUT,(tone,dit_time)       ; sound tone for dit length
    low LED_TR_OUT
    sound SIDE_TONE_OUT,(silent,dit_time)     ; silence for dit length
return

dah:
    high LED_TR_OUT
    sound SIDE_TONE_OUT,(tone,dah_time)       ; sound tone for dah length
    low LED_TR_OUT
    sound SIDE_TONE_OUT,(silent,dit_time)     ; silence for dit length
return

char_space:
    sound SIDE_TONE_OUT,(silent,letter_time)  ; send silence for dah length after char completely sent
return

word_space:
    sound SIDE_TONE_OUT,(silent,word_time)     ; send silence for break between words
return

'----------------------------------------------------------------------
;EOF;
 
Last edited:

hippy

Ex-Staff (retired)
Excellent. When it comes to optimising ...
Code:
MORSE:

    if i = 32 then
        k = 0  
    elseif i < "A" then     ; maybe a number if less than 65
        k = i - 47          ; i - 48 + 1 calc offset to numbers
    else  
        k = i - 54          ; calc offset to letters
    end if

    lookup k, ( MORSE_A2Z ), character
Where 'i' is an ASCII character value, you can use DATA definitions and compact that down to a simple -
Code:
MORSE:
  Read i, character
The nice thing about that is it allows the correlation of ASCII to Morse to be more easily defined, such as -
Code:
Data "A" , ( %01100000 ) ;  .-
That can also make it easier to define non A-Z ones like -
Code:
Data "," , ( %11001110 ) ; --..--    comma
Data "-" , ( %10000110 ) ; -....-    hyphen minus
The DATA will sort out the charcater ordering automatically so you don't need to know ASCII values for characters. That is "," can come before or after "-" in the above and it it will still work out right.
 

radiosparks

Active member
While this was not the original intent, here is the updated code as per Hippy's suggestion.
The former code was design to fit an old 08M and was used in a QRP beacon transmitter.


The real project is CAT (Computer Aided Tuning) control of an Amateur Radio transceiver. I needed the EEPROM space for character data on an OLED display and to store some extra frequency tuning data of the VFOs. Commands would be echoed by Morse code. The previous code fit-the-bill and 08M2 neatly.

Code:
#REM
-------------------------------------------------------------

    PICAXE-08M2 Simplified Morse Code Generator MOD 3
    
    Code Optimized Version THREE - rhb.20240601
   
     NOTE: All Morse characters are stored in shared EEPROM memory
    as an indexed offset based on the ASCII value of a text letter.
   
    e.g. The letter A has an ASCII value of 65,
         so we READ memory location 65 for the Morse character.

    96 characters have been defined, not all are used for Morse

-------------------------------------------------------------

    NOTES: Physical Connections

        pin C.1 LED output - Cathode to ground - Anode resistor 330 ohm to pin
        pin C.2 SIDE-TONE output is a simple piezo speaker

-------------------------------------------------------------
    ASCII Visual DATA Table of Morse Code BIN/HEX Values
-------------------------------------------------------------

    e.g. (SK) Digraph are letters sent together without a character space

#ENDREM

'/*** PUNCTUATION

    DATA " " , ( %10000000 ) ;            $80 word space [space key]
    DATA "!" , ( %10101110 ) ;    -.-.--  $AE exclamation mark (KW)
    DATA $22 , ( %01001010 ) ;    .-..-.  $4A quotation mark - note: ya can't quote a quote
    DATA "#" , ( %11111111 ) ;            $FF hashtag
    DATA "$" , ( %00010011 ) ;    ...-..- $13 dollar sign (SX)
    DATA "%" , ( %11111111 ) ;            $FF percent
    DATA "&" , ( %01000100 ) ;    .-...   $44 ampersand (AS)
    DATA "'" , ( %01111010 ) ;    .----.  $7A apostrophe
    DATA "(" , ( %10110100 ) ;    -.--.   $B4 parenthesis open (KN)
    DATA ")" , ( %10110110 ) ;    -.--.-  $B6 parenthesis closed
    DATA "*" , ( %11111111 ) ;            $FF asterisk
    DATA "+" , ( %01010100 ) ;    .-.-.   $54 plus (RN)
    DATA "," , ( %11001110 ) ;    --..--  $CE comma
    DATA "-" , ( %10000110 ) ;    -....-  $86 hyphen minus
    DATA "." , ( %01010110 ) ;    .-.-.-  $56 full stop [period]
    DATA "/" , ( %10010100 ) ;    -..-.   $94 forward slash (DN)

'/*** NUMBERS

    DATA "0" , ( %11111100 ) ;    -----   $FC The HEX values are for checking stored values and my sanity.
    DATA "1" , ( %01111100 ) ;    .----   $7C
    DATA "2" , ( %00111100 ) ;    ..---   $3C
    DATA "3" , ( %00011100 ) ;    ...--   $1C
    DATA "4" , ( %00001100 ) ;    ....-   $0C
    DATA "5" , ( %00000100 ) ;    .....   $04
    DATA "6" , ( %10000100 ) ;    -....   $84
    DATA "7" , ( %11000100 ) ;    --...   $C4
    DATA "8" , ( %11100100 ) ;    ---..   $E4
    DATA "9" , ( %11110100 ) ;    ----.   $F4

'/*** PUNCTUATION

    DATA ":" , ( %11100010 ) ;    ---...  $E2 colon
    DATA ";" , ( %10101010 ) ;    -.-.-.  $AA semicolon
    DATA "<" , ( %11111111 ) ;            $FF less than
    DATA "=" , ( %10001100 ) ;    -...-   $8C equality sign (BT)
    DATA ">" , ( %11111111 ) ;            $FF greater than
    DATA "?" , ( %00110010 ) ;    ..--..  $32 question mark
    DATA "@" , ( %01101010 ) ;    .--.-.  $6A at-sign [commat] (AC)

'/*** LETTERS - UPPERCASE

    DATA "A" , ( %01100000 ) ;    .-      $60
    DATA "B" , ( %10001000 ) ;    -...    $88
    DATA "C" , ( %10101000 ) ;    -.-.    $A8
    DATA "D" , ( %10010000 ) ;    -..     $90
    DATA "E" , ( %01000000 ) ;    .       $40
    DATA "F" , ( %00101000 ) ;    ..-.    $28
    DATA "G" , ( %11010000 ) ;    --.     $D0
    DATA "H" , ( %00001000 ) ;    ....    $08
    DATA "I" , ( %00100000 ) ;    ..      $20
    DATA "J" , ( %01111000 ) ;    .---    $78
    DATA "K" , ( %10110000 ) ;    -.-     $B0
    DATA "L" , ( %01001000 ) ;    .-..    $48
    DATA "M" , ( %11100000 ) ;    --      $E0
    DATA "N" , ( %10100000 ) ;    -.      $A0
    DATA "O" , ( %11110000 ) ;    ---     $F0
    DATA "P" , ( %01101000 ) ;    .--.    $68
    DATA "Q" , ( %11011000 ) ;    --.-    $D8
    DATA "R" , ( %01010000 ) ;    .-.     $50
    DATA "S" , ( %00010000 ) ;    ...     $10
    DATA "T" , ( %11000000 ) ;    -       $C0
    DATA "U" , ( %00110000 ) ;    ..-     $30
    DATA "V" , ( %00011000 ) ;    ...-    $18
    DATA "W" , ( %01110000 ) ;    .--     $70
    DATA "X" , ( %10011000 ) ;    -..-    $98
    DATA "Y" , ( %10111000 ) ;    -.--    $B8
    DATA "Z" , ( %11001000 ) ;    --..    $C8

'/*** UNDEFINED - $FF characters

    DATA "[" , ( %11111111 ) ;            $FF left square bracket
    DATA $5C , ( %11111111 ) ;            $FF backslash [\] - note: reserved escape character
    DATA "]" , ( %01010100 ) ;  .-.-.     $54 right square bracket - End of message (AR)
    DATA "^" , ( %11111111 ) ;            $FF circumflex / caret
    DATA "_" , ( %00110110 ) ;  ..--.-    $36 underscore
    DATA "`" , ( %11111111 ) ;            $FF grave / accent

'/*** LETTERS - LOWERCASE - [OPTIONAL] REM if memory space needed

    DATA "a" , ( %01100000 ) ;    .-      $60
    DATA "b" , ( %10001000 ) ;    -...    $88
    DATA "c" , ( %10101000 ) ;    -.-.    $A8
    DATA "d" , ( %10010000 ) ;    -..     $90
    DATA "e" , ( %01000000 ) ;    .       $40
    DATA "f" , ( %00101000 ) ;    ..-.    $28
    DATA "g" , ( %11010000 ) ;    --.     $D0
    DATA "h" , ( %00001000 ) ;    ....    $08
    DATA "i" , ( %00100000 ) ;    ..      $20
    DATA "j" , ( %01111000 ) ;    .---    $78
    DATA "k" , ( %10110000 ) ;    -.-     $B0
    DATA "l" , ( %01001000 ) ;    .-..    $48
    DATA "m" , ( %11100000 ) ;    --      $E0
    DATA "n" , ( %10100000 ) ;    -.      $A0
    DATA "o" , ( %11110000 ) ;    ---     $F0
    DATA "p" , ( %01101000 ) ;    .--.    $68
    DATA "q" , ( %11011000 ) ;    --.-    $D8
    DATA "r" , ( %01010000 ) ;    .-.     $50
    DATA "s" , ( %00010000 ) ;    ...     $10
    DATA "t" , ( %11000000 ) ;    -       $C0
    DATA "u" , ( %00110000 ) ;    ..-     $30
    DATA "v" , ( %00011000 ) ;    ...-    $18
    DATA "w" , ( %01110000 ) ;    .--     $70
    DATA "x" , ( %10011000 ) ;    -..-    $98
    DATA "y" , ( %10111000 ) ;    -.--    $B8
    DATA "z" , ( %11001000 ) ;    --..    $C8

'/*** UNDEFINED - $FF Characters

    DATA "{" , ( %11111111 ) ;            $FF left curly bracket
    DATA "|" , ( %11111111 ) ;            $FF vertical bar
    DATA "}" , ( %11111111 ) ;            $FF right curly bracket
    DATA "~" , ( %11111111 ) ;            $FF tilde
    DATA $7F , ( %11111111 ) ;            $FF delete

#PICAXE 08M2

' ---------------
'     Constants
' ---------------

symbol        tone = 96              ; sets the tone frequency ( ~750 Hz )
symbol      silent = 0               ; set silent tone (or QRSS tone 118/122)
symbol    dit_time = 9               ; set length of a dot (mS) approx. ~12wpm
                                     ; tone timing and overhead of interpreted BASIC
                                   
symbol    dah_time = dit_time * 3    ; set length of a dash (3 dits)
symbol letter_time = dit_time * 3    ; set space between letters (3 dits)
symbol   word_time = dit_time * 7    ; set space between words (7 dits)
                                   
'/*** Port Assignments ***/

symbol    LED_TR_OUT = c.1             ; LED output or TR key out
symbol SIDE_TONE_OUT = c.2             ; SIDE-TONE output is a simple piezo speaker

'/*** Variables ***/

symbol   character  = b0            ; BIT register for Morse Code character
symbol     ASCIIvalue  = b4         ; ASCII value from MESSAGE string
symbol  CHARpointer = b5            ; pointer to ASCII character in MESSAGE string

'/*** MACRO Directives ***/

' STANDARD Message - can also be defined directly in the MACRO command
#DEFINE MESSAGE_0 "CQ CQ CQ DX DE VE3XRM VE3XRM VE3XRM ] K "
' Note: The ] is an extended character to send End of message (AR)

' PANGRAM Holoalphabetic Sentence
#DEFINE MESSAGE_Z "A QUICK BROWN FOX JUMPS OVER THE LAZY DOG 1234567890 "
#DEFINE MESSAGE_Y "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 ] "

#MACRO SendMORSE( string )
   
    CHARpointer = 0
    do
        lookup CHARpointer, ( string, 0 ), ASCIIvalue
        if ASCIIvalue = 0 then exit
        call MORSE
    loop

#ENDMACRO

'/*** Main Program Start ***/

MAIN:     

    '/*** Different ways to sent the string data ***/

    ' e.g. Send Morse from a quoted string
    SendMORSE("CQ CQ CQ DX DE VE3XRM VE3XRM VE3XRM ] K ") ; uses 166 BYTES
   
    ' e.g. Send Morse from a pre-defined symbol
    'SendMORSE(MESSAGE_0)            ; uses 166 BYTES
       
    ' Sample all letters and numbers
    'SendMORSE(MESSAGE_Y)            ; uses 166 BYTES
   
    ' Sample Morse Pangram
    'SendMORSE(MESSAGE_Z)            ; uses 185 BYTES
   
goto MAIN

'/*** Subroutines ***/

MORSE:

    READ ASCIIvalue, character
       
    if character = $80 then
        gosub word_space
    else
        do until character = $80
            if bit7 = 1 then
                gosub dah
            else
                gosub dit
            endif
            character = character + character
        loop
        gosub char_space
    end if
    inc CHARpointer   
return

dit:
    high LED_TR_OUT
    sound SIDE_TONE_OUT,(tone,dit_time)
    low LED_TR_OUT
    sound SIDE_TONE_OUT,(silent,dit_time)
return

dah:
    high LED_TR_OUT
    sound SIDE_TONE_OUT,(tone,dah_time)
    low LED_TR_OUT
    sound SIDE_TONE_OUT,(silent,dit_time)
return

char_space:
    sound SIDE_TONE_OUT,(silent,letter_time)
return

word_space:
    sound SIDE_TONE_OUT,(silent,word_time)
return

'EOF
 
Last edited:
Top