<root>
<document schema='101' license='1,Georgios_Bardakis,2NK8PH' title='' description='' target='PIC.18F.18F4523' >
	<config data='!0,ff!8,32!10,e7!18,fe!20,ff!28,fb!30,ba!38,ff!40,ff!48,ff!50,ff!58,ff!60,ff!68,ff%8,2%e,0%f,0%10,1%11,3%13,0%18,0%19,f%28,1%29,1%2a,0%2f,1%30,0%32,0%36,0%37,1%40,1%41,1%42,1%43,1%4f,1%4e,1%50,1%51,1%52,1%53,1%5f,1%5e,1%5d,1%60,1%61,1%62,1%63,1%6e,1' 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='255' />
			<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 />
	<components >
		<settings autoimg='1' center='1' unitscale='0' fixedscale='0' fixedx='1' fixedy='1' fixedz='1' headcode='0' />
		<definition guid='b15d1842-d3c1-4431-946f-636fd40d490e' 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='false' type='b1' description='' isconst='1' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='weight' type='T8' description='measure weight' isconst='0' isinit='1' usrinit='&quot;&quot;' setinit='&quot;&quot;' >
						<array size='10' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='TotalWeight' type='T8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='10' />
					</def>
				</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='Zero_offset' type='s32' description='zero offset auto cal value' isconst='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
			</variables>
			<macros >
				<macro >
					<flowline name='HX711' description='reads data from the HX711 24 bit ADC

