PIC JAL IO Routine

MAX127/MAX128 ( 12 bits, 8 channels A/D converter) control routines

by  Alessandro Zummo

--
-- file      : max127.jal
-- author    : Alessandro Zummo <azummo at ita.flashnet.it>
-- date      : 03.07.2000
-- purpose   : MAX127/MAX128 ( 12 bits, 8 channels A/D converter) control routines
-- requires  : i2c
-- pins      : see i2cp
--
-- Copyright (C) 2000 Alessandro Zummo
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Library General Public
-- License as published by the Free Software Foundation; either
-- version 2 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-- Library General Public License for more details.
-- 
-- You should have received a copy of the GNU Library General Public
-- License along with this library; if not, write to the
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-- Boston, MA  02111-1307, USA.
--

-- This library has not (yet) been tested by the author. If it works
-- for you, please drop me a note.


-- include the required libraries
include i2c


-- Convert and read <channel> from the MAX127/MAX128 located at <address>
--
-- rng_in and bip_in will be copied to the RNG and BIP bits of the transferred
-- control byte. 
--
-- Result will be pacled in msb and lsb
--
-- Please check the datasheet for further explanations. 


procedure max127_read( byte in address, byte in channel, bit in rng_in, bit in bip_in, byte out msb, byte out lsb ) is

	var byte cnt = 4

	var byte control = 0b_1000_0000

	var bit rng at control : 3
	var bit bip at control : 2

	rng = rng_in
	bip = bip_in
	
	control = control | ( channel << 4)


	i2c_write_1( address, control )

	i2c_read_2( address, msb, lsb )


	-- shift the result right by 4 bits

	lsb = ( msb << 4 ) + ( lsb >> 4 )
	msb = ( msb >> 4 )

end procedure



-- Power down modes, to wake up the chip a call to max127_read should be enough.


-- standby power down

procedure max127_standby( byte in address ) is

	i2c_write_1( address, 0b_1000_0010 )

end procedure


-- full power down

procedure max127_powerdown( byte in address ) is

	i2c_write_1( address, 0b_1000_0011 )

end procedure



See:

See also:

Code:

Interested: