ucl 2.0 # Copyright (c) 2005-2008 by Wayne C. Gramlich # All rights reserved. # This module uses a PIC16F688: library $pic16f688 # The system is running at 20MHz: library clock20mhz # A microsecond takes 5 cycles at 20MHz: constant microsecond = 5 # The {$eusart} library defines some baud rate generator constants: constant $eusart_clock = clock_rate constant $eusart_factor = 4 library $eusart # The library of bus access routines for use by a PIC16F688. library rb2bus_pic16f688 # This module uses 20MHz crystal oscillator; hence mode EC=External Clock: configure fosc=hs # All pins on this package are used except RA3. package pdip pin 1 = power_supply pin 2 = osc1 pin 3 = ra4_nc pin 4 = ra3_nc, name=nc1 pin 5 = rx, name=rx, bit=rx_bit pin 6 = tx, name=tx, bit=tx_bit pin 7 = rc3_nc pin 8 = rc2_in, name=in3, mask=in3_mask, bit=in3_bit # N5 pin 9 = rc1_in, name=in2, mask=in2_mask, bit=in2_bit # N4 pin 10 = rc0_in, name=in1, mask=in1_mask, bit=in1_bit # N3 pin 11 = ra2_in, name=in0, mask=in0_mask, bit=in0_bit # N2 pin 12 = ra1_nc pin 13 = ra0_nc pin 14 = ground origin 0 procedure main arguments_none returns_nothing # This procedure initializes everything and does command decoding. local command byte local result byte local mask byte call rb2bus_initialize(19) mask := 0xf loop_forever # Make sure that we have been selected: rb2bus_error := $true while rb2bus_error call rb2bus_select_wait() command := rb2bus_byte_get() switch command >> 6 case 0 # 00xx xxxx: switch (command >> 3) & 7 case 0 # 0000 0xxx: switch command & 7 case 0 # 0000 0000 (Proximity Get): result := 0 if in0 result@0 := $true if in1 result@1 := $true if in2 result@2 := $true if in3 result@3 := $true result := result & mask call rb2bus_byte_put(result) case 1 # 0000 0001 (Mask Set): mask := rb2bus_byte_get() case 2 # 0000 0010 (Mask Get): call rb2bus_byte_put(mask) case_maximum 7 case_maximum 7 case 3 # 11xx xxxx: switch (command >> 3) & 7 case 7 # 1111 1xxx: call rb2bus_command(command) procedure wait arguments_none returns_nothing # This procedure is repeatably called whenever the software # is waiting for a byte to arrive from the bus. do_nothing string id = "\16,0,19,1,3,13\IRProximity-4\7\Gramson"