The next program blinks a LED which is connected to pin A0 and (via a suitable resistor) to either Gnd or Vcc.
example 1  -- flash a LED on pin A0  include 16f84_10  include jlib  pin_a0_direction = output  forever loop  pin_a0 = on  delay_1s  pin_a0 = off  delay_1s  end loop
 Jal is a free format language. The end of a line has no special meaning, except that it terminates a comment. A comment starts with two dashes. The numbers  etc. are for reference only and are not part of the program!
 The target is a 16f84 with a 10MHz crystal.
 The jlib standard library is included.
 On power-up all pins are in the input (high impedance) state. This statement makes pin A0 an output.
 The main part of the program is an endless loop.
 Pin A0 is set high. High and on are synonyms for true. likewise low and off are synonyms for false. Output and input are declared in jlib. The jlib output routines use a port buffer to avoid the read-modify-write problem inherent to the PIC architecture.
 This call causes a busy delay of 1 second. Related calls exist for delays of (multiples of) 100mS, 10mS, 1mS and 100uS. The argument to the delay calls is a byte, so the range is 0..255. All calculations in jal are modulo calculations. For a byte this means that a specified value will silently be interpreted modulo 256. The default argument is 1, so the statement causes a delay of 1 second.
The various delay routines are the main reason that the target's clock frequency must be specified. If we had included 16f84_4 while using a 10MHz clock the actual delay would have been 2.5 seconds.
 Pin A0 is set low.
 Same call as in line : a one second delay.
 This line indicates the end of the loop which was started in line .
The next program shows night-rider style LED display on port B.
example 2 [ 1] include 16f84_10 [ 2] include jlib [ 3] [ 4] -- night-rider LED display on port B [ 5] const bit to_right = 1 [ 6] const bit to_left = 0 [ 7] [ 8] procedure night( byte in out x, bit in out direction ) is [ 9] if ( x & 0b_1000_0000 ) != 0 then  direction = to_right  end if  if ( x & 0b_0000_0001 ) != 0 then  direction = to_left  end if   if direction == to_right then  x = x >> 1  else  x = x << 1  end if  end procedure   b_direction = all_output  var byte x = 0b_0000_0001  var bit d = to_left   forever loop  port_b = x  delay_100ms( 2 )  night( x, d )  end loop
 Jal does not support enumerates, so two constants of type bit are used to identify the current direction in which the LED pattern moves.
 The procedure night is declared which has two input-output parameters: the display and the current shift direction. Input-output parameters are copied to and from the actuals both before and after the procedure is executed. Input-only parameters are copied only before, and output-only parameters are copied only after the execution of the procedure.
[9,16] If the current display value has hit the left or right border the current shift direction is updated. The display value is AND-ed with 0b_000_0001 to detect a collision with the right border and with 0b_1000_0000 to detect a collision with the left border. The prefix 0b indicates a base-2 (binary) value. Other prefixes are 0h or 0x for hexadecimal and 0d (which is the default) for decimal. Underscores within a literal are ignored by the compiler but can be used to improve the readability.
 Depending on the current direction the display value is shifted one position to the right or to the left.
 This statement switches all pins of port B to output. All_output is decleared in jlib.
 The initial value of the display is 0b_0000_0001. A value of 0b_0000_0101 or 0b_0000_1111 would also produce a nice display.
 The initial direction is set to to_left. This could be omitted because the initial value of x cause the direction to be set immediatley.
 The infinite loop updates the PORT B value, waits 200 mS and calls the procedure night to calculate the next display value and possibly update the direction.
 For active-low LEDs this line could be changed to invert the x value before assigning it to port_b:
 port_b = x ^ 0x0FF