Pin B8 = clock out
Pin B9 = data in 
Pin B10 = Auto zero' >
						<return name='Return' type='T8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='20' />
						</return>
						<param name='scale' type='f32' description='scaling factor for load sensor' isconst='0' isinit='0' usrinit='0.0' setinit='' />
						<param name='calibrate' type='f32' description='offset for zero of load sensor' isconst='0' isinit='0' usrinit='0.0' setinit='' />
						<param name='Average_count' type='u8' description='sets the number of loops for averaging' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Average_loop_delay' type='u8' description='sets the delay between each loop [byte]' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='zero_swx' type='u8' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<local name='bit_counter' type='u8' description='bit counter = no of positional bits' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<local name='HX_DOUT' type='b1' description='reads the bit value form HX711' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<local name='hx771_word_in' type='u8' description='raw data word' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='24' />
						</local>
						<local name='hx711_word_out' type='u8' description='raw data word' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='24' />
						</local>
						<local name='wgt' type='s32' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<local name='wgt_ave' type='s32' description='avergae weight store' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<command class_type='calculation' title='reset weight value' >
							<exp exp='.wgt_ave = 0' />
						</command>
						<command class_type='loop' title='Averaging loop' type='2' exp='.Average_count' >
							<flowline >
								<command class_type='calculation' title='reset .wgt for next loop' >
									<exp exp='.wgt = 0' />
								</command>
								<command class_type='delay' title='averae loop delay' exp='.Average_loop_delay' type='1' />
								<command class_type='comment' title='' comment='wait until HX711 ready' textarea='12,0,12,0' />
								<command class_type='loop' title='check HX711 ready' type='0' forvar='.HX_DOUT = 1' exp='.HX_DOUT = 1' >
									<flowline >
										<command class_type='input' title='Input read DOUT' mode='1' port='135266305' mask='2' exp='.HX_DOUT' />
									</flowline>
								</command>
								<command class_type='calculation' title='set bit counter to MSB' >
									<exp exp='.bit_counter = 23' />
								</command>
								<command class_type='loop' title='read bit loop' type='2' exp='24' start='0' >
									<flowline >
										<command class_type='output' title='PD_SCK Clock output high' mode='1' port='1048578' mask='8' exp='1' />
										<command class_type='input' title='Input read DOUT' mode='1' port='1048578' mask='16' exp='.HX_DOUT' />
										<command class_type='delay' title='T3 - Clock High Time' exp='10' type='0' />
										<command class_type='output' title='PD_SCK Clock output low' mode='1' port='1048578' mask='8' exp='0' />
										<command class_type='delay' title='T3 - Clock High Time' exp='10' type='0' />
										<command class_type='calculation' title='build a byte' textarea='66,10,66,10' >
											<exp exp='.hx771_word_in[.bit_counter] = .HX_DOUT' />
										</command>
										<command class_type='calculation' title='Calculation' >
											<exp exp='.bit_counter = .bit_counter - 1' />
										</command>
									</flowline>
								</command>
								<command class_type='comment' title='' comment='25TH clock pulse = A channel High gain' textarea='36,18,36,18' />
								<command class_type='output' title='PD_SCK Clock output high' disable='1' mode='1' port='1048578' mask='8' exp='1' />
								<command class_type='delay' title='T3 - Clock High Time' disable='1' exp='10' type='0' />
								<command class_type='output' title='PD_SCK Clock output low' disable='1' mode='1' port='1048578' mask='8' exp='0' />
								<command class_type='delay' title='T3 - Clock High Time' disable='1' exp='10' type='0' />
								<command class_type='comment' title='' comment='26TH clock pulse = B Channel' textarea='36,7,36,7' disable='1' />
								<command class_type='output' title='PD_SCK Clock output high' disable='1' mode='1' port='1048578' mask='8' exp='1' />
								<command class_type='delay' title='T3 - Clock High Time' disable='1' exp='10' type='0' />
								<command class_type='output' title='PD_SCK Clock output low' disable='1' mode='1' port='1048578' mask='8' exp='0' />
								<command class_type='delay' title='T3 - Clock High Time' disable='1' exp='10' type='0' />
								<command class_type='comment' title='' comment='27TH clock pulse  = A channel low gain' textarea='36,7,36,7' disable='1' />
								<command class_type='output' title='PD_SCK Clock output high' disable='1' mode='1' port='1048578' mask='8' exp='1' />
								<command class_type='delay' title='T3 - Clock High Time' disable='1' exp='1' type='0' />
								<command class_type='output' title='PD_SCK Clock output low' disable='1' mode='1' port='1048578' mask='8' exp='0' />
								<command class_type='delay' title='T3 - Clock High Time' disable='1' exp='1' type='0' />
								<command class_type='comment' title='' comment='+/- sign data' textarea='12,0,12,0' />
								<command class_type='calculation' title='set bit counter to MSB' >
									<exp exp='.bit_counter = 23' />
								</command>
								<command class_type='decision' title='check if sign bit is set - then invert bits' exp='.hx771_word_in[23] = 1' swap='0' >
									<flowline >
										<command class_type='loop' title='invert convert loop' type='2' exp='24' >
											<flowline >
												<command class_type='calculation' title='Calculation' >
													<exp exp='.hx711_word_out[.bit_counter] = ! .hx771_word_in[.bit_counter]' />
												</command>
												<command class_type='calculation' title='Calculation' >
													<exp exp='.bit_counter = .bit_counter - 1' />
												</command>
												<command class_type='calculation' title='Calculation' >
													<exp exp='weight = &quot;-&quot;' />
												</command>
											</flowline>
										</command>
									</flowline>
									<flowline >
										<command class_type='loop' title='convert loop' type='2' exp='24' >
											<flowline >
												<command class_type='calculation' title='Calculation' >
													<exp exp='.hx711_word_out[.bit_counter] = .hx771_word_in[.bit_counter]' />
												</command>
												<command class_type='calculation' title='Calculation' >
													<exp exp='.bit_counter = .bit_counter - 1' />
												</command>
												<command class_type='calculation' title='Calculation' >
													<exp exp='weight = &quot;+&quot;' />
												</command>
											</flowline>
										</command>
									</flowline>
								</command>
								<command class_type='comment' title='' comment='build data' textarea='69,16,69,16' disable='1' />
								<command class_type='calculation' title='set bit counter to MSB' >
									<exp exp='.bit_counter = 23' />
								</command>
								<command class_type='loop' title='Loop' type='2' exp='20' start='0' >
									<flowline >
										<command class_type='decision' title='Decision' exp='.bit_counter = 20' swap='0' >
											<flowline >
												<command class_type='calculation' title='last bit - dont move LSH' >
													<exp exp='.wgt = (.wgt + .hx711_word_out[.bit_counter])' />
													<exp exp='' />
													<exp exp='' />
												</command>
											</flowline>
											<flowline >
												<command class_type='calculation' title='Calculation' >
													<exp exp='.wgt = (.wgt + .hx711_word_out[.bit_counter])' />
													<exp exp='.wgt = .wgt &lt;&lt; 1 // move along 1 bit' />
													<exp exp='' />
												</command>
											</flowline>
										</command>
										<command class_type='calculation' title='Calculation' >
											<exp exp='.bit_counter = .bit_counter - 1' />
										</command>
									</flowline>
								</command>
								<command class_type='decision' title='' exp='.hx771_word_in[23] = 1' swap='0' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.wgt = ~ .wgt' />
											<exp exp='.wgt = .wgt + 1' />
											<exp exp='' />
										</command>
									</flowline>
									<flowline />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.wgt = .wgt + .calibrate' />
								</command>
								<command class_type='comment' title='' comment='Auto calibrate' textarea='36,13,36,13' />
								<command class_type='call' title='Call Component Macro' component='pcb_switch1' macro='ReadState' >
									<return exp='.zero_swx' />
								</command>
								<command class_type='decision' title='Decision' exp='.zero_swx = 1' swap='0' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='Zero_offset = ~ .wgt + 1' />
										</command>
									</flowline>
									<flowline />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.wgt = .wgt + Zero_offset' />
								</command>
								<command class_type='comment' title='' comment='scale' textarea='12,0,12,0' />
								<command class_type='calculation' title='Calculation' >
									<exp exp='.wgt = .wgt * .scale' />
								</command>
								<command class_type='calculation' title='count average weight' >
									<exp exp='.wgt_ave = .wgt_ave + .wgt' />
								</command>
							</flowline>
						</command>
						<command class_type='comment' title='' comment='calculate average' textarea='12,0,12,0' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='.wgt = .wgt_ave / .Average_count' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Return = ToString$ (.wgt)' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Main' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='call' title='Call Component Macro' component='lcd_4x20' macro='Start' />
						<command class_type='loop' title='Loop' type='0' exp='1' >
							<flowline >
								<command class_type='call' title='Call Component Macro' component='lcd_4x20' macro='Cursor' >
									<argument exp='0' />
									<argument exp='0' />
								</command>
								<command class_type='call' title='Call Component Macro' component='lcd_4x20' macro='PrintString' >
									<argument exp='&quot;weight: &quot;' />
								</command>
								<command class_type='call' title='Call Component Macro' component='lcd_4x20' macro='PrintString' >
									<argument exp='TotalWeight' />
								</command>
								<command class_type='call' title='Call Component Macro' component='lcd_4x20' macro='PrintString' >
									<argument exp='&quot;     &quot;' />
								</command>
								<command class_type='call' title='Call Macro' macro='HX711' >
									<return exp='TotalWeight' />
									<argument exp='0.2' />
									<argument exp='0.1' />
									<argument exp='10' />
									<argument exp='5' />
								</command>
								<command class_type='delay' title='Delay' exp='500' type='1' />
							</flowline>
						</command>
					</flowline>
				</macro>
			</macros>
			<component class_type='ref' guid='a2b40602-5421-4e2f-ba82-96db1be51d69' vmin='1' vmaj='1' codename='lcd_4x20' x='-20' y='75' 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 >
					<value target='Pin_Data_0' data='$PORTB.0' />
					<value target='Pin_Data_1' data='$PORTB.1' />
					<value target='Pin_Data_2' data='$PORTB.2' />
					<value target='Pin_Data_3' data='$PORTB.3' />
					<value target='Pin_RS' data='$PORTB.4' />
					<value target='Pin_E' data='$PORTB.5' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
			<component class_type='ref' guid='26732594-ad79-472f-80ff-95d365b3b252' vmin='2' vmaj='1' codename='pcb_switch1' x='-85' y='80' z='0' xsz='3.88889' ysz='4.03226' 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 >
					<value target='pin' data='$PORTA.0' />
					<value target='polarity' data='000' />
					<value target='debounce' data='10' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
		</component>
	</components>
	<keymap />
	<panel2d shadows='0' lighting='2' brightness='0' perspective='0' >
		<background rgb='9737364' 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='62' />
		<camera xe='0' ye='0' ze='300' xt='0' yt='0' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
	</panel3d>
	<layout >
		<view type='0' name='Main' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAArAIAAHMDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='HX711' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAArAIAAHMDAAA' zoom='75' scrollx='0' scrolly='1663' flags='0' />
	</layout>
</document>
</root>
