<root>
<document schema='101' license='1,Jan Lichtenbelt,C5EM4X' title='' description='' target='PIC.16F.16F1847' >
	<config data='!0,9a4!10,1cff%0,4%3,0%5,1%6,0%7,1%8,1%9,0%b,1%c,0%d,0%10,3%14,1%18,0%19,0%1a,1%1c,1%1d,0' clkspd='19660800' simspd='1' usewdt='0' constif='0' />
	<plugins >
		<dll_dbg_icd enabled='0' >
			<data name='debug' value='1' />
			<data name='userpins' value='0' />
			<data name='speed' value='0' />
			<data name='usev9' value='0' />
			<data name='breaks' value='8' />
			<data name='stacks' value='8' />
			<data name='clkport' value='1' />
			<data name='clkbit' value='6' />
			<data name='dataport' value='1' />
			<data name='databit' value='7' />
			<data name='ghostype' value='0' />
			<data name='monitor' value='1' />
			<data name='ictloop' value='0' />
			<data name='ictrate' value='20000' />
			<data name='ictmask' value='0' />
			<data name='anlpres' value='19' />
			<data name='digmask1' value='-1' />
			<data name='digmask2' value='-1' />
		</dll_dbg_icd>
		<dll_models enabled='1' />
		<dll_upgrader enabled='1' />
		<dll_webhelp enabled='1' />
	</plugins>
	<supplement use='0' head='' body='' />
	<debug >
		<watch expr='Current_Correction_Factor' />
	</debug>
	<ghost >
		<FK2 >
			<data name='FK2D0' port='4294967295' pin='4294967295' />
			<data name='FK2D1' port='4294967295' pin='4294967295' />
			<data name='FK2D2' port='4294967295' pin='4294967295' />
			<data name='FK2D3' port='4294967295' pin='4294967295' />
			<data name='FK2D4' port='4294967295' pin='4294967295' />
			<data name='FK2D5' port='4294967295' pin='4294967295' />
			<data name='FK2D6' port='4294967295' pin='4294967295' />
			<data name='FK2D7' port='4294967295' pin='4294967295' />
			<data name='FK2D8' port='4294967295' pin='4294967295' />
			<data name='FK2D9' port='4294967295' pin='4294967295' />
			<data name='FK2D10' port='4294967295' pin='4294967295' />
			<data name='FK2D11' port='4294967295' pin='4294967295' />
			<data name='FK2D12' port='4294967295' pin='4294967295' />
			<data name='FK2D13' port='4294967295' pin='4294967295' />
			<data name='FK2D14' port='4294967295' pin='4294967295' />
			<data name='FK2D15' port='4294967295' pin='4294967295' />
			<data name='FK2A0' port='4294967295' pin='4294967295' />
			<data name='FK2A1' port='4294967295' pin='4294967295' />
			<data name='FK2A2' port='4294967295' pin='4294967295' />
			<data name='FK2A3' port='4294967295' pin='4294967295' />
			<data name='FK2A4' port='4294967295' pin='4294967295' />
			<data name='FK2A5' port='4294967295' pin='4294967295' />
		</FK2>
		<ICD >
			<data name='AnalogPrescaleValue' value='19' />
			<data name='DigitalSampleRate' value='100000' />
			<data name='BreakpointCount' value='8' />
			<data name='CallStackDepthCount' value='8' />
			<data name='ClockPort' value='1' />
			<data name='ClockPin' value='6' />
			<data name='DataPort' value='1' />
			<data name='DataPin' value='7' />
			<data name='UseDefaultPins' value='1' />
			<data name='WrapEnabled' value='1' />
			<data name='CommsDelayOverridden' value='0' />
			<data name='CommsDelay' value='9' />
			<data name='CalculatedCommsDelay' value='9' />
		</ICD>
		<pins >
			<digital A='0' B='0' C='0' D='0' E='0' F='0' G='0' H='0' I='0' J='0' K='0' L='0' M='0' N='0' O='0' P='0' Q='0' R='0' S='0' T='0' U='0' V='0' W='0' X='0' Y='0' Z='0' />
			<analog A='0' B='0' C='0' D='0' E='0' F='0' G='0' H='0' I='0' J='0' K='0' L='0' M='0' N='0' O='0' P='0' Q='0' R='0' S='0' T='0' U='0' V='0' W='0' X='0' Y='0' Z='0' />
		</pins>
	</ghost>
	<components >
		<settings autoimg='1' center='1' unitscale='0' fixedscale='0' fixedx='1' fixedy='1' fixedz='1' headcode='0' />
		<definition guid='dd3cb5d2-0750-424a-a23b-81c6dd6e22c6' vstate='40' vmin='0' vmaj='1' srcleaf='' visiblename='' description='' category='' catenable='1' author='' manuname='' manucode='' sysinfo='0' keywords='' dynamic='0' iconpath='' />
		<component class_type='root' codename='panel' x='0' y='0' z='0' xsz='1' ysz='1' zsz='1' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' interactive='1' solid='1' layer='0' poslock='0' >
			<resources />
			<properties />
			<values />
			<events />
			<apis />
			<variables >
				<variable public='0' >
					<def class_type='variable' name='Read_Databyte_L' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Test' type='b1' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Pointer_Bus_Voltage' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Read_Databyte_H' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Pointer_Power_Register' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Calibration_Register_L' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='false' type='b1' description='' isconst='1' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Calibration_Register_H' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Temp' type='u16' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Shunt_Current' type='s16' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='I2C_Slave_Address' type='u8' description='' isconst='0' isinit='1' usrinit='64' setinit='0x40' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='I2C_Write_Slave_Address' type='u8' description='Slave address' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Pointer_Current' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Configuration_Register_L' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Current_LSB' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Current_Correction_Factor' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Configuration_Register_H' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Pointer_Configuration_Register' type='u8' description='Register' isconst='0' isinit='1' usrinit='0' setinit='0x00' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Pointer_Calibration_Register' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Pointer_Shunt_Voltage' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Version' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='I2C_Read_Slave_Address' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='true' type='b1' description='' isconst='1' isinit='1' usrinit='1' setinit='1' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Bus_Voltage' type='u16' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Counter_Flickering' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
				</variable>
			</variables>
			<macros >
				<macro >
					<flowline name='Enable_I2C_Sensor' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='call' title='Initialise I2C master' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='Initialise' />
						<command class_type='call' title='Write configuration register' cmdcolor='1975743' cmdcolor_sec='1975743' macro='Write_Data' >
							<argument exp='Pointer_Configuration_Register' />
							<argument exp='Configuration_Register_H' />
							<argument exp='Configuration_Register_L' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Write_Data' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<param name='Pointer_Address' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Data_MSB' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Data_LSB' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='comment' title='' comment='Write I2C data' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='call' title='Start I2C' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='Start' />
						<command class_type='call' title='Send address' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='TransmitByte' >
							<argument exp='I2C_Write_Slave_Address' />
						</command>
						<command class_type='call' title='Send pointer address' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='TransmitByte' >
							<argument exp='.Pointer_Address' />
						</command>
						<command class_type='call' title='Send high byte MSB' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='TransmitByte' >
							<argument exp='.Data_MSB' />
						</command>
						<command class_type='call' title='Send low byte LSB' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='TransmitByte' >
							<argument exp='.Data_LSB' />
						</command>
						<command class_type='call' title='Stop' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='Stop' />
					</flowline>
				</macro>
				<macro >
					<flowline name='Read_Data' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<param name='Pointer_Address' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='comment' title='' comment='Receive I2C word' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='call' title='Start I2C' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='Start' />
						<command class_type='call' title='Send address' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='TransmitByte' >
							<argument exp='I2C_Write_Slave_Address' />
						</command>
						<command class_type='call' title='Send pointer address' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='TransmitByte' >
							<argument exp='.Pointer_Address' />
						</command>
						<command class_type='call' title='Restart I2C' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='Restart' />
						<command class_type='call' title='Send address' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='TransmitByte' >
							<argument exp='I2C_Read_Slave_Address' />
						</command>
						<command class_type='call' title='Read Databyte High (0= not last bit)' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='ReceiveByte' >
							<return exp='Read_Databyte_H' />
							<argument exp='0' />
						</command>
						<command class_type='call' title='Read Databyte Low (1= last bit read)' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='ReceiveByte' >
							<return exp='Read_Databyte_L' />
							<argument exp='1' />
						</command>
						<command class_type='call' title='Stop' cmdcolor='1975743' cmdcolor_sec='1975743' component='I2C_Master1' macro='Stop' />
					</flowline>
				</macro>
				<macro >
					<flowline name='Init' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='calculation' title='Set default values' cmdcolor='7895044' cmdcolor_sec='7895044' >
							<exp exp='// Move 7-bits address one bit left and add R/W bit at LSB' />
							<exp exp='I2C_Write_Slave_Address = I2C_Slave_Address &lt;&lt; 1 // LSB=0 for write mode' />
							<exp exp='I2C_Read_Slave_Address = I2C_Write_Slave_Address | 0x01 // LSB =1 for read mode' />
							<exp exp='Pointer_Configuration_Register = 0x00 //R/W' />
							<exp exp='Pointer_Shunt_Voltage = 0x01' />
							<exp exp='Pointer_Bus_Voltage = 0x02' />
							<exp exp='Pointer_Power_Register = 0x03' />
							<exp exp='Pointer_Current = 0x04' />
							<exp exp='Pointer_Calibration_Register = 0x05 // R/W' />
							<exp exp='Configuration_Register_H = 0x19' />
							<exp exp='Configuration_Register_L = 0x9F' />
						</command>
						<command class_type='calculation' title='Set version#' cmdcolor='7895044' cmdcolor_sec='7895044' >
							<exp exp='Version = 6' />
							<exp exp='Test = false' />
						</command>
						<command class_type='call' title='Start LCD' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='Start' />
						<command class_type='delay' title='Delay' cmdcolor='7895044' cmdcolor_sec='7895044' exp='10' type='1' />
						<command class_type='call' title='Clear LCD' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='Clear' />
						<command class_type='call' title='Show text' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintString' >
							<argument exp='&quot;Li-Charger&quot;' />
						</command>
						<command class_type='call' title='2nd line' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='Cursor' >
							<argument exp='0' />
							<argument exp='1' />
						</command>
						<command class_type='call' title='Show text' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintString' >
							<argument exp='&quot;V&quot;' />
						</command>
						<command class_type='call' title='Show version number' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintNumber' >
							<argument exp='Version' />
						</command>
						<command class_type='call' title='Enable VEML6075 and send configuration word' cmdcolor='1975743' cmdcolor_sec='1975743' macro='Enable_I2C_Sensor' />
						<command class_type='comment' title='' comment='Calibration register address: 05h (R/W)
