Quote Originally Posted by andybarrett1 View Post
Hi Steve.

My attempt at using gosubs... First thing I notice is the memory saving. I Know I could improve things by putting all the letters in a table and calling them up....Ideally I would like to be able to use a 24C32 or similar but how do I get the table in there ??

That way I could have lots more messages !!!

Anyway... Any suggestions on how to improve on my basics here.

Thank you

Andy
Hi Andy,

To use the code tags go advanced and use the # icon.

A way forward is to use a bit pattern within a byte simply by indicating . as 0 and - as 1.

this would make S 000 or the whole byte %00000000 which will not work but if we add a start bit 1 we get %00001000 or $08 in hex.

and O would be 111 and with the start bit 1111 we get $00001111 or $0F

and so on for all of the ASCII characters.

One way to encode each character in a message is to use a lookup table using the ASCII decimal value.

Name:  Capture.PNG
Views: 1562
Size:  87.6 KB

The first 32 characters are often ignored as they are not keyboard characters, with a few exceptions obviously.
Code:
TranslateASCIIMorse:
    MorseCode=0
        '
        ' Translate Numerics (0-9)
        ' ------------------------
    If ASCIIData>47 then
        If ASCIIData<58 then
            Lookup (ASCIIData-53),[$20,$30,$38,$3C,$3E],MorseCode            ' 5 6 7 8 9
            endif
        If ASCIIData<53 then
            Lookup (ASCIIData-48),[$3F,$2F,$27,$23,$21],MorseCode            ' 0 1 2 3 4
            endif
        endif
        '
        ' Translate Alphabetics (A-Z)
        ' ---------------------------
    If ASCIIData>96 then
        If ASCIIData<123 then ASCIIData=ASCIIData-32
        endif
    If ASCIIDATA>64 then
        If ASCIIData<91 then
              Lookup (ASCIIData-82),[$0A,$08,$03,$09,$11,$0B,$19,$1B,$1C],MorseCode              ' R S T U V W X Y Z
              endif
        If ASCIIData<82 then
              Lookup (ASCIIData-73),[$04,$17,$0D,$14,$07,$06,$0F,$16,$1D],MorseCode              ' I J K L M N O P Q
              endif
        If ASCIIData<73 then
              Lookup (ASCIIData-65),[$05,$18,$1A,$0C,$02,$12,$0E,$10],MorseCode              ' A B C D E F G H
              endif
        endif
        '
        ' Translate special characters
        ' ----------------------------
    If ASCIIData=39 then MorseCode=$5E            ' ' Apostrophe
    If ASCIIData=40 then MorseCode=$6D            ' ( Brackets
    If ASCIIData=41 then MorseCode=$6D            ' ) Brackets
    If ASCIIData=58 then MorseCode=$78            ' : Colon
    If ASCIIData=44 then MorseCode=$73            ' , Comma
    If ASCIIData=45 then MorseCode=$61            ' - Hyphen
    If ASCIIData=47 then MorseCode=$32            ' / Oblique Stroke
    If ASCIIData=46 then MorseCode=$55            ' . Period
    If ASCIIData=63 then MorseCode=$4C            ' ? Question
    If ASCIIData=34 then MorseCode=$52            ' " Quotation Moarks
        '
        ' Translate Space
        ' ---------------
    If ASCIIData=32 then MorseCode=$FF
    Return
Now we have encoded the character we need a decode routine.
Code:
SendMorseCode:
    If MorseCode=$FF then                          ' Execute Word Pause
        MorseEnable=MorseDot*80
        Pause MorseEnable
        Return
        endif
    MorseEnable=0        ' Reset Enable
    For MorseBitPointer=0 to 7                   ' Loop Up to 8 Times
        If MorseEnable=0 then                     ' Check for Character Start Flag
            If MorseCode.7=1 then MorseEnable=1            ' Set Morse Character Start Flag
            else            ' If Morse sub-element Enabled, Send sub-element
            ToneTime=(50000/DefaultBeepPitch/10)*MorseDot            ' Determine Morse Dot Time
            If MorseCode.7=1 then
                ToneTime=ToneTime*3                                                ' Determine Morse Dash Time
                endif
            Gosub BeepOut
            ToneTime=MorseDot*10
            Pause ToneTime
            endif
        MorseCode=MorseCode<<1        ' Shift to next Morse sub-element
        Next MorseBitPointer
    MorseEnable=MorseDot*30        ' Determine & Execute End of Character Pause
    Pause MorseEnable
    Return
Melanie used a beeper in the above code it needs changing to use LED and PAUSE
Code:
MorseDot con 500
MorseDash con 1500
MorseSpace con 4000

SendMorseCode:
    If MorseCode=$FF then                                          ' Execute Word Pause                        
        Pause MorseSpace
        Return
    endif
    MorseEnable=0                                                      ' Reset Enable
    For MorseBitPointer=0 to 7                                      ' Loop Up to 8 Times
        If MorseEnable=0 then                                        ' Check for Character Start Bit
            If MorseCode.7=1 then MorseEnable=1            ' Set Morse Character Start Flag
            else  
                High LED                                                             ' If Morse sub-element Enabled, Send sub-element
                If MorseCode.7=0 then  Pause MorseDot                ' Dot
                If MorseCode.7=1 then  Pause MorseDash              ' Dash
                Low LED
                If MorseBitPointer !=7 then Pause MorseDot
            endif
        MorseCode=MorseCode<<1        ' Shift to next Morse sub-element
        Next MorseBitPointer
       Pause MorseDash                        'End of character pause same pause as dash but LED is low
    Return
These snippets need stitching together along with other parts of Melanie's code which can be found following the link in post #15. I will leave that to you to do but as usual if you have any questions just ask. BTW I have not tested the above and have only simulated the code in my mind, again I leave that to you to do.

Andy you get all the fun!