+ Reply to Thread
Results 1 to 4 of 4

Thread: Morse Code Bot

  1. #1
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    1,060

    Default Morse Code Bot

    Hi Guys

    Hereís a video which shows the crux of a project to use a custom pic controlled TENS unit to contract my muscles
    through the use of electrodes, to make my hand key some predefined, valid Morse code:



    There are a couple of other videos on my channel prior to this, of the same series that better explain the background of the project.
    This one is jus the crux of it containing the best demo so far.

  • #2
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    1,060

    Default Re: Morse Code Bot

    ... and here is the source for the pic 16F628A, current at the time the video was made.
    Enjoy

    Code:
    '
    '****************************************************************
    '*                                                              *
    '*             Morse TENS controller V1 - Art 2019              *
    '*              For Microchip Pic 16F628A @ 10MHz               *
    '*                                                              *
    '****************************************************************
    '
    '
    DEFINE OSC 10		'10 MHz oscillator
    DEFINE NO_CLRWDT 1	'tell compiler not to insert clrwdt instructions
    '
    DATA " MORSE TENS - BREK MARTIN 2019 "
    '
    oout var portb.1	'orange led
    fout var portb.3	'frequency out
    gout var portb.2	'transistor output with green led
    rout var portb.4	'transistor output with red led
    hbut var porta.2	'pcb button input
    '
    key var byte		'key state - 0 = up 1 = down
    mval var byte		'lookup return value
    mcnt var byte		'lookup counter
    sval var byte		'
    scnt var byte		'
    kcnt var byte		'key stroke counter
    dcnt var byte		'
    fsel var byte		'frequency selection
    quit var bit		'
    space var bit		'
    dotlen var word		'dot length is one unit
    dashlen var word	'dash length is three units
    lettersp var word	'spacing within a letter is one unit
    wordsp var word		'spacing between letters is three units
    longsp var word		'spacing between words is seven units
    '
    'execution begins
    '
    'some of these morse constant periods are defined
    'incorrectly but compensated for at execution time
    dotlen = 100		'dot length is one unit
    dashlen = 300		'dash length is three units
    lettersp = 100		'spacing within a letter is one unit
    wordsp = 200		'spacing between letters is three units
    longsp = 600		'spacing between words is seven units
    '
    key = 0				'reset for startup
    mval = 0			'
    mcnt = 0			'
    sval = 0			'
    scnt = 0			'
    kcnt = 0			'
    quit = 0			'
    fsel = 1			'begin with default low duty cycle
    '
    CMCON = 7			'set ports to digital
    trisb = %00000000  	'
    trisa = %00000100	'
    '
    oout = 0			'set outputs
    gout = 0			'
    rout = 1			'
    fout = 0			'
    '
    gosub debout		'startup delay
    gosub setfreq		'start pwm
    pause 1000			'
    '
    cycle:				'main loop
    gosub sendstring
    pause 5000
    goto cycle			'repeat forever
    '
    getdefinition:		'define morse code
    lookup mcnt,[_
    1,1,1,1,1,8,_ '0
    0,1,1,1,1,8,_ '1
    0,0,1,1,1,8,_ '2
    0,0,0,1,1,8,_ '3
    0,0,0,0,1,8,_ '4
    0,0,0,0,0,8,_ '5
    1,0,0,0,0,8,_ '6
    1,1,0,0,0,8,_ '7
    1,1,1,0,0,8,_ '8
    1,1,1,1,0,8,_ '9
    0,1,8,8,8,8,_ 'A
    1,0,0,0,8,8,_ 'B
    1,0,1,0,8,8,_ 'C
    1,0,0,8,8,8,_ 'D
    0,8,8,8,8,8,_ 'E
    0,0,1,0,8,8,_ 'F
    1,1,0,8,8,8,_ 'G
    0,0,0,0,8,8,_ 'H
    0,0,8,8,8,8,_ 'I
    0,1,1,1,8,8,_ 'J
    1,0,1,8,8,8,_ 'K
    0,1,0,0,8,8,_ 'L
    1,1,8,8,8,8,_ 'M
    1,0,8,8,8,8,_ 'N
    1,1,1,8,8,8,_ 'O
    0,1,1,0,8,8,_ 'P
    1,1,0,1,8,8,_ 'Q
    0,1,0,8,8,8,_ 'R
    1,1,1,8,8,8,_ 'S
    1,8,8,8,8,8,_ 'T
    0,0,1,8,8,8,_ 'U
    0,0,0,1,8,8,_ 'V
    0,1,1,8,8,8,_ 'W
    1,0,0,1,8,8,_ 'X
    1,0,1,1,8,8,_ 'Y
    1,1,0,0,8,8_ 'Z
    ],mval
    @ clrwdt
    return
    '
    getstring:			'string to be sent terminated with a full stop
    lookup scnt,["VK4FAST CQDX CQDX CQDX  VK4FAST CQDX CQDX CQDX  ..."],sval
    return
    '
    sendstring:
    scnt = 0			'reset string counter
    sval = 0			'reset string character return value
    quit = 0			'
    '
    while quit = 0		'while character is not the full stop
    
    gosub checkbutton	'check the pcb button for frequency select
    
    gosub getstring		'get character value to sval variable
    scnt = scnt + 1		'increment string index counter
    '
    if sval = $2E then
    quit = 1
    endif
    if sval = $20 then
    space = 1
    else
    space = 0
    endif
    '
    if sval > $40 then	'offset alpha characters for lookup table
    sval = sval - $40
    sval = sval + 9
    sval = sval * 6		'adjust for real character offset in lookup table
    else
    if sval > $2F then	'offset numeric characters for lookup table index
    sval = sval - $30
    sval = sval * 6		'adjust for real character offset in lookup table
    endif
    endif
    '
    if quit = 0 then	'get the character morse definition
    mcnt = sval			'
    mval = 0			'
    if space == 1 then	'is a space character
    pause longsp		'
    else				'not a space character
    '
    while mval != 8		'
    gosub getdefinition	'
    mcnt = mcnt + 1		'
    if mval = 0 then
    rout = 0
    gout = 1
    pause dotlen
    gout = 0
    rout = 1
    endif
    if mval = 1 then
    rout = 0
    gout = 1
    pause dashlen
    gout = 0
    rout = 1
    endif
    pause lettersp
    wend				'end morse definition
    '
    pause wordsp - lettersp
    '
    endif				'end not space
    endif				'end not quit
    wend				'end not quit
    return
    '
    debout:
    rout = 1
    for dcnt = 0 to 10
    pause 60
    @ clrwdt
    oout = 1
    pause 60
    @ clrwdt
    oout = 0
    next dcnt
    return
    '
    cntout:
    rout = 1
    for dcnt = 0 to fsel
    pause 50
    @ clrwdt
    oout = 1
    pause 50
    @ clrwdt
    oout = 0
    next dcnt
    pause 200
    return
    '
    checkbutton:
    if hbut = 1 then	'increment selection
    fsel = fsel + 1
    else
    return
    endif
    if fsel > 4 then	'limit selection value
    fsel = 0
    endif
    setfreq:
    gosub cntout
    if fsel = 0 then
    PR2 = %11111001		'2.5 khz 50% duty (maximum power)
    T2CON = %00000101	'
    CCPR1L = %01111100	'
    CCP1CON = %00111100	'
    endif
    if fsel = 1 then
    PR2 = %11111001		'2.5 khz 20% duty (default)
    T2CON = %00000101	'
    CCPR1L = %00110001	'
    CCP1CON = %00111100	'
    endif
    if fsel = 2 then
    PR2 = %11111001		'2.5 khz 25% duty
    T2CON = %00000101	'
    CCPR1L = %00111110	'
    CCP1CON = %00011100	'
    endif
    if fsel = 3 then
    PR2 = %11111001		'2.5 khz 30% duty
    T2CON = %00000101	'
    CCPR1L = %01001010	'
    CCP1CON = %00111100	'
    endif
    if fsel = 4 then
    PR2 = %11111001		'2.5 khz 40% duty
    T2CON = %00000101	'
    CCPR1L = %01100011	'
    CCP1CON = %00111100	'
    endif
    ' experimental values tested with magnetic coupled piezo buzzer
    ' pwm settings are verified but not tested on a human
    ' these settings could possibly be painful so take care
    'if fsel = 2 then
    'PR2 = %01100111		'1.5 khz 50% duty
    'T2CON = %00000111	'
    'CCPR1L = %00110011	'
    'CCP1CON = %00111100	'
    'endif
    'if fsel = 3 then
    'PR2 = %10011011		'1.0 khz 50% duty
    'T2CON = %00000111	'
    'CCPR1L = %01001101	'
    'CCP1CON = %00111100	'
    'endif
    '
    pause 20		'debounce
    return
    '
    ‘
    '

  • #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,199

    Default Re: Morse Code Bot

    Brek, Talking about Morse code and it being Field Day today I thought I would add a small program that I wrote some years ago for an 10F222 to be put onto a 3 pin stereo plug and pluged into an HT for Fox Hunting. Enjoy. and 73's.
    Dave Purola,
    N8NTA
    EN82fn

  • #4
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    1,060

    Default Re: Morse Code Bot

    I got VK4FAST. It would be really cool to give that a meaning

  • Similar Threads

    1. Replies: 0
      Last Post: - 9th September 2018, 01:43
    2. Serial problem between BasicStamp code and PBP code
      By AllanZilkowsky in forum mel PIC BASIC Pro
      Replies: 22
      Last Post: - 6th April 2014, 02:15
    3. Working code but my layman approach uses too much code space
      By Christopher4187 in forum mel PIC BASIC Pro
      Replies: 4
      Last Post: - 14th December 2012, 20:44
    4. Morse code reader compiles but won't run
      By VE7ZNU in forum mel PIC BASIC
      Replies: 3
      Last Post: - 6th April 2009, 22:07

    Members who have read this thread : 18

    You do not have permission to view the list of names.

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts