Ah OK…..
Maybe stay where I am then :-)
Arrays are a hole new minefield for me….. Although I am OK with my Antenna Array on the roof. (Radio Ham)
Whole lot of learning for me yet!
BR and TY
Andy
Ah OK…..
Maybe stay where I am then :-)
Arrays are a hole new minefield for me….. Although I am OK with my Antenna Array on the roof. (Radio Ham)
Whole lot of learning for me yet!
BR and TY
Andy
Have a go with gosubs as a start, we can progress to arrays later. I could write examples for you but I believe you will learn more doing it yourself. As always if you need help just ask.
Steve Earl www.datageo.co.uk
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
'************************************************* ***************
'* Name : Morse_beta.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2014 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 17/08/2014 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
TRISA=0 'All A Port outs
TRISB=0 'All B Port outs
CMCON=7
LED VAR PORTB.0 'LED Indicator
Mess: pause 2000
High led
pause 5000 'Led on for 5 seconds
low led
pause 2000 'off for 2 seconds
begin:
m: gosub dash : gosub dash : gosub lgap
o: gosub dash : gosub dash : gosub dash : gosub lgap
s: gosub dot : gosub dot : gosub dot : gosub lgap
t: gosub dash : gosub lgap
l: gosub dot : gosub dash : gosub dot : gosub dot : gosub lgap
y: gosub dash : gosub dot : gosub dash : gosub dash : gosub lgap
spc: gosub space
h: gosub dot : gosub dot : gosub dot : gosub dot : gosub lgap
a: gosub dot : gosub dash : gosub lgap
r: gosub dot : gosub dash : gosub dot : gosub lgap
mm: gosub dash : gosub dash : gosub lgap
ll: gosub dot : gosub dash : gosub dot : gosub dot : gosub lgap
e: gosub dot : : gosub lgap
ss: gosub dot : gosub dot : gosub dot : gosub lgap
sss: gosub dot : gosub dot : gosub dot : gosub lgap
pause 3500 '3.5 sec delay
goto mess
dash: high led 'dash
pause 1500
low led
pause 500
return
dot: high led 'dot
pause 500
low led
pause 500
return
lgap: pause 1000 'letter gap
return
spaceause 1000 'space
return
end
Just thinking, use ASCII value of letter, load morse at that array element using special notation (letters have 1 to 3 codes).
Only need 6 bits of 1 byte to store morse code of a letter:
Bit 7, 1st code:
0 not used
1 used
Bit 6, 1st code value:
0 dot
1 dash
Bit 5, 2nd code:
...and so on...
That way you can store morse code for entire alphabet using 1 byte each into an array.
Then loop through a text string, gosub a routine that converts letter to ascii, looks up the array element and generates morse code.
Only need a text string, main loop and morse subroutine.
Robert
![]()
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.
The first 32 characters are often ignored as they are not keyboard characters, with a few exceptions obviously.
Now we have encoded the character we need a decode routine.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
Melanie used a beeper in the above code it needs changing to use LED and PAUSECode: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
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.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
Andy you get all the fun!![]()
Steve Earl www.datageo.co.uk
Weird, I was sure morse was up to 3 characters, turns out it's up to 5 characters.
I've tried all sorts of ways to try to store morse in as little space. Turns out the start bit technique is the best one yet.
There's non-English code ś and special character $ here that can be up to 7 characters; so you could still fit that in 8 bits.
http://en.wikipedia.org/wiki/Morse_code
The only character I haven't figured how to store is prosign ERROR; 8 dots. I suppose that could be hard-coded?
Robert
Hi All…
Thank you for all your words of wisdom.
Away at moment but will read and make sense of the advice when I am back
Thank you for replies
Andy
Bookmarks