Calibration register (2 bytes):
Definitions: Current_LSB is the smallest current measured (Current units) 
             = (Maximum Expected Current * 2^-15)  in A/bit 
             (mostly in the range uA/bit or mA/bit)
Store in Calibration register: 0.04096/(Current_LSB * Rshunt)
e.g.
with Max current=1.5A Current_LSB is about 50 uA/bit
with Rshunt= 0.22R the calibration = 3724 = 0x0E8C' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='calculation' title='Berekening' cmdcolor='7895044' cmdcolor_sec='7895044' >
							<exp exp='Calibration_Register_H = 0x0E' />
							<exp exp='Calibration_Register_L = 0x8C' />
							<exp exp='Current_LSB = 50 // 50 uA/bit' />
							<exp exp='Current_Correction_Factor = 1000 / Current_LSB // to change current in mA units' />
							<exp exp='' />
						</command>
						<command class_type='call' title='Write Calibration factor' cmdcolor='1975743' cmdcolor_sec='1975743' macro='Write_Data' >
							<argument exp='Pointer_Calibration_Register' />
							<argument exp='Calibration_Register_H' />
							<argument exp='Calibration_Register_L' />
						</command>
						<command class_type='calculation' title='Reset counter' cmdcolor='7895044' cmdcolor_sec='7895044' >
							<exp exp='Counter_Flickering = 0' />
						</command>
						<command class_type='delay' title='Delay' cmdcolor='7895044' cmdcolor_sec='7895044' exp='3' type='2' />
						<command class_type='decision' title='Test true?' cmdcolor='3568629' cmdcolor_sec='3568629' exp='Test' swap='0' >
							<flowline >
								<command class_type='call' title='Read config word' cmdcolor='1975743' cmdcolor_sec='1975743' macro='Read_Data' >
									<argument exp='Pointer_Configuration_Register' />
								</command>
								<command class_type='calculation' title='Calulate word' cmdcolor='7895044' cmdcolor_sec='7895044' >
									<exp exp='Temp = Read_Databyte_L' />
									<exp exp='Temp = Temp + (Read_Databyte_H &lt;&lt; 8)' />
								</command>
								<command class_type='call' title='Clear LCD' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='Clear' />
								<command class_type='call' title='Show text' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintString' >
									<argument exp='&quot;Config: &quot;' />
								</command>
								<command class_type='call' title='Show number' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintFormattedNumber' >
									<argument exp='Temp' />
									<argument exp='1' />
								</command>
								<command class_type='call' title='Read  Calibartion Register' cmdcolor='1975743' cmdcolor_sec='1975743' macro='Read_Data' >
									<argument exp='Pointer_Calibration_Register' />
								</command>
								<command class_type='calculation' title='Calculate word' cmdcolor='7895044' cmdcolor_sec='7895044' >
									<exp exp='Temp = Read_Databyte_L' />
									<exp exp='Temp = Temp + (Read_Databyte_H &lt;&lt; 8)' />
								</command>
								<command class_type='call' title='2nd line' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='Cursor' >
									<argument exp='0' />
									<argument exp='1' />
								</command>
								<command class_type='call' title='Show text' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintString' >
									<argument exp='&quot;Calibr: &quot;' />
								</command>
								<command class_type='call' title='Show number' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintFormattedNumber' >
									<argument exp='Temp' />
									<argument exp='1' />
								</command>
								<command class_type='delay' title='Delay' cmdcolor='7895044' cmdcolor_sec='7895044' exp='5' type='2' />
							</flowline>
							<flowline />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Main' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='comment' title='' comment='Bidirectional current sensor INA219 
