;444444444444444444444444444444444444444444444444444444444444444444444444 ;4 4 ;4 BEACON KEYER WITH 5 SPEED PRESETS 4 ;4 4 ;444444444444444444444444444444444444444444444444444444444444444444444444 ' Here is a nifty way to encode the Morse Code alphabet into BYTE sized bites... ' First, start by changing Dits and Dahs into 0's and 1's respectively. ' So ' a V would be 0001 (dit dit dit dah) ' ' Secondly, arrange the zeros and ones from right to left in the order of sending ' So ' 0001 is now 1000 ' add any zeros to make the code always 5 bits wide ' So ' 1000 now becomes 01000 ' ' Next, take the number of dits and dahs in the Morse character and... ' write that in binary ' So ' 4 dits & dahs becomes 100 ' and stick it in front of the 5 bit code from the step above ' So ' 100 + 01000 = 10001000 ' which happens to make the encoded characters always 1 byte long ' So ' the V character = 10001000 (binary) = 128 + 16 = 144 (decimal) ' ' Next, when you want to decode the data, you mask off the top 3 bits. ' To mask off bits, logical 'AND' the data with a mask byte which ' contains 1's only in the bits you want to have in the result. ' So ' 10001000 & 11100000 yields 10000000 = 128 (decimal) ' And then divide the result by 32 which happens to be the value of the ' place for bit5 which is the lowest 1 bit in the mask ' Now ' 10000000 /32 (or shifted 5 places) = 00000100 or 4 (decimal) ' and there are 4 dits and dahs in V. ' ' ' Lastly, when you want to check the data for dits and dahs... ' Starting at the very right, or bit0, construct a mask containg ONLY ' that bit set and logical 'AND' the mask with the data byte. ' If the result is zero, then the bit you are checking is a 0 or DIT ' If the result is greater than zero, then it is a 1 or DAH. ' Continue checking the data bits in the BYTE until you have looked at ' the proper number of bits as coded in the upper 3 bit value. ' ' So from the top 3 bits ' 10000000 & 11100000 = 10000000 = 128 (decimal) /32 = 4 elements ' ' 10001000 & 00000001 = 00000000 = dit = element 1 ' 10001000 & 00000010 = 00000000 = dit = element 2 ' 10001000 & 00000100 = 00000000 = dit = element 3 ' 10001000 & 00001000 = 00001000 = dah = element 4 ' ' and that is how the Morse characters are coded into data BYTES ' ' Morse Code characters encoded into BYTES ' ELEMENTS ' Char. Morse Code # CODE BYTE DECIMAL ' A dit dah.............2 01..........01000010 66 ' B dah dit dit dit.....4 1000........10000001 129 ' C dah dit dah dit.....4 1010........10000101 133 ' D dah dit dit.........3 100.........01100001 97 ' E dit.................1 0...........00100000 32 ' F dit dit dah dit.....4 0010........10000100 132 ' G dah dah dit.........3 110.........01100011 99 ' H dit dit dit dit.....4 0000........10000000 128 ' I dit dit.............2 00..........01000000 64 ' J dit dah dah dah.....4 0111........10001110 142 ' K dah dit dah.........3 101.........01100101 101 ' L dit dah dit dit.....4 0100........10000010 130 ' M dah dah.............2 11..........01000011 67 ' N dah dit.............2 10..........01000001 65 ' O dah dah dah.........3 111.........01100111 103 ' P dit dah dah dit.....4 0110........10000110 134 ' Q dah dah dit dah.....4 1101........10001011 139 ' R dit dah dit.........3 010.........01100010 98 ' S dit dit dit.........3 000.........01100000 96 ' T dah.................1 1...........00100001 33 ' U dit dit dah.........3 001.........01100100 100 ' V dit dit dit dah.....4 0001........10001000 136 ' W dit dah dah.........3 011.........01100110 102 ' X dah dit dit dah.....4 1001........10001001 137 ' Y dah dit dah dah.....4 1011........10001101 141 ' Z dah dah dit dit.....4 1100........10000011 131 ' 1 dit dah dah dah dah.5 01111.......10111110 190 ' 2 dit dit dah dah dah.5 00111.......10111100 188 ' 3 dit dit dit dah dah.5 00011.......10111000 184 ' 4 dit dit dit dit dah.5 00001.......10110000 176 ' 5 dit dit dit dit dit.5 00000.......10100000 160 ' 6 dah dit dit dit dit.5 10000.......10100001 161 ' 7 dah dah dit dit dit.5 11000.......10100011 163 ' 8 dah dah dah dit dit.5 11100.......10100111 167 ' 9 dah dah dah dah dit.5 11110.......10101111 175 ' 0 dah dah dah dah dah.5 11111.......10111111 191 ' / dah dit dit dah dit 5 10010.......10110010 180 ' AR dit dah dit dah dit 5 01010.......10101010 170 ' . dit dah dit dah dit dah.....special......... 252 ' space.......................................................255 ' 'END OF LESSON! '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 'Define the Input & Output lines Output 0 'OPTO #1 Output 1 'OPTO #2 *OR* PIEZO/SPEAKER Input 2 'MUX SWITCHES *OR* VOLTAGE INPUT Input 3 'IR INPUT Input 4 'SWITCH *OR* ONE-WIRE TEMP SENSOR 'Define come constants used in generating Morse Code Symbol Time1=3000 'time between chirping and sending call sign = 3 sec. or 3000 msec. Symbol Time2=5000 'time between becon transmissions = 30 sec. or 30000 msec. Symbol Keypin=0 'Keying through Opto1 Symbol PZOpin=1 'Piezo sounder here Symbol Freq=122 'Sidetone frequency 'Define some variables to hold variable data Symbol I=b1 'Loop variable for call sign letter position Symbol J=b2 'Loop variable for element position in Morse character Symbol K=b3 'Variable holding successive Morse bit data from character Symbol V=b13 'Variable holding LAST battery reading Symbol Mchar=b4 'Variable holding the current Morse character for transmission Symbol Numdit=b5 'Variable holding the # of elements data of the Morse character Symbol Ditdat=b6 'Variable holding the element data of the Morse character Symbol Mask=b7 'Variable holding changing mask data to obtain ' successive bits in the Morse character Symbol Send=w4 'Word length variable holding 'rather' large numbers ' for the time constants Ditlen*3, 500, 1000 Symbol Ditlen=b10 'time length of basic DIT ' 240ms = 5 WPM ' 120ms = 10 WPM ' 92ms = 13 WPM ' 80ms = 15 WPM ' 60ms = 20 WPM Symbol OPT=b11 'MUX switch settings Symbol AD=b12 'A/D input value Bcon: Gosub MUX 'Get MUX switch settings Lookup OPT,(24,12,9,8,6),Ditlen 'convert MUX sw reading to appropriate ' tone units ( 10 msec/unit ) ' 24 units = 240ms = 5 WPM ' 12 units = 120ms = 10 WPM ' 9 units = 90ms = 13 WPM ' 8 units = 80ms = 15 WPM ' 6 units = 60ms = 20 WPM MORSE: '************************************************************************************** For J=1 to 18 'My beacon message is 18 characters (including spaces & prosigns) long ' Put the length of YOUR message in place of the 18 in the line above '************************************************************************************** K=J-1 'adjust for using in the Lookup command '************************************************************************************** Lookup K,(136,136,136,255,102,190,98,32,137,180,129,255,32,67,188,188,255,170),Mchar ' MESSAGE = 'VVV W1REX/B EM22 AR' ' Put YOUR MESSAGE in the above line in place of the 144,144,....170 '************************************************************************************** Gosub Didah 'Send the character Next J 'Next character Pause Time2 'Pause Time2 milliseconds before continuing Goto BCON 'Start all over again Didah:If Mchar<252 then Reg '"Regular" character or 'weird prosign'??? Weird:If Mchar=255 then Spc 'pause only Prop: Low Keypin 'Key the transmitter Sound PZOpin,(Freq,Ditlen) 'Send an A High Keypin 'Turn OFF the LEDs Sound PZOpin,(0,Ditlen) 'Silence for the proper inter-element time Send=3*Ditlen 'prep for a dah Low Keypin 'Key the transmitter Sound PZOpin,(Freq,Send) 'Sidetone for the proper element time High Keypin 'Turn OFF the LEDs Sound PZOpin,(0,Ditlen) 'Silence for the proper inter-element time Mchar=Mchar+1 'a little Tom-foolery If Mchar<255 then Prop 'send 3 A's with no inter-character time for a '.' Goto Move 'move on now... Spc: Send=3*Ditlen 'make an inter-character time delay Sound PZOpin,(0,Send) 'just a pause (no sound for 3 times dit length) Goto Move Reg: Numdit= Mchar & %11100000 'Break off the top 3 bits of the Morse character Numdit=Numdit /32 -1 'Fix them as 0 to 7 for number of elements -1 (adjusted for Lookup command) Ditdat=Mchar & %00011111 'Break off the lower 5 bits which are element data For I=0 to Numdit 'Loop through flash routine for # of elements times Lookup I,(1,2,4,8,16),Mask 'Make masks to mask off the lower 5 bits 1 bit at a time Send=Ditlen 'Element time starts out as a Dit K=Ditdat & Mask 'Mask off the proper bit in the character sequence If K =0 Then Flash 'Is the bit a zero? Then the Element time is OK... Got1: Send=3*Ditlen 'Bit is a 1 so element is a dash, element time = 3 * Dit Flash:Low Keypin 'Key the transmitter Sound PZOpin,(Freq,Send) 'Sidetone for the proper element time High Keypin 'Turn OFF the LEDs Sound PZOpin,(0,Ditlen) 'Silence for the proper inter-element time Move: Next I 'Next element Send=3*Ditlen Sound PZOpin,(0,Send) 'Silence for the inter-character time Return 'Done sending character ;MUX SWITCH INPUT ; This subroutine reads an analog voltage on logical pin 2. ; The 4 MUX DIP switches are used to create an analog voltage ; based on which switch is closed. Each switch controls a weighted ; resistor to create 4 unique voltage readings for the 4 switches. ; The max reading is 255 (8 bits) so dividing the reading by 52 ; will produce a whole number between 0 and 4 based on which switch ; is closed... MUX: ReadADC 2,AD 'read the MUXed switch voltage (8 bits) OPT = AD/52 'normalize it to 5 readings Return 'we are done!