' ============================================================================ ' TR1_output_test.bas ' TR1 output test using Proton Basic ' This program performs the following tests... ' Send loop number to the serial port at 9600 baud ' Blink status led ' Turn each output on and off in sequence 1-4 and back, 4 times ' Repeat ' ============================================================================ ' ============================================================================ ' DEFINE HARDWARE CONFIGURATION PARAMETERS Device 18F2620 ' Select device type XTAL = 40 ' Set clock frequency to 40 MHz CONFIG_START ' Set hardware configuration parameters OSC = HSPLL ' Set 4x PLL on (10 MHz crystal * 4x = 40 MHz) 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 ' ============================================================================ ' DEFINE PIC HW REGISTER CONFIGURATION PARAMETERS SPBRG = 64 ' Set baud rate to 9600 ' For 9600 baud, 64 for 40 MHz osc, 31 for 20 MHz osc, 15 for 10 MHz osc ' 10 = 57600 (40 MHz osc) ' 32 = 19200 (40 MHz osc) RCSTA = %10010000 ' Enable serial continuous receive TXSTA = %00100000 ' Enable transmit asynchronous mode ' ============================================================================ ' DEFINE VARIABLES Dim i As Byte Dim x As Byte Dim loop_count As Word Dim msg As String * 128 ' ============================================================================ ' INITIALIZE VARIABLES loop_count = 0 ' ============================================================================ ' =====[ MAIN PROGRAM LOOP ]================================================== ' ============================================================================ main_loop: ' ---------------------------------------------------------------------------- ' Send status text out to the serial port loop_count = loop_count + 1 ' Increment the counter msg = "Output test loop # " + Str$(Dec loop_count) ' Build output string HSerOut [msg,13,10] ' Send string to main serial port ' ---------------------------------------------------------------------------- ' Blink status led 5 times For i = 1 To 5 Low status_led ' Set pin C1 low (0 volts) LED on DelayMS 50 ' Delay 200 ms High status_led ' Set pin C1 high (5 volts) LED off DelayMS 50 ' Delay 200 ms Next i ' ---------------------------------------------------------------------------- ' Cycle outputs on and off 4 times GoSub force_outputs_off ' Turn off all outputs i = 45 ' Set time LEDs stay on For x = 1 To 4 ' Set number of loops to 4 High out1 : DelayMS i : Low out1 ' Turn on output, wait i ms, turn off output High out2 : DelayMS i : Low out2 High out3 : DelayMS i : Low out3 High out4 : DelayMS i : Low out4 High out5 : DelayMS i : Low out5 High out4 : DelayMS i : Low out4 High out3 : DelayMS i : Low out3 High out2 : DelayMS i : Low out2 High out1 : DelayMS i : Low out1 Next x GoSub force_outputs_off ' Turn off all outputs ' ---------------------------------------------------------------------------- GoTo main_loop ' Go to the top of the loop ' ============================================================================ ' ============================================================================ ' ============================================================================ ' =====[ SUBROUTINES ]======================================================== ' ============================================================================ ' Subroutine to force all 5 outputs off force_outputs_off: out1 = 0 out2 = 0 out3 = 0 out4 = 0 out5 = 0 Return ' ============================================================================ ' ============================================================================