# ############################################################################# # # Copyright (c) 2002 by Wayne C. Gramlich and Bill Benson # All rights reserved. # # Permission to use, copy, modify, distribute, and sell this software # for any purpose is hereby granted without fee provided that the above # copyright notice and this permission are retained. The author makes # no representations about the suitability of this software for any purpose. # It is provided "as is" without express or implied warranty. # # This is the code that implements the LED10 RoboBrick. Basically # it just waits for commands that come in at 2400 baud and responds # to them. See # # http://web.gramlich.net/projects/robobricks/led10/index.html # # for more details. # # ############################################################################# processor pic16c505 cp=off wdte=on mclre=off fosc=intrc_no_clock # Define processor constants: constant clock_rate 4000000 constant clocks_per_instruction 4 constant instruction_rate clock_rate / clocks_per_instruction # Define serial communication control constants: constant baud_rate 2400 constant instructions_per_bit instruction_rate / baud_rate constant delays_per_bit 3 constant instructions_per_delay instructions_per_bit / delays_per_bit constant extra_instructions_per_bit 9 constant extra_instructions_per_delay extra_instructions_per_bit / delays_per_bit constant delay_instructions instructions_per_delay - extra_instructions_per_delay # Register definitions: # Status register: register status 3 bind c status@0 bind z status@2 # OSCCAL register: register osccal 5 constant osccal_lsb 4 # Define pin assignments and directions: constant led0_bit 5 constant led1_bit 0 constant led2_bit 1 constant led3_bit 2 constant led4_bit 0 constant led5_bit 1 constant led6_bit 3 constant led7_bit 4 constant led8_bit 4 constant mode_bit 5 constant serial_out_bit 2 constant serial_in_bit 3 constant led0_mask (1 << led0_bit) constant led1_mask (1 << led1_bit) constant led2_mask (1 << led2_bit) constant led3_mask (1 << led3_bit) constant led4_mask (1 << led4_bit) constant led5_mask (1 << led5_bit) constant led6_mask (1 << led6_bit) constant led7_mask (1 << led7_bit) constant led8_mask (1 << led8_bit) port portb b bits_and_byte read_write_static port portc c bits_and_byte write_only pin led0 portb led0_bit write_only pin led1 portb led1_bit write_only pin led2 portb led2_bit write_only pin led3 portc led3_bit write_only pin led4 portc led4_bit write_only pin led5 portc led5_bit write_only pin led6 portc led6_bit write_only pin led7 portb led7_bit write_only pin led8 portc led8_bit write_only pin mode portc mode_bit read_only pin serial_out portb serial_out_bit write_only pin serial_in portb serial_in_bit read_only global b_on byte global c_on byte global b_off byte global c_off byte procedure main { arguments_none returns_nothing variable command byte variable glitch byte variable index byte variable count1 byte variable count2 byte loop_forever { # Strobe the LED's for 600uS at 40kHz: count_down count1 20 { portb := 0xff portc := 0xff nop (13 - 4) portb := 0 portc := 0 nop (12 - 2 - 3) } # Leave everything off for 100mS: count_down count2 200 { count_down count1 20 { nop (25 - 3) } } } }