OpenBCM V1.08-5-g2f4a (Linux)

Packet Radio Mailbox

IZ3LSV

[San Dona' di P. JN]

 Login: GUEST





  
M0PZT  > TECH     15.03.09 01:33l 116 Lines 3055 Bytes #999 (0) @ WW
BID : 590030M0PZT
Read: GUEST
Subj: BASIC Stamp Morse Code
Path: IZ3LSV<IK2XDE<DB0RES<ON0BEL<GB7CIP<GB7ESX
Sent: 090314/1715z 37980@GB7ESX.#31.GBR.EU $:590030M0PZT  [Witham, Esx]NNA V3.1


Some code for making a BASIC Stamp produce a bit of CW...

TONE CON 850 - defines 850 as a Constant.  I use this to specify a CW
frequency for my repeater logic - Rather than changing every instance of
850, you just use a Constant!

COR_SENSE PIN 0 - renames Pin0 to something more memorable
PTT PIN 1 - renames Pin1 to something more memorable
CWOUT PIN 2 - renames Pin2 to something more memorable
HIGH PTT - sends the PTT output (pin1) HIGH (+v)

Let's put some of this code into practice:

'{$STAMP BS2}
'{$PORT COM1}
'{$PBASIC 2.5}
MAIN:
IF COR_SENSE = 1 THEN ACTIVE
GOTO MAIN
ACTIVE:
HIGH PTT
IF COR_SENSE = 1 THEN ACTIVE
ELSE
FREQOUT CWOUT,150,TONE
LOW PTT
ENDIF
GOTO MAIN

That's a very simple routine to monitor the input pin (connected to the
squelch output of a radio, for example) and when it goes +5v, the PTT is
enabled and the code continues to check the input and loops until it goes
low.  When it does, a beep is produced and the PTT is turned off.

Loop routines are useful to save code space - You can define a variable
and have that variable increment by +1 each time your loop cycles through.
 Once your Variable is reached, the code moves on.  My example below is a
beeper which sends a longer beep after 5 short beeps... Simple, but it a
good starting point!

Notice how I use a Constant for the beep output pin - Imagine a large
project with many instances of the FREQOUT command and you decided to
change the output pin (or worse, the frequency of the beep!) - a Constant
saves the day (and your valuable time).

'{$STAMP BS2}
'{$PORT COM1}
'{$PBASIC 2.5}

CWOUT PIN 9
I VAR Word
BEEP_COUNT VAR Word

BEEP_COUNT = 1

START:
DO
FOR I = 0 TO 1000 ' Repeat every 1 seconds
NEXT
IF BEEP_COUNT > 5 THEN DONE
BEEP_COUNT = BEEP_COUNT + 1
DEBUG "Beep!" , CR
FREQOUT CWOUT,150,850 ' Beep!
LOOP
DONE:
BEEP_COUNT = 1
DEBUG "Finished!" , CR
FREQOUT CWOUT,500,850 ' A Longer Beep!
GOTO START

I mentioned using Constants to replace the beep output pin (and even the
beep frequency) earlier, you can make this into a more elaborate project
by turning your simple beeper into a Morse Code beacon.

By adding LOOKUP and BRANCH commands, we can tell the code to send either
a DIT or a DAH:

MORSE:
BRANCH CHARACTER,[SPACE,DIT,DAH]
RETURN
DAH:
FREQOUT CWOUT,250,TONE ' 250mS for a DAH
PAUSE 25
RETURN
DIT:
FREQOUT CWOUT,90,TONE ' 90mS for a DIT
PAUSE 25
RETURN
SPACE:
PAUSE 175 ' 175mS for a word-gap
RETURN

To vary the speed of the Morse Code, you simply adjust the above timing
parameters - Or, if you regularly need to call a faster CW speed,
duplicate this section and re-name it to something like MORSE_FAST: ...
It's really very simple!

The routine for sending a Morse Code sequence is fairly straightforward:

SEND_ID
FOR I = 0 TO 6
LOOKUP I, [2,2,2,0,2,1,2],CHARACTER ' Sends "OK"
GOSUB MORSE
NEXT

...and if you wanted to use the faster CW speed, you would GOSUB
MORSE_FAST instead.

See my website for more complex examples of BASIC Stamp code.

--
Charlie - M0PZT @ GB7ESX.#31.GBR.EU
http://www.m0pzt.net

Sent: 17:12 on 14 Mar 2009


Read previous mail | Read next mail


 23.12.2024 02:44:42lGo back Go up