Home

Pete's Morse Code Project

Project Description

PROGRAM SendMorse.bas
P. H. Morton, W3GVX
September 3, 2007

V2, Version 2, of this program has added additional morse characters including punctuation, and other symbols. The morse data table has been expanded to include a contiguous section of the ASCII character set. This permitted a simpler program with fewer lines of code, thus freeing up program memory.

  • This program is for a PICAXE 08M microcontroller
  • The PICAXE will flash an LED and output a keyed audio tone in Morse code The morse code message sent is defined in the last data statement below.
  • When you change the message in the data statement, be sure to change the "msglen" variable value just below it.
  • This program, as written, uses 256 of 256 bytes of available EEPROM memory, so keep this in mind when changing the message. A maximum of 59 characters, including spaces, may be used in the message.
  • The program is written for a configuration of an LED on Port 1 and a speaker on Port 2. The LED port may be changed if desired using the "out" variable defined below.
  • I used a small (less than 2 in. diameter) 8 ohm speaker from Radio Shack connected in series with a 68uF cap and a 100 ohm resistor to Port 2 (not lead 2) of the PICAXE
  • http://www.phanderson.com/picaxe/, distributor of the PICAXE development board, lists a 2 in. 100 ohm speaker that they say may be connected with a supplied 47 uF capacitor directly to the port without a resistor. The price is $0.95. I ordered some parts Monday night and they arrived in Wednesday's mail.

Project Hardware Setup

I downloaded Pete's code to my "Half-board". As you can see from Pete's description the key thing is the outputs: the LED on port 1 and the speaker on port 2. I didn't have a speaker handy so I used a TX433 on port 2 and my HT as the speaker. You may notice that the picture of my setup is similar to the PICetSat Lite setup. All I did was pull the unused components from the breadboard and moved the LED from port 0 to port 1. I was able to run Pete's code without a single software change.

Petes_Proj.jpg

Here is another working hardware setup. Here I am using a 1/8" stereo phone jack. I just soldered wire leads to the 3 appropriate pins on the bottom of the jack. It fits into the breadboard quite nicely. I've also added a 10k resistor. It works without the resistor, but hold on to your eardrums!

petejack.jpg

Project Software

'  PROGRAM SendMorseV2.bas
  
'  P. H. Morton, W3GVX
'  September 3, 2007

'      V2, Version 2, of this program has added additional morse characters including punctuation,
'      and other symbols.  The morse data table has been expanded to include a contiguous
'      section of the ASCII character set.  This permitted a simpler program with fewer 
'      lines of code, thus freeing up program memory.

'  This program is for a PICAXE 08M microcontroller

'  The PICAXE will flash an LED and output a keyed audio tone in Morse code
'  The morse code message sent is defined in the last data statement below.

'  When you change the message in the data statement, be sure to change 
'  the "msglen" variable value just below it.

'  This program, as written, uses 256 of 256 bytes of available EEPROM memory, so keep this
'  in mind when changing the message.  A maximum of 59 characters, including spaces, 
'  may be used in the message.

'  The program is written for a configuration of an LED on Port 1 and a speaker on Port 2.  
'  The LED port may be changed if desired using the "out" variable defined below.

'  I used a small (less than 2 in. diameter) 8 ohm speaker from Radio Shack connected
'  in series with a 68uF cap and a 100 ohm resistor to Port 2 (not lead 2) of the PICAXE

'  http://www.phanderson.com/picaxe/, distributor of the PICAXE development board, lists a 2 inch
'  100 ohm speaker that they say may be connected with a supplied 47 uF capacitor directly to 
'  the port without a resistor.  The price is $0.95.  I ordered some parts Monday night and 
'  they arrived in Wednesday's mail.

'  The following data is morse data for ascii characters 32 (space) through 95 (underscore)

'  To see an ASCII table, see:  www.asciitable.com

'  For more info on Morse Code, see the ARRL Operating Manual, and look up "Morse Code" on www.Wikipedia.com 

'  There is no morse code assigned by the ITU-R to some ASCII characters.  Invalid characters 
'  are:  # % < > [ \ ] ^ ` { | } ~  
'  Basic does not allow the " (quote) character or the \ (backslash) in the message field
'  7 dits will be keyed for any invalid character used

'  I assigned [SK] to the * for which there is no official morse code.

'  Lower case letters may be used in the message field.

'  The first 1 in each byte reading from left to right is a flag to mark the beginning 
'  of the dit and dah data that follow.  0 for dit, 1 for dah

'  This data is stored in the PICAXE EEPROM when the program is loaded