The next program controls a simple line-following robot which consists of two four-phase stepper motors and two reflective IR sensors. The robot follows a black line on a white background by stepping each motor only when the associated sensor sees white.
example 3 [ 1] -- A line following robot: [ 2] -- port B drives two 4-phase stepper motors via an ULN2803. [ 3] -- a0 and a1 are connected to 2 white-is-low reflective sensors. [ 4] -- a2 and a3 drive 2 LEDs which show the state of the sensor inputs. [ 5] [ 6] include 16f84_10 [ 7] include jlib [ 8] [ 9] port_b_direction = all_output  pin_a0_direction = input  pin_a1_direction = input  pin_a2_direction = output  pin_a3_direction = output   procedure steppers( byte in a, b ) is  port_b = a + ( b < < 4 )  delay_1mS( 10 )  end procedure   var byte left_stepper = 0b_0001  var byte right_stepper = 0b_0001   forever loop  pin_a2 = pin_a0  pin_a3 = pin_a1   if ! pin_a0 then  stepper_motor_half_forward( right_stepper )  end if  if ! pin_a1 then  stepper_motor_half_forward( left_stepper )  end if   steppers( left_stepper, right_stepper )  end loop
 The procedure Steppers is declared which has two input-only parameters.
 Port B is set to the appropriate value for driving the one stepper motor from pins B0 .. B3 and the other one from pins B4 .. B7.
 This delay between each step is appropriate for the stepper motors used in older 5-1/4 inch diskdrives. The argument to the delay is a byte, so it must be in the range 0 .. 255.
 Two variables are declared to hold the current steering value for each stepper motor. The initial values for both motors is 0b_0001.
 The indicator LEDs are set according to the values of the sensor inputs.
 Each stepper motor value is advanced one (half) step only when the associated sensor input is low. The procedure Stepper_Motor_Half_Forward is declared in jlib. Alterantively Stepper_Motor_Full_Forward could be used. Note that jal is not case sensitive.
 The Steppers procedure is called to provide the new steering to the motors and wait the appropriate time before the next step.
The next program reads the temperature from an LM75 using the i2c protocol, and writes the result to an LCD controlled by a Hitachi HD44780.
example 4 [ 1] -- a temperature display using [ 2] -- an LM75 and a HD44780 LCD controller [ 3] [ 4] include 16c84_10 [ 5] include jlib [ 6] include lm75 [ 7] include hd447804 [ 8] [ 9] const lm75_address = 0   hd44780_clear   forever loop   var byte t, d  var bit f   lm75_read_fdt( lm75_address, f, d, t )   hd44780_line1  if f then  hd44780 = "-"  else  hd44780 = "+"  end if  print_decimal_2( hd44780, d, " " )  hd44780 = "."  print_decimal_1( hd44780, t, "0" )   delay_200mS   end loop
[6,7] The i2c and hd447804 libraries must be included explicitly because they are not part of jlib. Refer to the i2cp and hd44780p library files for the IO pin assignments used. When your target circuit uses different IO pins you should make a local copy of these files and edit that copy.
 This constant defines the 3-bit i2c address of the LM75 as configured by the LM75's A0 A1 and A2 pins. The LM75 routines will set the higher bits of the address (0b_1001 for an LM75).
 The LCD display is cleared.
[15,16] The variables for reading the LM75 are declared. It is a good idea to declare variables within smallest possible scope.
 The LM75 is read.
 The cursor in the HD44780 is put back to the first position. Using HD44780_clear at this point would cause some flickering of the display.
 First the sign is written. HD44780 is a pseudo-variable: each assignment to this variable invokes a procedure which writes the value to the display and advances the cursor.
 The temperature is written using the print_decimal_2 procedure. The HD44780 pseudo-variable is passed as destination of the formatted string. The second argument is the value to be written. The last argument is the ASCII value to use for leading zero's. Here we supply a space.
[27,28] After the decimal point the tenth degree value is printed. Print_decimal_1 is used which prints only one digit. A "0" is supplied for leading zero's, so either "0" or "5" is printed.
 A little delay is inserted to limit the update speed.