' ============================================================================ ' TR1 Board Example - Send CW ' ============================================================================ ' === HARDWARE PARAMETERS ==================================================== Device 18F2620 XTAL = 40 ' ==== 18F2620 CONFIGURATION FUSES =========================================== CONFIG_START OSC = HSPLL ' 4x PLL Oscillator IESO = On ' Int/Ext Oscillator Switch Over Disabled PWRT = On ' Power Up Timer Enabled BOREN = On ' Brownout Reset Enabled WDT = On ' Watchdog Timer Enabled WDTPS = 128 ' Watchdog Postscaler: 1:128 MCLRE = On ' External MCLR enabled STVREN = On ' Stack Overflow Reset Enabled LVP = OFF ' Low Voltage ICSP Disabled Debug = OFF ' Background Debugger Disabled PBADEN = OFF ' Port B ADC functions Disabled CP0 = OFF ' Code Protection Block 0 Disabled CP1 = OFF ' Code Protection Block 1 Disabled CPB = OFF ' Boot Block Code Protection Disabled CPD = OFF ' Data EEPROM Code Protection Disabled WRT0 = OFF ' Write Protection Block 0 Disabled WRT1 = OFF ' Write Protection Block 1Disabled WRTB = OFF ' Boot Block Write Protection Disabled WRTC = OFF ' Configuration Register Write Protection Disabled WRTD = OFF ' Data EEPROM Write Protection Disabled EBTR0 = OFF ' Table Read Protection Block 0 Disabled EBTR1 = OFF ' Table Read Protection Block 1 Disabled EBTRB = OFF ' Boot Block Table Read Protection Disabled CONFIG_END ' ============================================================================ ' ============================================================================ ' DEFINE PHYSICAL IO PINS SYMBOL NAMES Symbol ad0_pin = PORTA.0 : TRISA.0 = 1 ' Analog Input, analog conn pin 6 Symbol ad1_pin = PORTA.1 : TRISA.1 = 1 ' Analog Input, analog conn pin 5 Symbol ad2_pin = PORTA.2 : TRISA.2 = 1 ' Analog Input, analog conn pin 4 Symbol ad3_pin = PORTA.3 : TRISA.3 = 1 ' Analog Input, analog conn pin 3 Symbol lcd_out = PORTA.4 : TRISA.4 = 0 ' LCD serial output Symbol key_in = PORTA.5 : TRISA.5 = 1 ' Primary trigger input Symbol net_assert = PORTC.0 : TRISC.0 = 0 ' OC transistor output to assert net traffic Symbol status_led = PORTC.1 : TRISC.1 = 0 ' System status LED Symbol pwm_pin = PORTC.2 : TRISC.2 = 0 ' PWM Output, analog conn pin 1 Symbol net_cd = PORTC.3 : TRISC.3 = 1 ' Network carrier detect - 0 = traffic present Symbol out1 = PORTC.4 : TRISC.4 = 0 Symbol out2 = PORTC.5 : TRISC.5 = 0 Symbol out3 = PORTB.0 : TRISB.0 = 0 Symbol out4 = PORTB.1 : TRISB.1 = 0 Symbol out5 = PORTB.2 : TRISB.2 = 0 Symbol ptt_in = PORTB.3 : TRISB.3 = 1 Symbol inhibit_in = PORTB.4 : TRISB.4 = 1 ' ============================================================================ ' ============================================================================ DelayMS 100 ' IMMEDIATELY JAM ALL OUTPUTS TO THE OFF STATE Low out1 Low out2 Low out3 Low out4 Low out5 ' ============================================================================ ' ============================================================================ ' VARIABLE DECLARATION - Application specific vars Dim cw_tone As Word ' CW telemetry tone Dim cw_time As Word ' CW unit time in ms - dit = 1 unit, dah = 3 units Dim cw_wpm As Byte Dim cw_len As Byte Dim cw_string As String * 50 Dim cw_char As String * 1 Dim cw_temp As String * 1 Dim cw_bits As String * 5 Dim i As Byte Dim x As Byte Dim y As Byte Dim led_off As Bit Dim led_on As Bit ' ============================================================================ ' ============================================================================ ' DEFINE PIC HW REGISTER CONFIGURATION PARAMETERS ADCON1 = %00001011 ' Value=11 - Set AN0-AN3 to analog, the rest to digital PORTB_PULLUPS = On ' ============================================================================ ' ============================================================================ ' =========[ STARTUP CODE ]=================================================== ' ============================================================================ ' ============================================================================ cw_string = "CQ CQ CQ DE W6ABC W6ABC W6ABC K" cw_wpm = 15 cw_time = 1200 / cw_wpm ' Approx values of cw_time per WPM speed: 240 = 5 WPM, 92 = 13 WPM, 60 = 20 WPM cw_tone = 850 led_on = 0 led_off = 1 status_led = led_off ' --------------------------------------------------------------------------- ' ---[ MAIN PROGRAM LOOP ]--------------------------------------------------- ' --------------------------------------------------------------------------- mainloop: If key_in = 1 Then GoSub send_cw GoTo mainloop ' --------------------------------------------------------------------------- ' ---[ CW TELEMETRY ROUTINES ]----------------------------------------------- ' --------------------------------------------------------------------------- send_cw: High status_led cw_len = Len(cw_string) For i = 1 To cw_len cw_char = Mid$(cw_string,i,1) 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 GoSub cw_parse Next i Return ' --------------------------------------- cw_parse: x = Len(cw_bits) For y = 1 To x cw_temp = Mid$(cw_bits,y,1) If cw_temp = "." Then High out5 FreqOut pwm_pin, cw_time, cw_tone Low out5 ElseIf cw_temp = "-" Then High out5 FreqOut pwm_pin, 3*cw_time, cw_tone Low out5 ElseIf cw_temp = " " Then DelayMS 3*cw_time EndIf DelayMS cw_time Next y DelayMS 3*cw_time Return