' ============================================================================ ' TR1_input_test.bas ' TR1 input test using Proton Basic ' This program performs the following tests... ' Loop forever blinking the ststus LED ' When input 1, 2 or 3 is pulled to ground, the corresponding ' output 1, 2 or 3 LED will light. ' ============================================================================ ' ============================================================================ ' 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 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 ADCON1 = %00001011 ' Value=11 - Set AN0-AN3 to analog, the rest to digital PORTB_PULLUPS = On Declare ADIN_RES 10 ' Set A/D converter to 10 bit resolution Declare ADIN_TAD 32_fosc ' adin_tad = ' Set A/D converter oscillator (FRC = RC) ' adin_delay = 50 ' Set A/D converter sample time to 50 uS ' ============================================================================ ' DEFINE PHYSICAL IO PINS SYMBOL NAMES Symbol status_led = PORTC.1 : TRISC.1 = 0 ' System status LED Symbol in1 = PORTA.5 : TRISA.5 = 1 ' Primary trigger input Symbol in2 = PORTB.3 : TRISB.3 = 1 Symbol in3 = PORTB.4 : TRISB.4 = 1 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 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 net_assert = PORTC.0 : TRISC.0 = 0 ' OC transistor output to assert net traffic Symbol net_cd = PORTC.3 : TRISC.3 = 1 ' Network carrier detect - 0 = traffic present Symbol pwm_pin = PORTC.2 : TRISC.2 = 0 ' PWM Output, analog conn pin 1 ' ============================================================================ ' DEFINE VARIABLES Dim i As Byte Dim x As Byte Dim slower As Byte Dim faster As Byte Dim loop_count As Word Dim loop_delay As Byte Dim msg As String * 128 ' ============================================================================ ' INITIALIZE VARIABLES loop_count = 0 loop_delay = 50 slower = 200 faster = 10 ' ============================================================================ ' INITIALIZATION CODE GoSub force_outputs_off ' Turn off all outputs ' ============================================================================ ' =====[ MAIN PROGRAM LOOP ]================================================== ' ============================================================================ main_loop: ' ---------------------------------------------------------------------------- Low status_led DelayMS 50 High status_led DelayMS 50 ' ---------------------------------------------------------------------------- ' Test inputs to see if any have triggered If in1 = 0 Then Low out1 If in1 = 1 Then High out1 If in2 = 0 Then Low out2 If in2 = 1 Then High out2 If in3 = 0 Then Low out3 If in3 = 1 Then High out3 ' ---------------------------------------------------------------------------- GoTo main_loop ' Go to the top of the loop ' ============================================================================ ' ============================================================================ ' ============================================================================ ' =====[ SUBROUTINES ]======================================================== ' ============================================================================ ' Subroutine to force all 5 outputs off force_outputs_off: Low out1 Low out2 Low out3 Low out4 Low out5 Return ' ============================================================================ ' ============================================================================