-- Include standard libraries include f628_4i include jlib var volatile byte CMCON at 0x1F = 0x07 -- disable port a analog functions -- This program assumes the following: -- 8 LED's connected to port B and to +5V (PIC must drive output low to turn LED on) -- 4 Switches connected to port A, pulled high (Switch grounds PIN when closed) -- Declare LED variables on port B var bit LED1 is pin_b0 var bit LED2 is pin_b1 var bit LED3 is pin_b2 var bit LED4 is pin_b3 var bit LED5 is pin_b4 var bit LED6 is pin_b5 var bit LED7 is pin_b6 var bit LED8 is pin_b7 -- Declare SWITCH variables on port A var bit SWITCH1 is pin_a0 var bit SWITCH2 is pin_a1 var bit SWITCH3 is pin_a2 var bit SWITCH4 is pin_a3 -- Set Pin direction pin_b0_direction = output pin_b1_direction = output pin_b2_direction = output pin_b3_direction = output pin_b4_direction = output pin_b5_direction = output pin_b6_direction = output pin_b7_direction = output pin_a0_direction = input pin_a1_direction = input pin_a2_direction = input pin_a3_direction = input -- Declare variables, set default values var bit count_direction = true var byte delay = 3 var byte counter = 0 -- The main loop forever loop -- Delay delay_100ms( delay ) -- Increment or decrement counter variable depending on current direction if (count_direction == true) then counter = counter + 1 else counter = counter - 1 end if -- Write counter value out to Port B port_b = counter -- Read switches if (SWITCH1 == low) then -- Change delay to 500 ms delay = 5 elsif (SWITCH2 == low) then -- Change delay to 100 ms delay = 1 end if if (SWITCH3 == low) then -- Change direction count_direction = true elsif (SWITCH4 == low) then -- Change direction count_direction = false end if end loop