Hi Matt,

Please create test files to show how a specific library works.
Together with the board files, this will give samples for different
kind of pics. And even when you add a board file, a new sample will be
generated if appropriate.

Joep

2010/2/13  <[email protected]>:
> Revision: 1660
> Author: [email protected]
> Date: Fri Feb 12 22:50:33 2010
> Log: added bit array library + sample
> http://code.google.com/p/jallib/source/detail?r=1660
>
> Added:
>  /trunk/include/jal/bit_array_1.jal
>  /trunk/sample/18f452_bit_array.jal
>
> =======================================
> --- /dev/null
> +++ /trunk/include/jal/bit_array_1.jal  Fri Feb 12 22:50:33 2010
> @@ -0,0 +1,146 @@
> +-- Title: bit array library
> +-- Author: Matthew Schinkel - borntechi.com, copyright (c) 2009, all rights
> reserved.
> +-- Adapted-by:
> +-- Compiler: >=2.4m
> +--
> +-- This file is part of jallib (http://jallib.googlecode.com)
> +-- Released under the ZLIB license
> (http://www.opensource.org/licenses/zlib-license.html)
> +--
> +-- Description: This library creates one bit array up to 2047 bits
> +--
> +-- Sources:
> +--
> +-- notes:
> +-- const dword BIT_ARRAY_1_SIZE = 600   -- choose number of array variables
> +-- include bit_array                    -- include the array library
> +-- alias test is bit_array_1            -- rename/alias the array to test
> +
> +-- create a byte array to hold the bits
> +const byte _bit_array_1_calc1 = BIT_ARRAY_1_SIZE / 8
> +const byte _bit_array_1_calc2 = _bit_array_1_calc1 * 8
> +const byte _bit_array_1_calc3 = BIT_ARRAY_1_SIZE - _bit_array_1_calc1
> +
> +
> +-- this is the byte array that holds the bit array data
> +var byte bit_array_1_byte_array[(BIT_ARRAY_1_SIZE / 8)+ 1]
> +-- the size of the byte array
> +const byte bit_array_1_byte_array_size = (BIT_ARRAY_1_SIZE / 8)+ 1
> +
> +--
> ----------------------------------------------------------------------------
> +-- Writes one bit to the correct byte array (internal use only)
> +--
> ----------------------------------------------------------------------------
> +procedure _bit_array_1_set_byte(word in byte_address, byte in bit_address,
> bit in data) is
> +   var byte holder
> +   holder = bit_array_1_byte_array[byte_address] -- get the byte out of the
> byte array
> +
> +   var bit bit0 at holder : 0   -- get the bits out of the byte
> +   var bit bit1 at holder : 1
> +   var bit bit2 at holder : 2
> +   var bit bit3 at holder : 3
> +   var bit bit4 at holder : 4
> +   var bit bit5 at holder : 5
> +   var bit bit6 at holder : 6
> +   var bit bit7 at holder : 7
> +
> +   if bit_address == 0 then     -- set the correct bit in the byte
> +       bit0 = data
> +   elsif bit_address == 1 then
> +       bit1 = data
> +   elsif bit_address == 2 then
> +       bit2 = data
> +   elsif bit_address == 3 then
> +       bit3 = data
> +   elsif bit_address == 4 then
> +       bit4 = data
> +   elsif bit_address == 5 then
> +       bit5 = data
> +   elsif bit_address == 6 then
> +       bit6 = data
> +   elsif bit_address == 7 then
> +       bit7 = data
> +   end if
> +
> +   bit_array_1_byte_array[byte_address] = holder  -- save the new byte to
> the byte array
> +
> +end procedure
> +
> +--
> ----------------------------------------------------------------------------
> +-- Reads one bit from the correct byte array (internal use only)
> +--
> ----------------------------------------------------------------------------
> +function _bit_array_1_get_byte(word in byte_address, byte in bit_address)
> return bit is
> +   var bit data
> +
> +   var byte holder
> +   holder = bit_array_1_byte_array[byte_address]  -- get the byte out of
> the byte array
> +
> +   var bit bit0 at holder : 0   -- get the bits out of the byte
> +   var bit bit1 at holder : 1
> +   var bit bit2 at holder : 2
> +   var bit bit3 at holder : 3
> +   var bit bit4 at holder : 4
> +   var bit bit5 at holder : 5
> +   var bit bit6 at holder : 6
> +   var bit bit7 at holder : 7
> +
> +   if bit_address == 0 then     -- get the correct bit out of the byte
> +       data = bit0
> +   elsif bit_address == 1 then
> +       data = bit1
> +   elsif bit_address == 2 then
> +       data = bit2
> +   elsif bit_address == 3 then
> +       data = bit3
> +   elsif bit_address == 4 then
> +       data = bit4
> +   elsif bit_address == 5 then
> +       data = bit5
> +   elsif bit_address == 6 then
> +       data = bit6
> +   elsif bit_address == 7 then
> +       data = bit7
> +   end if
> +
> +   return data
> +end function
> +
> +--
> ----------------------------------------------------------------------------
> +-- Write to bit array
> +--
> ----------------------------------------------------------------------------
> +procedure bit_array_1'put(word in address, bit in data) is
> +
> +   var word byte_array_location
> +   var byte bit_location
> +   var word calc_bit_location
> +
> +   -- find the byte location
> +   byte_array_location = address / 8
> +   -- find the bit location
> +   calc_bit_location = address - (byte_array_location * 8)
> +   var byte val[2] at calc_bit_location
> +   bit_location = val[0]
> +   -- write the bit
> +   _bit_array_1_set_byte(byte_array_location, bit_location, data)
> +
> +end procedure
> +
> +--
> ----------------------------------------------------------------------------
> +-- Read from bit array
> +--
> ----------------------------------------------------------------------------
> +function bit_array_1'get(word in address) return bit is
> +   var bit data
> +
> +   var word byte_array_location
> +   var byte bit_location
> +   var word calc_bit_location
> +
> +   -- find the byte location
> +   byte_array_location = address / 8
> +   -- find the bit location
> +   calc_bit_location = address - (byte_array_location * 8)
> +   var byte val[2] at calc_bit_location
> +   bit_location = val[0]
> +   -- write the bit
> +   data = _bit_array_1_get_byte(byte_array_location, bit_location)
> +
> +   return data -- return the bit
> +end function
> =======================================
> --- /dev/null
> +++ /trunk/sample/18f452_bit_array.jal  Fri Feb 12 22:50:33 2010
> @@ -0,0 +1,66 @@
> +-- Title: bit array library
> +-- Author: Matthew Schinkel - borntechi.com, copyright (c) 2009, all rights
> reserved.
> +-- Adapted-by:
> +-- Compiler: >=2.4m
> +--
> +-- This file is part of jallib (http://jallib.googlecode.com)
> +-- Released under the BSD license
> (http://www.opensource.org/licenses/bsd-license.php)
> +--
> +-- Description: This samples shows usage of one bit array up to 2047 bits
> +--
> +-- Sources:
> +--
> +-- notes:
> +-- const dword BIT_ARRAY_1_SIZE = 2047  -- choose number of array variables
> +-- include bit_array_1                  -- include the array library
> +-- alias test is bit_array_1            -- rename/alias the array to test
> +--
> +
> +-- include chip
> +include 18F452                   -- target picmicro
> +
> +-- This program assumes a 20 MHz resonator or crystal
> +-- is connected to pins OSC1 and OSC2.
> +pragma target clock 20_000_000     -- oscillator frequency
> +-- configuration memory settings (fuses)
> +pragma target OSC  HS              -- HS crystal or resonator
> +pragma target WDT  disabled        -- no watchdog
> +pragma target LVP  disabled        -- no Low Voltage Programming
> +
> +enable_digital_io()                -- disable analog I/O (if any)
> +
> +-- setup uart for communication
> +const serial_hw_baudrate  = 115200   -- set the baudrate
> +include serial_hardware
> +serial_hw_init()
> +
> +const dword BIT_ARRAY_1_SIZE = 2047    -- choose number of array variables
> +include bit_array_1                    -- include the array library
> +alias test is bit_array_1              -- rename/alias the array to test
> +
> +;example write bit
> +test[2000] = 1
> +test[2001] = 0
> +test[2002] = 1
> +
> +;example read bit
> +var bit x,y,z
> +x = test[2000]
> +y = test[2001]
> +z = test[2002]
> +
> +-- send these three bytes via serial port 10 times
> +for 10 loop
> +   serial_hw_data = x
> +   serial_hw_data = y
> +   serial_hw_data = z
> +end loop
> +
> +-- show the array byte that contains these bits
> +-- location is 2000 / 8 = 250
> +-- non-valued bits will be unpredictable
> +-- in this sample, output will be byte XXXXX101
> +for 10 loop
> +   serial_hw_data = bit_array_1_byte_array[250]
> +end loop
> +
>
> --
> You received this message because you are subscribed to the Google Groups
> "jallib" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/jallib?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to