Sierra

Radio

PayPal: View Cart

8A Relay Board Kit

Relay board stacked on a CPU board

Resources

FAQ Frequently Asked Questions

Builders Alert !

HamStack


8A Relay Board

' cw_beacon.bas   This program sends a message in CW forever


Device = 18F4620           ' Set the CPU type to a Microchip 18F4620

Clock = 10                 ' Set CPU clock frequency to 10 MHz

Include "string.bas"       ' Include the string manipulation subroutines

Include "usart.bas"        ' Include the RS232 UART subroutines


'----- VARIABLE DEFINITIONS ---------------------------------------

Dim wpm         As Byte       ' CW speed in words per minute

Dim cw_string   As String(30) ' CW message to be sent

Dim cw_time     As Word       ' Calculated time value of a dit in ms.

Dim cw_len      As Byte       ' Working variable, length of string

Dim i           As Byte       ' Working variable

Dim x           As Byte       ' Working variable

Dim y           As Byte       ' Workign variable

Dim cw_char     As String(2)  ' Holds the character being sent

Dim cw_bits     As String(15) ' Dit / Dah pattern being sent

Dim cw_temp     As String(2)  ' Working variable

Dim led         As PORTC.0    ' Assign the name "LED" to RC0  

Dim relay       As PORTB.3    ' Assign the name "relay" to port RB3


'----- DEFINE PIN DIRECTIONS --------------------------------------

'Pin function.  GPIO is General Purpose IO.  () undicates default use.

TRISA.4 = 1  ' Mode button

TRISB.3 = 0     ' Relay 1

TRISC.0 = 0     ' Status LED


'----- INITIALIZE VARIABLES AND SERIAL PORT ------------------------

SetBaudrate(br9600)                      ' Set serial baud rate to 9600

cw_string = "CQ CQ CQ DE W6ABC W6ABC"    ' CW message to be sent

wpm = 13                                 ' CW speed in words per minute


'----- START MAIN PROGRAM CODE -------------------------------------

DelayMS(500)                   ' Pause for 500ms after hardware reset

USART.Write("Beacon program will send " + cw_string + " forever.", 13, 10)    

cw_time = 1200 / wpm           '  Calculate the length of a dit

cw_len = Length(cw_string)     '  Determine the length of the string

'----- START MASTER CONTROL LOOP ------------------------------------


master_loop:   ' Outer loop will process the whole string.

    For i = 0 To cw_len-1                        ' Go through the string

        cw_char = Mid(cw_string,i,1)             ' Grab the current char

        USART.Write("Sending: ", cw_char, 13, 10)' Send char serial port


        Select cw_char                  

            Case "A"  :  cw_bits = ".-"    

            Case "B"  :  cw_bits = "-..."

            Case "C"  :  cw_bits = "-.-."

            Case "D"  :  cw_bits = "-.."

            Case "E"  :  cw_bits = "."

            Case "F"  :  cw_bits = "..-."

            Case "G"  :  cw_bits = "--."

            Case "H"  :  cw_bits = "...."

            Case "I"  :  cw_bits = ".."

            Case "J"  :  cw_bits = ".---"

            Case "K"  :  cw_bits = "-.-"

            Case "L"  :  cw_bits = ".-.."

            Case "M"  :  cw_bits = "--"

            Case "N"  :  cw_bits = "-."

            Case "O"  :  cw_bits = "---"

            Case "P"  :  cw_bits = ".--."

            Case "Q"  :  cw_bits = "--.-"

            Case "R"  :  cw_bits = ".-."

            Case "S"  :  cw_bits = "..."

            Case "T"  :  cw_bits = "-"

            Case "U"  :  cw_bits = "..-"

            Case "V"  :  cw_bits = "...-"

            Case "W"  :  cw_bits = ".--"

            Case "X"  :  cw_bits = "-..-"

            Case "Y"  :  cw_bits = "-.--"

            Case "Z"  :  cw_bits = "--.."

            Case "0"  :  cw_bits = "-----"

            Case "1"  :  cw_bits = ".----"

            Case "2"  :  cw_bits = "..---"

            Case "3"  :  cw_bits = "...--"

            Case "4"  :  cw_bits = "...-"

            Case "5"  :  cw_bits = "....."

            Case "6"  :  cw_bits = "-...."

            Case "7"  :  cw_bits = "--..."

            Case "8"  :  cw_bits = "---.."

            Case "9"  :  cw_bits = "----."

            Case "/"  :  cw_bits = "-..-."

            Case "="  :  cw_bits = "-...-"

            Case " "  :  cw_bits = " "

        EndSelect  

 '  This section sends the individual dits and dahs


        x = Length(cw_bits)                 ' How many dits and dahs ?


        For y = 0 To x-1                    ' Loop through sending each


            cw_temp = Mid(cw_bits,y,1)      ' Grab the dit or dah


            If cw_temp = "." Then           ' Check for dit

                High(led)                   ' Turn on the LED

                High(relay)                 ' Key down relay #1

                DelayMS(cw_time)            ' Wait for one dit

                Low(led)                    ' Turn off the LED

                Low(relay)                  ' Unkey relay #1

                DelayMS(cw_time)            ' Wait for one dit

            EndIf


            If cw_temp = "-" Then           ' Check for dah

                High(led)                   ' Turn on the LED

                High(relay)                 ' Key down relay #1

                DelayMS(cw_time * 3)        ' Wait for one dah

                Low(led)                    ' Turn off the LED

                Low(relay)                  ' Unkey relay #1

                DelayMS(cw_time)            ' Wait for one dit

            EndIf


            If cw_temp = " " Then           ' If space?  If so...

                DelayMS(cw_time * 7)        ' Wait for 7 dits

            EndIf  

  

        Next                                ' Send the next dit or dah

        

        ' Now that all the dits and dahs are sent...

        DelayMS(cw_time * 3)                ' Delay the length of 3 dits

 

    Next                                    ' Go to the next character


' All characters in the string have been sent.    

DelayMS(cw_time * 7)                        ' Delay the length of 7 dits

GoTo master_loop                            ' Go back and loop forever


Just for fun, here is a little test program written in Swordfish Basic that uses the relay board to send as text string in CW with relay 1 connected to CPU pin RB.3

$29.95

Price: