Home

Pete's Morse Keyer Project

Project Description

PROGRAM MorseKeyer.bas
P. H. Morton, W3GVX
September 28, 2007

' This program is for a PICAXE 08M microcontroller on a modified prototype ' board distributed by P. H. Anderson (http://www.phanderson.com).

' The PICAXE will key your transceiver in morse as you type on your PC keyboard ' using HyperTermial or other terminal emulation program. The PC connects to ' the PICAXE evaluation board via the PC serial (RS-232) port.

Project Schematic

PICAXE08Mschematic.jpg

Project Hardware Setup

The PICAXE 08M prototype board was modified as follows:

The RS-232 connector on the prototype board normally used for downloading the PICAXE program was also used for communication with HyperTerminal. Two 3-pin headers with jumpers were added to allow switching between the programming in/out ports of the PICAXE (ports SIN and Port 0) and the ports used for serial communication with HyperTerminal (Port 3 input, Port 4 output). Components for proper level shifting, clamping and port protection must be added between the RS-232 connector and the PICAXE ports (see schematic). Note that an input clamping diode to +5V is needed for Port 3 (see page 140 of the PICAXE Manual 2 found in PICAXE Programming Editor Help).

A second serial port connector may be used in lieu of the jumper blocks if desired.

Hardware flow control was implemented by adding a jumper between pins 4 and 6 (DTR and DSR respectively) of the serial connector, and adding a 220 ohm resistor between Port 2 of the PICAXE and pin 8 (CTS) of the serial connector.

The keyer output is at Port 1. Interface with modern transceivers may be implemented using a simple transisitor circuit with open-collector output to the transceiver, or a reed relay may used for high-voltage or negative- voltage key interfaces. An LED and/or small Piezo buzzer may also be used (see schematic). A suitable reed relay is available from P. H. Anderson for $1.25 (http://www.phanderson.com/picaxe/omr_106H.html).

Project PC Software

HyperTerminal setup:

  • HyperTerminal is an accessory provided with Windows 95, 98, XP, and probably others, but not Vista. HyperTerminal may be downloaded free for personal use from: http://www.hilgraeve.com/htpe/
  • When opening HyperTerminal on your PC, close the "Connection Discription" window that opens at startup..
  • Verify the little telephone icon with the handset on the cradle is the brighter of the two telephone icons, indicating that HyperTerminal is disconnected.
  • Click on the properties icon, the one farthest to the right in the toolbar to open the "Connection Properties" window.
  • In the "Connect using" box, select the proper COM port.
  • After the COM port is defined, click on the "Configure" button and select 300 bits per second (2400 is too fast and does not work properly)
    • 8 data bits
    • None parity,
    • 1 stop bit
    • Hardware flow control.
    • Click "OK"

CQ message;

  • You may send a "CQ" message by typing [CTRL] C in Hyperterminal. See the program listing below for more info.
  • Note: Messages may also be stored in Notepad text files and sent to the PICAXE using HyperTerminal.

Return key

  • You may press the Return key at any time to move the cursor down to the beginning of the next line on the display. No morse is generated and Carriage Return and Line Feed control characters are echoed back to HyperTerminal by the PICAXE.

Project Software

'  PROGRAM MorseKeyer.bas
  
'  P. H. Morton, W3GVX
'  September 28, 2007

'  This program is for a PICAXE 08M microcontroller on a modified prototype
'  board distributed by P. H. Anderson (http://www.phanderson.com).

'  The PICAXE will key your transceiver in morse as you type on your PC keyboard 
'  using HyperTermial or other terminal emulation program.  The PC connects to 
'  the PICAXE evaluation board via the PC serial (RS-232) port.

'  The PICAXE 08M prototype board was modified as follows:

'    The RS-232 connector on the prototype board normally used for downloading 
'    the PICAXE program was also used for communication with HyperTerminal.  Two 
'    3-pin headers with jumpers were added to allow switching between the programming 
'    in/out ports of the PICAXE (ports SIN and Port 0) and the ports used for serial 
'    communication with HyperTerminal (Port 3 input, Port 4 output).  Components 
'    for proper level shifting, clamping and port protection must be added between 
'    the RS-232 connector and the PICAXE ports (see schematic). Note that an input 
'    clamping diode to +5V is needed for Port 3 (see page 140 of the PICAXE Manual 2 
'    found in PICAXE Programming Editor Help). 

'    A second serial port connector may be used in lieu of the jumper blocks if desired.

'    Hardware flow control was implemented by adding a jumper between 
'    pins 4 and 6 (DTR and DSR respectively) of the serial connector, and 
'    adding a 220 ohm resistor between Port 2 of the PICAXE and pin 8 (CTS) of the 
'    serial connector.

'    The keyer output is at Port 1.  Interface with modern transceivers may be 
'    implemented using a simple transisitor circuit with open-collector output
'    to the transceiver, or a reed relay may used for high-voltage or negative-
'    voltage key interfaces. An LED and/or small Piezo buzzer may also be used 
'    (see schematic). A suitable reed relay is available from P. H. Anderson 
'    for $1.25 (http://www.phanderson.com/picaxe/omr_106H.html).

'  HyperTerminal setup:

'    HyperTerminal is an accessory provided with Windows 95, 98, XP, and probably 
'    others, but not Vista. HyperTerminal may be downloaded free for personal use 
'    from:  http://www.hilgraeve.com/htpe/ 

'    When opening HyperTerminal on your PC, close the "Connection Discription"
'    window that opens at startup..  

'    Verify the little telephone icon with the handset on the cradle is the 
'    brighter of the two telephone icons, indicating that HyperTerminal is 
'    disconnected.

'    Click on the properties icon, the one farthest to the right in the toolbar
'    to open the "Connection Properties" window.

'    In the "Connect using" box, select the proper COM port.

'    After the COM port is defined, click on the "Configure" button and
'    select 300 bits per second (2400 is too fast and does not work properly)
'    8 data bits
'    None parity,
'    1 stop bit
'    Hardware flow control.
'    Click "OK"

'  CQ message;  

'    You may send a "CQ" message by typing [CTRL] C in Hyperterminal.  See the 
'    program listing below for more info.

'    Note:  Messages may also be stored in Notepad text files and sent to the 
'    PICAXE using HyperTerminal.

'  Return key

'    You may press the Return key at any time to move the cursor down to the beginning
'    of the next line on the display.  No morse is generated and Carriage Return
'    and Line Feed control characters are echoed back to HyperTerminal by the PICAXE.

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

'  The following comments are relative to this program.

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

'  This program, as written, uses 254 of 256 bytes of available EEPROM memory, so keep 
'  this in mind when changing the "CQ" message below. The two free bytes may be used 
'  for a 6 character call sign in lieu of my 5 character call sign. A maximum of 28 
'  characters, including spaces, may be used in the "CQ" message.

'  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" 
'  at: http://www.Wikipedia.com 

'  There is no morse code assigned by the ITU-R to some ASCII characters.  Invalid characters 
'  are:  # % < > [ \ ] ^ ` { | } ~  [backspace] [delete] and other keyboard functions

'  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]
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 returns 7 dits
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 change the "CQ" message

data     ("cq cq cq de W3GVX W3GVX  k" )		' "CQ" 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 28 characters may be used.

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


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


symbol t1 = 100						' time duration in MS of dit/dah spacing 

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

symbol t3 = 300						' time duration in MS of a dah 

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

symbol out = 1						' output port # for LED
symbol cts = 2						' clear to send port
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:

  high cts						' enable data from PC, ClearToSend high

  serin 3,n300,ascii				' read character from PC

  low cts						' stop data from PC, CTS low

  if ascii = 13 then				' check for Carriage Return
    serout 4,n300,(ascii)
    serout 4,n300,(10)
    goto main
  endif
  
  if ascii = 3 then				' check for [CTRL] C, 
    for charcount = 1 to msglen		' send "CQ" message
      charptr = msgptr + charcount - 1 	' determine address of character in data memory
      read charptr, ascii 			' put character into ascii variable
      gosub sendmorse				' generate morse code
    next charcount				' get next character in the "CQ" message
  else
    gosub sendmorse				' generate morse for character read from PC
  endif

  goto main						' get next character from PC
    
sendmorse:

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

    if ascii >= 97 and ascii <= 122 then
      ascii = ascii - 32			' change lower case to upper case
    endif
    serout 4,n300,(ascii)			' echo character back to PC
    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
    endif

    b1 = 128
    bitptr = 7
    b3 = b1 and b0

    do while b3 = 0 and bitptr <> 0		' find location of 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						' if not a space, send morse
      do
        b1 = b1 /2
        bitptr = bitptr - 1			' test each successive bit for 0 or 1 (dit or dah)
        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 (key down)
          pause t1				' dit
          low out					' turn off LED (key up)
          pause t1				' pause after each dit
        else
          high out				' turn on LED (key down)
          pause t3				' dah
          low out					' turn off LED (key up)
          pause t1				' pause after each dah
        endif
      loop until bitptr = 0			' get next dit or dah
      pause t2					' pause at end of character
    endif
    
    return    

  end