ref: www.ti.com/product/INA219

Used to monitor the (de)charging process of a Li-battery.
Set up: 6V power -&gt; Li-battery charger (MIC79050) -&gt; shunt resistance -&gt; Li-battery
The current sensor is parallel the shunt resiatnce.

Jan Lichtenbelt, NL
August, 2017

Version 4: Lot of changes
Version 5: improved calibration word
Version 6: LED sequence/colours changed' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='comment' title='' comment='I2C_Slave_Address = 0x40   Slave address (with Port A0 and A1 of INA219 to GND)' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='comment' title='' comment='Remark:
If your are new in using this currents sensor, I would use
only the Vbus (Vin-), the voltage at the load site and
the Shunt Voltage (Vin+-Vin-). 
The advantage is that you do not need the calibration factor. 
But then you have to calcaulate the current and/or the power yourself.
Only take care of 
1. The bit 13 of the configuartion register
which will be 0 for Vbus &lt;16 Volt or will be 1 for Vbus &lt;32 Volt.
(Conf. reg. is resp. 199Fh and 399Fh)
2. Vshunt will be in 10 uVolt units
3. Vbus = Vbus-register&gt;&gt;3 in 4 mVolt units

Advice: Set test=true in the init macro' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='comment' title='' comment='Registers:

POINTER 0x00h (R/W):
Configuration register (2 bytes): 0001 1001 1001 1111 = 199Fh = 6559
bit 15: 0   No reset
bit 14: X   not used
bit 13: 0   maximum bus voltage 16 Volt (at IN-)
bits 11, 12: 11  maximum voltage over the shunt ±320 mV
bits 7-10: 0011  12 bit Bus voltage resolution with 532 usec conversion time
bits 3-6: 0011   12 bits sunt voltage resulution with 532 usec conversion time
bits 0-2: 111  shunt and bus continous mode

