' BEACON6.BAS PIC16F628 Freakin' Beacon Project ' PicBasic Pro Compiler ' William Coleman Consulting ' ' 09/25/02 BEACON1: Initial programming with canned message in EEPROM. ' 09/26/02 Added characters and commands. ' 09/27/02 Added serial programming input, CW tone feedback. ' 10/04/02 BEACON2: Upgraded to 16F628 processor. ' Uncommented character echo and commands that ' wouldn't fit in 16F84. ' 10/19/02 Program input being ignored... Added command to ' place PORTA inputs in Digital mode, not Analog mode. ' 02/15/03 BEACON3: Modified to generate tone during T, S, and F while keyed. ' Set High power as default. ' 03/29/03 BEACON4: Corrected bug affecting message length: changed playback ' pointer test from 64 to 127 to match record pointer. ' 05/22/03 BEACON5: Added echo function to list present message to terminal ' at power up if programming jumper is installed. ' Added O command for One minute delay. ' Added V command for Very long delay (10 minutes). ' Added N command to Null V command. ' Added @ character .--.- for email addresses. ' * Note: sound statements could be replaced with freqout statements to ' get finer code speed resolution. ' 12/08/03 BEACON6: Added QRSS modes ' A=QRSS60, B=QRSS30, C=QRSS10, D=QRSS3, E=QRSS1. ' Added R command for qRss mode. Enters QRSS mode. Speed per QRSS A-E. ' Added I command to Inhibit QRSS mode. ' ' Configure PORTA as Digital Inputs, not Analog Inputs CMCON = 7 ' Configure RA0 & RA1 as Outputs ' Configure RA2-RA4 as Inputs TRISA = %00011100 ' Configure RB0-RB7 as Outputs TRISB = %00000000 ' Assign names to pins trigger var PORTA.2 ' Ground to trigger message program var PORTA.3 ' Ground to enter program mode Serial_in var PORTA.4 ' Serial input for programming PTT var PORTB.0 ' PTT output, active high Key var PORTB.1 ' Key output, active high Serial_out var PORTB.2 ' Serial output for programming Sidetone var PORTB.3 ' Sidetone output EL_pwr var PORTB.4 ' Extra low power, active high Low_pwr var PORTB.5 ' Low power, active high Med_pwr var PORTB.6 ' Medium power, active high High_pwr var PORTB.7 ' High power, active high ' Initialize variables to default states element var word ' Was byte. Changed to word when QRSS added. element = 60 ' element time = 60 ms (20.8 WPM) dittime var byte dittime = 5 ' dittime = 60 ms (20.8 WPM) dahtime var byte dahtime = 15 ' dahtime = 180 ms (20.8 WPM) QRSS var byte QRSS = 3 ' QRSS = 3 (3 second dit) pointer var byte command var byte verify var byte newchar var byte Keyflag var byte Nullflag var byte Nullflag = 0 QRSSflag var byte QRSSflag = 0 verylong var byte onemin var byte X var byte ' Initialize EEPROM with test message Data "P","S","D","v","v","v","S","Q","S","Z" Start: if program = 1 then goto main serout serial_out,6,[13,10] pointer=0 loopecho: Read pointer, command serout serial_out,6,[command] pointer = pointer + 1 if pointer = 127 then goto doneecho if command = "Z" then goto doneecho goto loopecho doneecho: serout serial_out,6,[13,10] serout serial_out,6,[13,10,"Change program? y/n",13,10] gosub send_y gosub question serin serial_in,6,10000,Main,verify if verify != "y" then goto main serout serial_out,6,[13,10,"Enter new program followed by Z.",13,10] gosub send_o gosub send_k pointer = 0 prog: serin serial_in,6,newchar write pointer,newchar serout serial_out,6,[newchar] if newchar = "Z" then goto main pointer = pointer + 1 if pointer = 127 then goto main goto prog ' Main loop Main: gosub HighP ' High power is default gosub Keyup ' Ensure unkeyed, key flag cleared pointer = 0 Loop: Read pointer, command if command = "a" then gosub send_a if command = "b" then gosub send_b if command = "c" then gosub send_c if command = "d" then gosub send_d if command = "e" then gosub send_e if command = "f" then gosub send_f if command = "g" then gosub send_g if command = "h" then gosub send_h if command = "i" then gosub send_i if command = "j" then gosub send_j if command = "k" then gosub send_k if command = "l" then gosub send_l if command = "m" then gosub send_m if command = "n" then gosub send_n if command = "o" then gosub send_o if command = "p" then gosub send_p if command = "q" then gosub send_q if command = "r" then gosub send_r if command = "s" then gosub send_s if command = "t" then gosub send_t if command = "u" then gosub send_u if command = "v" then gosub send_v if command = "w" then gosub send_w if command = "x" then gosub send_x if command = "y" then gosub send_y if command = "z" then gosub send_z if command = "1" then gosub send_1 if command = "2" then gosub send_2 if command = "3" then gosub send_3 if command = "4" then gosub send_4 if command = "5" then gosub send_5 if command = "6" then gosub send_6 if command = "7" then gosub send_7 if command = "8" then gosub send_8 if command = "9" then gosub send_9 if command = "0" then gosub send_0 if command = " " then gosub space if command = "/" then gosub slash if command = "." then gosub period if command = "," then gosub comma if command = "?" then gosub question if command = "=" then gosub BT if command = "+" then gosub AR if command = "&" then gosub AS if command = "(" then gosub KN if command = "*" then gosub SK if command = "@" then gosub AT if command = "A" then gosub WPM5 if command = "B" then gosub WPM10 if command = "C" then gosub WPM15 if command = "D" then gosub WPM21 if command = "E" then gosub WPM52 if command = "F" then gosub Five if command = "H" then gosub HighP if command = "I" then gosub QRSSoff ' Inhibit QRSS, use normal speed if command = "K" then gosub Keydown if command = "L" then gosub LowP if command = "M" then gosub MediumP if command = "N" then gosub Null ' Null Very command if command = "O" then gosub One ' One minute delay if command = "P" then gosub PTTon if command = "Q" then gosub PTToff if command = "R" then gosub QRSSon if command = "S" then gosub Second if command = "T" then gosub Tenth if command = "U" then gosub Keyup if command = "V" then gosub Very ' Very long delay (10 minutes) if command = "W" then gosub WaitTrig if command = "X" then gosub ExtraP if command = "Z" then goto main pointer = pointer + 1 if pointer = 127 then goto main Goto Loop send_a: gosub dit gosub dah pause element pause element return send_b: gosub dah gosub dit gosub dit gosub dit pause element pause element return send_c: gosub dah gosub dit gosub dah gosub dit pause element pause element return send_d: gosub dah gosub dit gosub dit pause element pause element return send_e: gosub dit pause element pause element return send_f: gosub dit gosub dit gosub dah gosub dit pause element pause element return send_g: gosub dah gosub dah gosub dit pause element pause element return send_h: gosub dit gosub dit gosub dit gosub dit pause element pause element return send_i: gosub dit gosub dit pause element pause element return send_j: gosub dit gosub dah gosub dah gosub dah pause element pause element return send_k: gosub dah gosub dit gosub dah pause element pause element return send_l: gosub dit gosub dah gosub dit gosub dit pause element pause element return send_m: gosub dah gosub dah pause element pause element return send_n: gosub dah gosub dit pause element pause element return send_o: gosub dah gosub dah gosub dah pause element pause element return send_p: gosub dit gosub dah gosub dah gosub dit pause element pause element return send_q: gosub dah gosub dah gosub dit gosub dah pause element pause element return send_r: gosub dit gosub dah gosub dit pause element pause element return send_s: gosub dit gosub dit gosub dit pause element pause element return send_t: gosub dah pause element pause element return send_u: gosub dit gosub dit gosub dah pause element pause element return send_v: gosub dit gosub dit gosub dit gosub dah pause element pause element return send_w: gosub dit gosub dah gosub dah pause element pause element return send_x: gosub dah gosub dit gosub dit gosub dah pause element pause element return send_y: gosub dah gosub dit gosub dah gosub dah pause element pause element return send_z: gosub dah gosub dah gosub dit gosub dit pause element pause element return send_1: gosub dit gosub dah gosub dah gosub dah gosub dah pause element pause element return send_2: gosub dit gosub dit gosub dah gosub dah gosub dah pause element pause element return send_3: gosub dit gosub dit gosub dit gosub dah gosub dah pause element pause element return send_4: gosub dit gosub dit gosub dit gosub dit gosub dah pause element pause element return send_5: gosub dit gosub dit gosub dit gosub dit gosub dit pause element pause element return send_6: gosub dah gosub dit gosub dit gosub dit gosub dit pause element pause element return send_7: gosub dah gosub dah gosub dit gosub dit gosub dit pause element pause element return send_8: gosub dah gosub dah gosub dah gosub dit gosub dit pause element pause element return send_9: gosub dah gosub dah gosub dah gosub dah gosub dit pause element pause element return send_0: gosub dah gosub dah gosub dah gosub dah gosub dah pause element pause element return slash: gosub dah gosub dit gosub dit gosub dah gosub dit pause element pause element return period: gosub dit gosub dah gosub dit gosub dah gosub dit gosub dah pause element pause element return comma: gosub dah gosub dah gosub dit gosub dit gosub dah gosub dah pause element pause element return question: gosub dit gosub dit gosub dah gosub dah gosub dit gosub dit pause element pause element return BT: gosub dah gosub dit gosub dit gosub dit gosub dah pause element pause element return AR: gosub dit gosub dah gosub dit gosub dah gosub dit pause element pause element return AS: gosub dit gosub dah gosub dit gosub dit gosub dit pause element pause element return KN: gosub dah gosub dit gosub dah gosub dah gosub dit pause element pause element return SK: gosub dit gosub dit gosub dit gosub dah gosub dit gosub dah pause element pause element return AT: gosub dit ' @ symbol for email address gosub dah gosub dah gosub dit gosub dah pause element pause element return Dit: if QRSSflag = 1 then goto QRSSdit Key = 1 sound sidetone,[110,dittime] Key = 0 pause element Return QRSSdit: Key = 1 for X = 1 to QRSS sound sidetone,[110,83] ' 1 second next X Key = 0 pause element Return Dah: if QRSSflag = 1 then goto QRSSdah Key = 1 sound sidetone,[110,dahtime] Key = 0 pause element Return QRSSdah: Key = 1 for X = 1 to QRSS sound sidetone,[110,250] ' 3 seconds next X Key = 0 pause element Return Space: pause element pause element pause element Return WPM5: element = 250 ' A dittime = 21 dahtime = 63 QRSS = 60 if QRSSflag = 1 then element = 60000 return WPM10: element = 120 ' B dittime = 10 dahtime = 30 QRSS = 30 if QRSSflag = 1 then element = 30000 return WPM15: element = 84 ' C dittime = 7 dahtime = 21 QRSS = 10 if QRSSflag = 1 then element = 10000 return WPM21: element = 60 ' D dittime = 5 dahtime = 15 QRSS = 3 if QRSSflag = 1 then element = 3000 return WPM52: element = 24 ' E dittime = 2 dahtime = 6 QRSS = 1 if QRSSflag = 1 then element = 1000 return HighP: High_pwr = 1 ' H Med_pwr = 0 Low_pwr = 0 EL_pwr = 0 return MediumP: High_pwr = 0 ' M Med_pwr = 1 Low_pwr = 0 EL_pwr = 0 return LowP: High_pwr = 0 ' L Med_pwr = 0 Low_pwr = 1 EL_pwr = 0 return ExtraP: High_pwr = 0 ' X Med_pwr = 0 Low_pwr = 0 EL_pwr = 1 return WaitTrig: if trigger = 1 then goto WaitTrig ' W return Keydown: Key = 1 ' K Keyflag = 1 ' used to enable SOUND during T, S, & F Return Keyup: Key = 0 ' U Keyflag = 0 ' used to disable SOUND during T, S, & F Return Very: if Nullflag = 0 then ' Skip if Null command has been executed for verylong = 1 to 10 ' 10 minute delay gosub One next verylong endif return Null: Nullflag = 1 return One: for onemin = 1 to 12 gosub Five next onemin return Five: if Keyflag = 1 then sound sidetone, [110,208]' keyed so sidetone for (208+209)*12ms sound sidetone, [110,209]' or 5004ms else pause 5000 ' F Hold 5 seconds endif return Second: if Keyflag = 1 then sound sidetone, [110,83] ' keyed so sidetone for 83*12ms = 996ms else pause 1000 ' S Hold 1 second endif Return Tenth: if Keyflag = 1 then sound sidetone, [110,8] ' keyed so sidetone for 8*12ms = 96ms else pause 100 ' T Hold 0.1 seconds endif Return PTTon: PTT = 1 ' P Return PTToff: PTT = 0 ' Q Return QRSSon: QRSSflag = 1 ' R if element = 250 then element = 60000 if element = 120 then element = 30000 if element = 84 then element = 10000 if element = 60 then element = 3000 if element = 24 then element = 1000 Return QRSSoff: QRSSflag = 0 ' I if element = 60000 then element = 250 if element = 30000 then element = 120 if element = 10000 then element = 84 if element = 3000 then element = 60 if element = 1000 then element = 24 Return END