data   0,(%00000001)		' ascii 32, space, program interprets a byte value less than 2 as a space (pause)
data     (%01101011)		' ascii 33, ! (exclamation point) [KW], unofficial code, some amateurs prefer [MN]
data     (%01010010)		' ascii 34, " (quote) [AF], the message is enclosed in quotes, don't use
data     (%10000000)		' ascii 35, # no morse code assigned, program returns 7 dits
data     (%10001001)		' ascii 36, $ [SX]
data     (%10000000)		' ascii 37, % no morse code assigned, program returns 7 dits
data     (%00101000)		' ascii 38, & [AS]
data     (%01011110)		' ascii 39, ' (apostrophe) [WG]
data     (%00110110)		' ascii 40, ( [KN]
data     (%01101101)		' ascii 41, ) [KK]
data     (%01000101)		' ascii 42, * no official morse, I assigned [SK]  
data     (%00101010)		' ascii 43, + [AR]
data     (%01110011)		' ascii 44, , (comma)
data     (%01100001)		' ascii 45, - (hyphen) [DU]
data     (%01010101)		' ascii 46, . (period)
data     (%00110010)		' ascii 47, / (forward slash) [DN]
data     (%00111111,%00101111,%00100111,%00100011,%00100001)	' ascii 48 to 52,  0,1,2,3,4
data     (%00100000,%00110000,%00111000,%00111100,%00111110)	' ascii 53 to 57,  5,6,7,8,9
data     (%01111000)		' ascii 58, : colon [OS]
data     (%01101010)		' ascii 59, ; semicolon [KR]
data     (%10000000)		' ascii 60, < no morse code assigned, program returns 7 dits
data     (%00110001)		' ascii 61  = [BT]
data     (%10000000)		' ascii 62  > no morse code assigned, program returns 7 dits
data     (%01001100)		' ascii 63, ?
data     (%01011010)		' ascii 64, @ [AC] (code assigned in 2004 by the ITU-R)
data     (%00000101,%00011000,%00011010,%00001100,%00000010)	' ascii 65 to 69,  A,B,C,D,E
data     (%00010010,%00001110,%00010000,%00000100,%00010111)	' ascii 70 to 74,  F,G,H,I,J
data     (%00001101,%00010100,%00000111,%00000110,%00001111)	' ascii 75 to 79,  K,L,M,N,O
data     (%00010110,%00011101,%00001010,%00001000,%00000011)	' ascii 80 to 84,  P,Q,R,S,T
data     (%00001001,%00010001,%00001011,%00011001,%00011011)	' ascii 85 to 89,  U,V,W,X,Y
data     (%00011100)								' ascii 90,        Z
data     (%10000000)		' ascii 91, [ no morse code assigned, program returns 7 dits
data     (%10000000)		' ascii 92, \ no morse code assigned, Program error if used in message string
data     (%10000000)		' ascii 93, ] no morse code assigned, program returns 7 dits
data     (%10000000)		' ascii 94, ^ (carat) no morse code assigned, program returns 7 dits
data     (%01001101)		' ascii 95, _ (underscore) [IQ]
symbol msgptr = 64		' pointer to address of first message character in memory
					' msgptr = number of data bytes assigned above 


'  ----------------------------------------------------------------------------------------------------------

'  Change the next two lines to insert your message

data     ("73 de W3GVX rst 599 = name Pete = QTH is Finksburg, MD =  +")  ' message to send in Morse. Use
										' valid characters listed in the data 
										' statements above.  
										' Lower case letters may also be used.
										' " (quotes)  and \ (backslash) may not
										' be used in the message string.  The message 
										' string must be enclosed with quotes. 
										' A maximum of 59 characters may be used.

symbol msglen = 59				' number of characters in message to send 
							' including spaces (59 maximum)


'  ----------------------------------------------------------------------------------------------------------


symbol t1 = 100						' time duration in MS of dit/dah spacing 
								' [use for dit LED flash if simultaneous sound not used]

symbol t2 = 200						' additional time between characters, total = t1 + t2

'symbol t3 = 300						' time duration in MS of a dah 
								' [use for LED flash if simultaneous sound not used]

symbol t4 = 300						' time duration between words:  total = t1 + t2 + t4

symbol t10 = 10						' time duration (X 10 MS) of a dit (sound)

symbol t30 = 30						' time duration (X 10 MS) of a dah (sound)

symbol tone = 115						' pitch of morse sound, 0 to 127, use 128 to 255 for noise

symbol out = 1						' output port # for LED

symbol charcount = b11					' character counter variable
symbol charptr = b10					' pointer variable for address of message character
symbol bitptr = b9					' bit pointer to bits in morse byte (b0)
symbol ascii = b8						' variable containing current ascii character to send
symbol morseptr = b7					' pointer variable for address of morse data look-up


main:

  wait 5						' wait 5 seconds 
  for charcount = 1 to msglen			' get character
    charptr = msgptr + charcount - 1 	' determine address of character in data memory
    read charptr, ascii 			' put character into ascii variable

    if ascii >= 97 and ascii <= 122 then
      ascii = ascii - 32			' change lower case to upper case
    endif

    b0 = %10000000				' initialize morse to 7 dits in case ascii character is not defined

    if ascii >= 32 and ascii <= 95 then	' check to see if the character is in the look-up table
      morseptr = ascii - 32			' define address for code in the look-up table
      read morseptr,b0				' get morse from look-up table in EEPROM 
    endif

    b1 = 128
    bitptr = 7
    b3 = b1 and b0

    do while b3 = 0 and bitptr <> 0		' find first 1 in morse byte (b0)
      b1 = b1 / 2
      bitptr = bitptr - 1
      b3 = b1 and b0
    loop
    
    if bitptr = 0 then				' test for a space character
      pause t4					' pause for time period between words (an ascii space)
    else
      do
        b1 = b1 /2
        bitptr = bitptr - 1			' test each successive bit for 0 or 1 (dit or dash)
        b3 = b1 and b0				' determine if morse bit is dit (b3=0) or dah (b3 not 0)
        if b3 = 0 then				' test bit for 0 (dit)
          high out				' turn on LED
          sound 2,(tone,t10)			' dit
          low out					' turn off LED
          pause t1				' pause after each dit
        else
          high out				' turn on LED
          sound 2,(tone,t30)			' dah
          low out					' turn off LED
          pause t1				' pause after each dah
        endif
      loop until bitptr = 0			' get next bit
    endif
    
    pause t2					' pause at end of character
    
  next charcount					' get next character

  goto main
  
  end