POINTER 0x01h (R):
Shunt voltage (Vin+ - Vin-)in 10uV units 
in 2&apos;s complement format with:
320 mV = 32000 (dec)= 7C00h
0mV=  0
-0.01 mV= -1 (dec) = FFFFh
-320mV= -32000 (dec) = 8300h

POINTER 0x02h (R):
Bus Voltage register Vin- (2 bytes)
    should be right shifted 3 bits (diviede by 8) to get the 4 mV units

POINTER 0x03h (R):
Power register (not used)

POINTER 0x04h (R):
The shunt current register (2 bytes) in 1 mA unit
Negative values are stored in 2&apos;s complement format, see shunt voltage

POINTER 0x05h (R/W):
Calibration register (2 bytes):
Definitions: Current_LSB is the smallest current measured (Current units) 
             = (Maximum Expected Current * 2^-15)  in A/bit (mostly in the range uA/bit or mA/bit)
Store in Calibration register: 0.04096/(Current_LSB * Rshunt)' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='comment' title='' comment='LCD output: Vbus and shunt current
LED output (based on measurements of my Li-battery 800mAh) 
Load current &gt;0 during charging process 
     (current up to about I2 = 400 mA)
     Vbus &gt; 4.15 Volt green
     3.9 &lt; Vbus &lt; 4.15 Volt orange (capacity&gt;50%)
     3.0 &lt;Vbus &lt; 3.9 Volt red (charging strongly advised)
     Vbus &lt;3.0 Volt red flickering (start charging process directly)
