Shop OBEX P1 Docs P2 Docs Learn Events
CW Flasher — Parallax Forums

CW Flasher

n1iicn1iic Posts: 19
edited 2005-07-19 21:10 in BASIC Stamp
Greetings, everyone.
I just bought the 'What is a Microcontroller' kit from RS last week hoping to make a few different projects.
I am starting with trying to make a LED flash CW. I started writing the code with the references for each letter, and then I found this code at http://www.qsl.net/kc8qno/Files/beacon_key(trans).bs2
I am trying to learn his code, but he says no support is available, so I didn't bother him.

*EDIT* I deleted the code that was here, it was malfunctioning code, and made for a long thread /EDIT

I realize that it is converting binary into dits and dahs, but how???
And what does changing the number in ELEMENTS do.

Feel free to start with a hint to point me in the right direction to finding my own answer. =]

Jason

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sick and tired of our media and the cheesy radio DJ's in the US? http://www.opieandanthony.com

Post Edited (n1iic) : 7/19/2005 9:12:01 PM GMT

Comments

  • Philip GamblinPhilip Gamblin Posts: 202
    edited 2005-07-19 04:29
    Generally speaking there are 5 timing elements in Morse code. Dit ( . ) time Dah ( _ ) time, element time is pause between individual Dits and Dahs and then Character time which is the pause between letters , and lastly the pause between words. I think I used a 1:3 ratio for dits and dahs respectively.
    Consider SOS
    Where (EP) = element pause, (CP) =character pause and (WP) = word pause

    S O S
    dit dit dit dah dah dah dit dit dit

    dit (EP) dit (EP) dit (CP) dah dah dah (CP) dit (EP) dit (EP) dit (WP) dit (EP) dit (EP) dit (CP) dah dah dah (CP) dit (EP) dit (EP) dit


    The subroutines are for each of the individual elements..... Dit, Dah, Element pause, Character pause, and word pause. Then the subroutines are called as necessary. Now the output pin 1 was probably used to key a relay via a transistor driver that operated the radio.
    If you are actually trying to learn Morse Code, there are much better ways. Looking at the code written in dits and dahs is THE ABSOLUTE WORST way to learn the code for a number of reasons. Try the www.arrl.org website. or Google 'morse code'.
    73 de KD5GKD
  • n1iicn1iic Posts: 19
    edited 2005-07-19 13:41
    Thanks Philip. Not trying to learn it again! =] I passed the 20 to get my Extra.
    This project is going to flash a matrix of LED's that have replaced a bulb inside a colored dome, and will be used at hamfests to send code. This is only a grins and giggles project.

    What I am trying to figure out is how it converts the DEC 20 into a V. It is not obvious in the code, and I do not understand enough of this yet.

    Thanks

    Jason

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sick and tired of our media and the cheesy radio DJ's in the US? http://www.opieandanthony.com
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-19 14:37
    I think I have it mostly figured out but I dont have time at this exact moment to explain it. Later today if noone has responded Ill post an explanation. A super quick nutshell, he is byte stuffing the morse code and the number of elements into a single byte, the 5 leftmost bits are the morse code, the three rightmost bits are the number of elements (dits and dahs) in the code. The code 20 is $14 in HEX meaning it has 4 elements which are 0001 or dit dit dit dah, you can set up a table to represent all the charactors, say A is dit-dah which is two elements so if you define MORSE_A to be %01000010 (dit dah 3 unused bits and 010 or two elements) or $42 in hex, 66 in decimal; you can use the MORSE_A in your lookup tables to make it easier to write strings·in morse.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 7/19/2005 2:58:44 PM GMT
  • n1iicn1iic Posts: 19
    edited 2005-07-19 16:15
    Thanks. I will try to understand it how you explained it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sick and tired of our media and the cheesy radio DJ's in the US? http://www.opieandanthony.com
  • n1iicn1iic Posts: 19
    edited 2005-07-19 16:40
    Well, after wondering why it was sending SK instead of V, I figured out that I can't re-arrange the subroutines at the end to make it easier to follow. This is the correct code.
    I am a little puzzled why I can't move subroutines around, but that will come in time.

    'KC8QNO Beacon Software for the Basic Stamp 2
    'Pin 1 controls the morse key on the rig
    'Pin 2 controls the LED on the Stamp
    
    
    INDEX1  VAR  Byte
    INDEX2  VAR  Byte
    ELEMENTS  VAR  Byte
    CHARACTER   VAR   Byte
    DELAY  CON  1500
    I    VAR  Byte
    C    VAR  Byte
    
    IDENTIFY:
      LOW 2
      FOR I = 1 TO 8              'Loop for one "dit" every 2 sec
      CHARACTER = 1              'until ID string (8 times)
      GOSUB MORSE
      PAUSE 2000
      NEXT
      PAUSE 1000                'Time Between Words
      FOR INDEX1 = 0 TO 2
      LOOKUP INDEX1,[noparse][[/noparse]20,20,20],CHARACTER               'VVV
      GOSUB MORSE
      PAUSE 1000
      NEXT
      FOR INDEX1 = 0 TO 5
      LOOKUP INDEX1,[noparse][[/noparse]132,1,66,164,227,130],CHARACTER    'BEACON
      GOSUB MORSE
      NEXT
      PAUSE 1000
      FOR INDEX1 = 0 TO 1
      LOOKUP INDEX1,[noparse][[/noparse]131,1],CHARACTER        'DE
      GOSUB MORSE
      NEXT
      PAUSE 1000
      FOR INDEX1 = 0 TO 5
      LOOKUP INDEX1,[noparse][[/noparse]163,164,229,212,130,227],CHARACTER  'KC8QNO
      GOSUB MORSE
      NEXT
      PAUSE 1000
      FOR INDEX1 = 0 TO 6
      LOOKUP INDEX1,[noparse][[/noparse]129,35,3,164,227,68,66],CHARACTER  'TUSCOLA
      GOSUB MORSE
      NEXT
      PAUSE 1000
      FOR INDEX1 = 0 TO 1
      LOOKUP INDEX1,[noparse][[/noparse]164,227],CHARACTER        'CO
      GOSUB MORSE
      NEXT
      PAUSE 1000
      FOR INDEX1 = 0 TO 1
      LOOKUP INDEX1,[noparse][[/noparse]194,2],CHARACTER        'MI
      GOSUB MORSE
      NEXT
      PAUSE 1000
      FOR INDEX1 = 0 TO 1
      LOOKUP INDEX1,[noparse][[/noparse]3,163],CHARACTER        'SK
      GOSUB MORSE
      NEXT
      RETURN
    MORSE:  ELEMENTS = CHARACTER & %00000111
      IF ELEMENTS = 7 THEN ADJUST1
      IF ELEMENTS = 6 THEN ADJUST2
    BANG_KEY:
      FOR INDEX2 = 1 TO ELEMENTS
      IF CHARACTER >= 128 THEN DAH
      GOTO DIT
    REENTER:
      CHARACTER = CHARACTER * 2
      NEXT
      GOSUB CHAR_SP
      RETURN
    ADJUST1:
      ELEMENTS = 6
      GOTO BANG_KEY
    ADJUST2:
      CHARACTER = CHARACTER & %11111011
      GOTO BANG_KEY
    DIT:  HIGH 2
      LOW 1
      PAUSE 175
      LOW 2
      HIGH 1
      PAUSE 125      'Letter Speed (DIT and DAH must match here or the code
      GOTO REENTER    'sounds funny
    DAH:  HIGH 2
      LOW 1
      PAUSE 375
      LOW 2
      HIGH 1
      PAUSE 125      'Letter Speed (DIT and DAH must match here or the code
      GOTO REENTER    'sounds funny
    CHAR_SP:
      LOW 2
      HIGH 1
      PAUSE 500      'Time Between Letters (Characters)
      RETURN
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sick and tired of our media and the cheesy radio DJ's in the US? http://www.opieandanthony.com
  • Philip GamblinPhilip Gamblin Posts: 202
    edited 2005-07-19 17:02
    Sorry Jason, I apologized in a private message.Never got my 20 but I did pass my 13...Then they caved in, and everyone upgraded Hi Hi. The description I gave in my previous post was how MY program (that I have lost) worked. I think what he has done is to encode all the chars into binary and then the subroutines take the bytes handle the code generation.

    Paul got it the first time. Hope this visual helps.

    Bit #················ 7···· 6···· 5··· 4··· 3·· 2·· 1·· 0

    bit value········· 128·· 64·· 32·· 16·· 8·· 4·· 2·· 1



    B···················· 1···· 0···· 0··· 0·····0···1·· 0··· 0················ = 132

    E···················· ·0··· 0···· 0··· 0··· 0····0·· 0··· 1················ = 1

    A······················0····1···· 0··· 0··· 0··· 0··· 1··· 0··············· = 66

    C····················· 1··· O···· 1··· 0··· 0··· 1··· 0··· 0··············· = 164

    O····················· 1···· 1···· 1··· 0··· 0··· 0··· 1··· 1············· = 227

    N····················· 1····· 0····0···· 0··· 0··· 0··· 1··· 0············ = 130

    This is just a visual of what Paul was saying. The upper 5 bits represent the character in dahs ( 1 )·and dits ( 0 ) and the lower three bytes represent the number of elements in character b= 1 000 + 0100 or Dah dit dit dit ( an "extra" or unused bit) + the lower bits 0100 telling the subroutine that there are 4 elements in the character. It's a much more elegant method than what I used. Hope this helps.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-19 17:29
    Right so you can define
    MORSE_A CON 66
    MORSE_B CON 132
    MORSE_c CON 164
    MORSE_E CON 1
    MORSE_N CON 130
    MORSE_O CON 227
    

    Then declare

    LOOKUP INDEX1,[noparse][[/noparse]MORSE_B,MORSE_E,MORSE_A,MORSE_C,MORSE_O,MORSE_N],CHARACTER    'BEACON  
    

    ·If you define all of the morse charactors, creating lookup strings·is an easier task.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • n1iicn1iic Posts: 19
    edited 2005-07-19 18:00
    So, 3 would be I, 131 is D, I get it now.

    Very out of the box!

    Thank You for your help, gentlemen. It would have been a long time before I understood it. I will let you know how the "drinking light" project comes along.
    If anyone makes it to Hosstraders hamfest here in NH, let me know.


    Jason

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sick and tired of our media and the cheesy radio DJ's in the US? http://www.opieandanthony.com
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-07-19 18:30
    Actually, I is 2 (2 dits), 3 would be S (3 dits)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Philip GamblinPhilip Gamblin Posts: 202
    edited 2005-07-19 18:51
    Paul gets the credit for doing the real work, I just came along for the ride. Keep us posted.
  • n1iicn1iic Posts: 19
    edited 2005-07-19 21:10
    With a little help from my friends, this is verison 2.0

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    'KC8QNO Beacon Software for the Basic Stamp 2 Upgraded by n1iic July 2005. Verison 2.0
    'Pin 1 controls the morse key on the rig
    'Pin 2 controls the LED on the Stamp
    'The Uniden HR2510 radio that KC8QNO used has a PTT toggle, so no PTT control here. Easy
    ' to add if you like.
    'I took KC8QNO's original code, and added constants for letters, numbers, and some
    ' prosigns and punctiation to allow easier programming for the charaters to be sent. He
    ' originally used it for a 10 meter beacon.
    'I would have done international characters, but I can't make them on my keyboard.
    'This  code functions with the 5 upper bits as the morse flags, and the last 3 bits
    ' as the character length. 10000101 is the numeral six. 10000 is the morse charcter,
    ' and 101 is binary for 5, the length of the character. 00000001 is E.
    'To conserve space, use decimal instead of the constants as done originally by KC8QNO
    ' and delete the letter/number/prosign portion of the init subroutine.
    
    GOSUB init
    IDENTIFY:
      FOR INDEX1 = 0 TO 4
      LOOKUP INDEX1,[noparse][[/noparse]n,one,i,i,c],CHARACTER
      GOSUB MORSE
      NEXT
      PAUSE 1000
      FOR INDEX1 = 0 TO 7
      LOOKUP INDEX1,[noparse][[/noparse]d,r,i,n,k,i,n,g],CHARACTER
      GOSUB MORSE
      NEXT
      PAUSE 1000
      FOR INDEX1 = 0 TO 4
      LOOKUP INDEX1,[noparse][[/noparse]l,i,g,h,t],CHARACTER
      GOSUB MORSE
      NEXT
      PAUSE 1000
    
      RETURN
    MORSE:  ELEMENTS = CHARACTER & %00000111
      IF ELEMENTS = 7 THEN ADJUST1
      IF ELEMENTS = 6 THEN ADJUST2
    BANG_KEY:
      FOR INDEX2 = 1 TO ELEMENTS
      IF CHARACTER >= 128 THEN DAH
      GOTO DIT
    REENTER:
      CHARACTER = CHARACTER * 2
      NEXT
      GOSUB CHAR_SP
      RETURN
    ADJUST1:
      ELEMENTS = 6
      GOTO BANG_KEY
    ADJUST2:
      CHARACTER = CHARACTER & %11111011
      GOTO BANG_KEY
    DIT:  HIGH 2
      LOW 1
      PAUSE 175
      LOW 2
      HIGH 1
      PAUSE 125      'Letter Speed (DIT and DAH must match here or the code
      GOTO REENTER    'sounds funny
    DAH:  HIGH 2
      LOW 1
      PAUSE 375
      LOW 2
      HIGH 1
      PAUSE 125      'Letter Speed (DIT and DAH must match here or the code
      GOTO REENTER    'sounds funny
    CHAR_SP:
      LOW 2
      HIGH 1
      PAUSE 500      'Time Between Letters (Characters)
      RETURN
    
    INIT:
    
    INDEX1  VAR  Byte
    INDEX2  VAR  Byte
    ELEMENTS  VAR  Byte
    CHARACTER   VAR   Byte
    DELAY  CON  1500
    II    VAR  Byte
    
    A CON 66
    B CON 132
    c CON 164
    d CON 131
    E CON 1
    f CON 36
    g CON 195
    h CON 4
    i CON 2
    j CON 116
    k CON 163
    l CON 68
    m CON 194
    N CON 130
    O CON 227
    p CON 148
    q CON 212
    r CON 67
    s CON 3
    t CON 129
    u CON 35
    v CON 20
    w CON 99
    x CON 148
    y CON 180
    z CON 196
    zero CON 253
    one CON 125
    two CON 61
    three CON 29
    four CON 13
    five CON 5
    six CON 133
    seven CON 197
    eight CON 229
    nine CON 245
    slash CON 149
    equals CON 141
    ar CON 85
    as CON 69
    bt CON 142
    kn CON 181
    sk CON 45
    RETURN
    
    'Block of original code
    '  FOR INDEX1 = 0 TO 5
    '  LOOKUP INDEX1,[noparse][[/noparse]163,164,229,212,130,227],CHARACTER  'KC8QNO
    '  GOSUB MORSE
    '  NEXT
    '  PAUSE 1000
    
    



    It's really bloated, but at least it now has comments. The fluff and the constants can be axed if the space is critical.

    Now to figure out the best way to build LED replacements for the bulbs, and to find a good price on white LED's.
    In the 2nd version of the hardware I want to have chasing rows or columns. If I REALLY get ambitious, a matrix so I can scroll letters. scool.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sick and tired of our media and the cheesy radio DJ's in the US? http://www.opieandanthony.com
Sign In or Register to comment.