Load current &lt;0 during discharging process (continously I10 = 80 mA)
     3.7 &lt; Vbus &lt; 4.2 Volt green (OK)
     3.6 &lt; Vbus &lt; 3.7 Volt orange (Pay attention)
     3.0 &lt; Vbus &lt; 3.6 Volt red (charging advised)
     Vbus &lt; 3.0 Volt flickering red flickering (start charging directly)


Steps:
1. Enable I2C
2. Store Configuration word
3. Store calibration word
4. Read bus voltage and shunt current' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='comment' title='' comment='I2C: 
Channel 1: SDA1 on port B1 and SCL1 on port B4
(Channel 2: SDA2 on port B2 and SCL2 in port B5. Not used)' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='comment' title='' comment='Output ports:
LCD:
Rs port A2
E port A3
D4 port A4
D5 port A6
D6 port B0
D7 port B2

LEDs:
B5: LED green 
B6: LED orange
B3: LED red' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
						<command class_type='native' title='Set internal osc. 16 MHz' ccode='OSCCON= 0x78; 

' cmdcolor='3389439' cmdcolor_sec='3389439' language='C' />
						<command class_type='call' title='Initialise' cmdcolor='1975743' cmdcolor_sec='1975743' macro='Init' />
						<command class_type='loop' title='Lus' cmdcolor='3568629' cmdcolor_sec='3568629' type='0' exp='1' >
							<flowline >
								<command class_type='call' title='Read bus voltage ' cmdcolor='1975743' cmdcolor_sec='1975743' macro='Read_Data' >
									<argument exp='Pointer_Bus_Voltage' />
								</command>
								<command class_type='calculation' title='Save bus voltage' cmdcolor='7895044' cmdcolor_sec='7895044' >
									<exp exp='Bus_Voltage = Read_Databyte_L' />
									<exp exp='Bus_Voltage = Bus_Voltage + (Read_Databyte_H &lt;&lt; 8)' />
									<exp exp='Bus_Voltage = Bus_Voltage &gt;&gt; 3 // in  4 mV' />
									<exp exp='Bus_Voltage = Bus_Voltage &lt;&lt; 2 // in mV' />
								</command>
								<command class_type='call' title='Read shunt current' cmdcolor='1975743' cmdcolor_sec='1975743' macro='Read_Data' >
									<argument exp='Pointer_Current' />
								</command>
								<command class_type='calculation' title='Save shunt current' cmdcolor='7895044' cmdcolor_sec='7895044' >
									<exp exp='Shunt_Current = Read_Databyte_L' />
									<exp exp='Shunt_Current = Shunt_Current + (Read_Databyte_H &lt;&lt; 8)' />
								</command>
								<command class_type='calculation' title='Calculate current in mA' cmdcolor='7895044' cmdcolor_sec='7895044' >
									<exp exp='Shunt_Current = Shunt_Current / Current_Correction_Factor // mA units' />
									<exp exp='' />
								</command>
								<command class_type='call' title='Start LCD' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='Start' />
								<command class_type='delay' title='Delay' cmdcolor='7895044' cmdcolor_sec='7895044' exp='3' type='1' />
								<command class_type='call' title='Show number' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintFormattedNumber' >
									<argument exp='Bus_Voltage' />
									<argument exp='1' />
								</command>
								<command class_type='call' title='Show text' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintString' >
									<argument exp='&quot; mV&quot;' />
								</command>
								<command class_type='call' title='2nd line' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='Cursor' >
									<argument exp='0' />
									<argument exp='1' />
								</command>
								<command class_type='decision' title='Vbus &gt; 2.7 Volt' cmdcolor='3568629' cmdcolor_sec='3568629' exp='(Bus_Voltage &gt; 2700) OR test' swap='1' >
									<flowline >
										<command class_type='call' title='Show text' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintString' >
											<argument exp='&quot;SHUT DOWN!!!&quot;' />
										</command>
									</flowline>
									<flowline >
										<command class_type='call' title='Show number' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintFormattedNumber' >
											<argument exp='Shunt_Current' />
											<argument exp='0' />
										</command>
										<command class_type='call' title='Show text' cmdcolor='1975743' cmdcolor_sec='1975743' component='lcd_eb005' macro='PrintString' >
											<argument exp='&quot; mA&quot;' />
										</command>
									</flowline>
								</command>
								<command class_type='decision' title='Current &lt;0?' cmdcolor='3568629' cmdcolor_sec='3568629' exp='Shunt_Current &lt; 0' swap='0' >
									<flowline >
										<command class_type='comment' title='' comment='You are discharging now' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
										<command class_type='decision' title='Vbus &gt; 3.7 Volt?' cmdcolor='3568629' cmdcolor_sec='3568629' exp='Bus_Voltage &gt; 3700' swap='0' >
											<flowline >
												<command class_type='comment' title='' comment='Still in comfort range V&gt;3.7 Volt' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
												<command class_type='output' title='green LED' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='32' exp='1' />
											</flowline>
											<flowline >
												<command class_type='decision' title='Vbus &gt; 3.6 Volt?' cmdcolor='3568629' cmdcolor_sec='3568629' exp='Bus_Voltage &gt; 3600' swap='0' >
													<flowline >
														<command class_type='comment' title='' comment='Pay attention in the range 3.6-3.7 Volt
' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
														<command class_type='output' title='orange LED on' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='64' exp='1' />
													</flowline>
													<flowline >
														<command class_type='decision' title='Vbus &gt; 3.0 Volt?' cmdcolor='3568629' cmdcolor_sec='3568629' exp='Bus_Voltage &gt; 3000' swap='0' >
															<flowline >
																<command class_type='comment' title='' comment='Serious warning range: STOP if &lt; 3.6 Volt' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
																<command class_type='output' title='red LED on' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='8' exp='1' />
															</flowline>
															<flowline >
																<command class_type='comment' title='' comment='&lt; 3 Volt: ALARM, START CHARGING DIRECTLY' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
																<command class_type='output' title='red LED flickering' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='8' exp='Counter_Flickering' />
																<command class_type='calculation' title='Change counter' cmdcolor='7895044' cmdcolor_sec='7895044' >
																	<exp exp='Counter_Flickering = 1 - Counter_Flickering' />
																</command>
															</flowline>
														</command>
													</flowline>
												</command>
											</flowline>
										</command>
									</flowline>
									<flowline >
										<command class_type='comment' title='' comment='On the right way of charging

' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
										<command class_type='decision' title='Vbus &gt;4.15 Volt?' cmdcolor='3568629' cmdcolor_sec='3568629' exp='Bus_Voltage &gt; 4150' swap='0' >
											<flowline >
												<command class_type='comment' title='' comment='Full of charge 4.15-4.2 VOLT' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
												<command class_type='output' title='green LED on' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='32' exp='1' />
											</flowline>
											<flowline >
												<command class_type='decision' title='Vbus &gt; 3 .9Volt' cmdcolor='3568629' cmdcolor_sec='3568629' exp='Bus_Voltage &gt; 3900' swap='0' >
													<flowline >
														<command class_type='comment' title='' comment='3.9 &lt; Vbus &lt; 4.15 Volt Capacity &gt;50%

 ' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
														<command class_type='output' title='Orange LED on' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='64' exp='1' />
													</flowline>
													<flowline >
														<command class_type='decision' title='Vbus &gt; 3 Volt' cmdcolor='3568629' cmdcolor_sec='3568629' exp='Bus_Voltage &gt; 3000' swap='0' >
															<flowline >
																<command class_type='comment' title='' comment='3.0 &lt; Vbus &lt; 3.9 Volt. Capacity &lt; 50%. Charging advised


 ' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
																<command class_type='output' title='Red LED on' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='8' exp='1' />
															</flowline>
															<flowline >
																<command class_type='comment' title='' comment='Vbus &lt; 3.0 Volt. Low capacity. Start charging directly!


 ' textarea='12,0,12,0' cmdcolor='1975743' cmdcolor_sec='1975743' />
																<command class_type='output' title='red LED flickering' cmdcolor='7895044' cmdcolor_sec='7895044' mode='1' port='1048577' mask='8' exp='Counter_Flickering' />
																<command class_type='calculation' title='Change counter' cmdcolor='7895044' cmdcolor_sec='7895044' >
																	<exp exp='Counter_Flickering = 1 - Counter_Flickering' />
																</command>
															</flowline>
														</command>
													</flowline>
												</command>
											</flowline>
										</command>
									</flowline>
								</command>
								<command class_type='delay' title='Vertraging' cmdcolor='7895044' cmdcolor_sec='7895044' exp='300' type='1' />
							</flowline>
						</command>
					</flowline>
				</macro>
			</macros>
			<component class_type='ref' guid='24219805-113d-4b12-b6bd-e1b0b0c33981' vmin='4' vmaj='1' codename='I2C_Master1' x='-10' y='110' z='0.755' xsz='60' ysz='26' zsz='1.51' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' interactive='1' solid='1' layer='1' poslock='0' >
				<resources />
				<properties />
				<values >
					<value target='CHANNEL' data='001' />
					<value target='BAUD_LIST' data='001' />
					<value target='SRC' data='000' />
					<value target='SMB' data='000' />
					<value target='StopDelay' data='1' />
					<value target='BAUD' data='50000' />
					<value target='SDA' data='$PORTB.1' />
					<value target='SCL' data='$PORTB.4' />
					<value target='label' data='I2C Master' />
					<value target='ScopeTraces' data='0' />
					<value target='ConsoleData' data='' />
					<value target='Injector' data='000' />
					<value target='InjectorHandle' data='' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
			<component class_type='ref' guid='d29dda88-17de-4008-991a-c881890d4c57' vmin='1' vmaj='1' codename='lcd_eb005' x='0' y='0' z='5.085' xsz='1' ysz='1' zsz='1' xang='0' yang='0' zang='0' xquat='0' yquat='0' zquat='0' wquat='1' visible='1' interactive='1' solid='1' layer='1' poslock='0' >
				<resources />
				<properties />
				<values >
					<value target='Pin_Data_0' data='$PORTA.4' />
					<value target='Pin_Data_1' data='$PORTA.6' />
					<value target='Pin_Data_2' data='$PORTB.0' />
					<value target='Pin_Data_3' data='$PORTB.2' />
					<value target='Pin_RS' data='$PORTA.2' />
					<value target='Pin_E' data='$PORTA.3' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
		</component>
	</components>
	<keymap />
	<panel2d shadows='0' lighting='2' brightness='0' perspective='0' >
		<background rgb='2105930' img='' style='0' />
		<camera xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
	</panel2d>
	<panel3d shadows='0' lighting='2' brightness='0' perspective='0' >
		<background rgb='8409120' img='' style='0' />
		<table rgb='7360576' img='' style='0' size='25' />
		<camera xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<camerakey0 xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
		<camerakey1 xe='-3.67394e-14' ye='0' ze='-300' xt='0' yt='0' zt='0' xquat='0' yquat='1' zquat='0' wquat='6.12323e-17' />
		<camerakey2 xe='0' ye='-300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.707107' yquat='0' zquat='0' wquat='0.707107' />
		<camerakey3 xe='-3.67394e-14' ye='300' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-4.32978e-17' yquat='0.707107' zquat='0.707107' wquat='4.32978e-17' />
		<camerakey4 xe='-300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='0.5' zquat='0.5' wquat='0.5' />
		<camerakey5 xe='300' ye='-6.66134e-14' ze='6.66134e-14' xt='0' yt='0' zt='0' xquat='-0.5' yquat='-0.5' zquat='-0.5' wquat='0.5' />
		<camerakey6 xe='-173.205' ye='-173.205' ze='173.205' xt='0' yt='0' zt='0' xquat='-0.424708' yquat='0.17592' zquat='0.339851' wquat='0.820473' />
	</panel3d>
	<layout >
		<view type='0' name='Main' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAYAAAAOgMAANoCAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Init' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAYAAAAOgMAANoCAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Enable_I2C_Sensor' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAYAAAAOgMAANoCAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Write_Data' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAYAAAAOgMAANoCAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Read_Data' mode='0' placement='LAAAAAAAAAABAAAA---------------------wUAAAAYAAAAOgMAANoCAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
	</layout>
</document>
</root>
