<root>
<document schema='101' license='50,Dev User,XDKHX7' title='' description='' target='PIC16.24H.24HJ128GP202' >
	<config data='!0,ffff!10,ffff!20,ffff!30,ff7a!40,ff9e!50,ff7f!60,ffff!70,ffdf%0,1%1,7%6,3%10,1%11,7%16,3%20,1%21,3%30,2%37,0%40,2%42,1%45,0%46,2%50,f%54,1%56,1%57,0%60,7%64,1%65,7%70,3%75,0%76,1%77,1' clkspd='12000000' 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='1000' />
			<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='1' />
			<data name='ictrate' value='1000' />
			<data name='ictmask' value='-1' />
			<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='#define _FGS(x) __attribute__((section(&quot;__FGS.sec,code&quot;))) int _FGS = (x);' body='' />
	<debug />
	<components >
		<settings autoimg='1' center='1' unitscale='0' fixedscale='0' fixedx='1' fixedy='1' fixedz='1' headcode='0' />
		<definition guid='3f8d29a6-40a6-4d5e-a254-190c86d9ebb7' vstate='40' vmin='0' vmaj='1' srcleaf='' visiblename='RFID' description='Functions designed to work with the MFRC522 contactless reader IC.
The MFRC522 supports all variants of the MIFARE Mini, MIFARE 1K, MIFARE 4K, MIFARE Ultralight, 
MIFARE DESFire EV1 and MIFARE Plus RF identification protocols.
' category='Wireless' catenable='1' author='Ben Rowland' manuname='' manucode='' sysinfo='0' keywords='' dynamic='0' iconpath='' />
		<component class_type='root' codename='RFID_MFRC522' 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 >
				<property name='Connections' folder='property_1' hidden='0' >
					<property name='Channel' target='Channel' typeid='16' hidden='0' locked='0' info='' />
					<property name='MISO / SDI' target='miso' typeid='5' hidden='0' locked='0' info='SPI Data In Pin
' />
					<property name='MOSI / SDO' target='mosi' typeid='5' hidden='0' locked='0' info='SPI Data Out Pin
' />
					<property name='SCK' target='sck' typeid='5' hidden='0' locked='0' info='SPI Serial Clock Pin
' />
					<property name='CS' target='CS' typeid='5' hidden='0' locked='0' info='SPI Chip Select Pin
' />
					<property name='Reset' target='reset' typeid='5' hidden='0' locked='0' info='MFRC522 Reset Pin
' />
				</property>
			</properties>
			<values >
				<value target='Channel' data='000' />
				<value target='miso' data='$PORTB.11' />
				<value target='mosi' data='$PORTB.10' />
				<value target='sck' data='$PORTB.9' />
				<value target='CS' data='$PORTB.8' />
				<value target='reset' data='$PORTB.13' />
			</values>
			<events />
			<apis >
				<api name='WriteBlock' alt='WriteBlock' type='1' proto='1' />
				<api name='ReadDataBuffer' alt='ReadDataBuffer' type='1' proto='1' />
				<api name='AntennaOff' alt='AntennaOff' type='1' proto='1' />
				<api name='ReadBlock' alt='ReadBlock' type='1' proto='1' />
				<api name='SelectTag' alt='SelectTag' type='1' proto='1' />
				<api name='WriteDataBuffer' alt='WriteDataBuffer' type='1' proto='1' />
				<api name='Auth' alt='Auth' type='1' proto='1' />
				<api name='AntennaOn' alt='AntennaOn' type='1' proto='1' />
				<api name='Compare' alt='Compare' type='1' proto='1' />
				<api name='Initialise' alt='Initialise' type='1' proto='1' />
				<api name='Check' alt='Check' type='1' proto='1' />
			</apis>
			<variables >
				<variable public='0' >
					<def class_type='variable' name='UserData' type='u8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='16' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='BackLen' 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='SendData' type='u8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='18' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Card' 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='BackData' type='u8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='16' />
					</def>
				</variable>
			</variables>
			<macros >
				<macro >
					<flowline name='Reset' description='Resets the MFRC522 device' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<local name='done' type='u8' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<local name='ret' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='CommandReg - PCD_SoftReset' macro='WriteRegister' >
							<argument exp='0x01' />
							<argument exp='0x0F' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='WriteBlock' description='Writes the contents of the 16-byte data buffer to the RFID block.
The data comes from the DataBuffer which can be set using the 
WriteDataBuffer macro.
Returns 0 for a succesful write.' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='BlockAddress' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='i' type='u8' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='SendData[0] = 0xA0' />
							<exp exp='SendData[1] = .BlockAddress' />
						</command>
						<command class_type='call' title='Call Macro' macro='CalculateCRC' >
							<argument exp='2' />
						</command>
						<command class_type='call' title='Call Macro' macro='ToCard' >
							<return exp='.Return' />
							<argument exp='0x0C' />
							<argument exp='4' />
						</command>
						<command class_type='decision' title='Decision' exp='.Return = 0' swap='0' >
							<flowline >
								<command class_type='loop' title='Loop' type='0' exp='.i &lt; 16' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='SendData[.i] = UserData[.i]' />
										</command>
										<command class_type='calculation' title='Calculation' >
											<exp exp='.i = .i + 1' />
										</command>
									</flowline>
								</command>
								<command class_type='call' title='Call Macro' macro='CalculateCRC' >
									<argument exp='16' />
								</command>
								<command class_type='call' title='Call Macro' macro='ToCard' >
									<return exp='.Return' />
									<argument exp='0x0C' />
									<argument exp='18' />
								</command>
							</flowline>
							<flowline />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='ReadDataBuffer' description='Reads a byte from the receive data buffer.
ID locations are 0-4
Data locations are 0-15' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Index' type='u8' description='Locations 0-15' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Return = BackData[.Index]' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='AntennaOff' description='Switches off the RFID antenna' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<local name='RegVal' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='Call Macro' macro='ClearBitMask' >
							<argument exp='0x14' />
							<argument exp='0x03' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='AntiColl' description='' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='SerNumCheck' type='u8' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<local name='i' type='u8' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<command class_type='call' title='Call Macro' macro='WriteRegister' >
							<argument exp='0x0D' />
							<argument exp='0x00' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='SendData[0] = 0x93' />
							<exp exp='SendData[1] = 0x20' />
						</command>
						<command class_type='call' title='Call Macro' macro='ToCard' >
							<return exp='.Return' />
							<argument exp='0x0C' />
							<argument exp='2' />
						</command>
						<command class_type='decision' title='Decision' exp='.Return = 0' swap='0' >
							<flowline >
								<command class_type='loop' title='Loop' type='0' exp='.i &lt; 4' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.SerNumCheck = .SerNumCheck ^ BackData[.i]' />
										</command>
										<command class_type='calculation' title='Calculation' >
											<exp exp='.i = .i + 1' />
										</command>
									</flowline>
								</command>
								<command class_type='decision' title='Decision' exp='.SerNumCheck != BackData[.i]' swap='0' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.Return = 255' />
										</command>
									</flowline>
									<flowline />
								</command>
							</flowline>
							<flowline />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='ReadBlock' description='Reads the contents of the 16-byte data buffer block on the RFID.
The receive data is stored in the data buffer and read back using the ReadDataBuffer macro.
Returns 0 for a succesful read.' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='BlockAddress' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='SendData[0] = 0x30' />
							<exp exp='SendData[1] = .BlockAddress' />
						</command>
						<command class_type='call' title='Call Macro' macro='CalculateCRC' >
							<argument exp='2' />
						</command>
						<command class_type='call' title='Call Macro' macro='ToCard' >
							<return exp='.Return' />
							<argument exp='0x0C' />
							<argument exp='4' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Halt' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='SendData[0] = 0x50' />
							<exp exp='SendData[1] = 0' />
						</command>
						<command class_type='call' title='Call Macro' macro='CalculateCRC' >
							<argument exp='2' />
						</command>
						<command class_type='call' title='Call Macro' macro='ToCard' >
							<argument exp='0x0C' />
							<argument exp='4' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='WriteDataBuffer' description='Writes a value to the 16-byte data buffer
ID locations are 0-4
Data locations are 0-15' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<param name='Index' type='u8' description='0-15' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Data' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='UserData[.Index] = .Data' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='SelectTag' description='' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Ser0' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Ser1' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Ser2' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Ser3' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Ser4' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='SendData[0] = 0x93' />
							<exp exp='SendData[1] = 0x70' />
							<exp exp='SendData[2] = .Ser0' />
							<exp exp='SendData[3] = .Ser1' />
							<exp exp='SendData[4] = .Ser2' />
							<exp exp='SendData[5] = .Ser3' />
							<exp exp='SendData[6] = .Ser4' />
						</command>
						<command class_type='call' title='Call Macro' macro='CalculateCRC' >
							<argument exp='7' />
						</command>
						<command class_type='call' title='Call Macro' macro='ToCard' >
							<return exp='.Return' />
							<argument exp='0x0C' />
							<argument exp='9' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='SetBitMask' description='Sets the specified bits in a register onboard the MFRC522 device' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<param name='Address' type='u8' description='Register Address' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Mask' type='u8' description='Bit mask to select which bits to modify 0=dont modify, 1=modify' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='RegVal' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='Read Register' macro='ReadRegister' >
							<return exp='.RegVal' />
							<argument exp='.Address' />
						</command>
						<command class_type='call' title='Write Register with modified value' macro='WriteRegister' >
							<argument exp='.Address' />
							<argument exp='.RegVal | .Mask' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Auth' description='' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='AuthMode' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='BlockAddress' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Key0' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Key1' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Key2' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Key3' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Key4' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Key5' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Ser0' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Ser1' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Ser2' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Ser3' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='SendData[0] = .AuthMode' />
							<exp exp='SendData[1] = .BlockAddress' />
							<exp exp='SendData[2] = .Key0' />
							<exp exp='SendData[3] = .Key1' />
							<exp exp='SendData[4] = .Key2' />
							<exp exp='SendData[5] = .Key3' />
							<exp exp='SendData[6] = .Key4' />
							<exp exp='SendData[7] = .Key5' />
							<exp exp='SendData[8] = .Ser0' />
							<exp exp='SendData[9] = .Ser1' />
							<exp exp='SendData[10] = .Ser2' />
							<exp exp='SendData[11] = .Ser3' />
						</command>
						<command class_type='call' title='Call Macro' macro='ToCard' >
							<return exp='.Return' />
							<argument exp='0x0E' />
							<argument exp='12' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='ClearBitMask' description='Clears the specified bits in a register onboard the MFRC522 device' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<param name='Address' type='u8' description='Register Address' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Mask' type='u8' description='Bit mask to select which bits to modify 0=dont modify, 1=modify' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='RegVal' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='Read Register' macro='ReadRegister' >
							<return exp='.RegVal' />
							<argument exp='.Address' />
						</command>
						<command class_type='call' title='Write Register with modified value' macro='WriteRegister' >
							<argument exp='.Address' />
							<argument exp='.RegVal &amp; (~.Mask)' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='ToCard' description='' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Command' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='sendLen' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='irqEn' type='u16' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<local name='waitIrq' type='u8' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<local name='i' type='u16' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<local name='n' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='lastBits' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='Error' >
							<exp exp='.Return = 255' />
						</command>
						<command class_type='switch' title='Switch' textarea='36,25,36,25' exp='.command' >
							<case >
								<flowline />
							</case>
							<case exp='0x0E' >
								<flowline >
									<command class_type='comment' title='' comment='Authent
' textarea='52,8,52,8' />
									<command class_type='calculation' title='Calculation' >
										<exp exp='.irqEn = 0x12' />
										<exp exp='.waitIrq = 0x10' />
									</command>
								</flowline>
							</case>
							<case exp='0x0C' >
								<flowline >
									<command class_type='comment' title='' comment='Transcieve' textarea='52,8,52,8' />
									<command class_type='calculation' title='Calculation' >
										<exp exp='.irqEn = 0x77' />
										<exp exp='.waitIrq = 0x30' />
									</command>
								</flowline>
							</case>
						</command>
						<command class_type='call' title='Call Macro' macro='WriteRegister' >
							<argument exp='0x02' />
							<argument exp='.irqEn | 0x80' />
						</command>
						<command class_type='call' title='Call Macro' macro='ClearBitMask' >
							<argument exp='0x04' />
							<argument exp='0x80' />
						</command>
						<command class_type='call' title='Call Macro' macro='SetBitMask' >
							<argument exp='0x0A' />
							<argument exp='0x80' />
						</command>
						<command class_type='call' title='Call Macro' macro='WriteRegister' >
							<argument exp='0x01' />
							<argument exp='0' />
						</command>
						<command class_type='loop' title='Writing data to FIFO' type='0' exp='.i &lt; .sendLen' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='WriteRegister' >
									<argument exp='0x09' />
									<argument exp='sendData[.i]' />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.i = .i + 1' />
								</command>
							</flowline>
						</command>
						<command class_type='call' title='Call Macro' macro='WriteRegister' >
							<argument exp='0x01' />
							<argument exp='.Command' />
						</command>
						<command class_type='decision' title='Transcieve?' exp='.Command = 0x0C' swap='0' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='SetBitMask' >
									<argument exp='0x0D' />
									<argument exp='0x80' />
								</command>
							</flowline>
							<flowline />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.i = 2000' />
						</command>
						<command class_type='loop' title='Loop' type='0' exp='1' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='ReadRegister' >
									<return exp='.n' />
									<argument exp='0x04' />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.i = .i - 1' />
								</command>
								<command class_type='decision' title='Decision' exp='.i = 0' swap='0' >
									<flowline >
										<command class_type='goto' title='Goto Connection Point' labelid='0' labelname='' />
									</flowline>
									<flowline >
										<command class_type='decision' title='Decision' exp='.n &amp; 0x01' swap='0' >
											<flowline >
												<command class_type='goto' title='Goto Connection Point' labelid='0' labelname='' />
											</flowline>
											<flowline >
												<command class_type='decision' title='Decision' exp='.n &amp; .waitIrq' swap='0' >
													<flowline >
														<command class_type='goto' title='Goto Connection Point' labelid='0' labelname='' />
													</flowline>
													<flowline />
												</command>
											</flowline>
										</command>
									</flowline>
								</command>
							</flowline>
						</command>
						<command class_type='label' title='Connection Point' labelid='0' labelname='A' />
						<command class_type='call' title='Call Macro' macro='ClearBitMask' >
							<argument exp='0x0D' />
							<argument exp='0x80' />
						</command>
						<command class_type='decision' title='Decision' exp='.i != 0' swap='0' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='ReadRegister' >
									<return exp='.i' />
									<argument exp='0x06' />
								</command>
								<command class_type='decision' title='Decision' exp='! (.i &amp; 0x1B)' swap='0' >
									<flowline >
										<command class_type='calculation' title='OK' >
											<exp exp='.Return = 0' />
										</command>
										<command class_type='decision' title='Decision' exp='.n &amp; .irqEn &amp; 0x01' swap='0' >
											<flowline >
												<command class_type='calculation' title='NOTAGERR' >
													<exp exp='.Return = 1' />
												</command>
											</flowline>
											<flowline />
										</command>
										<command class_type='decision' title='Decision' exp='.Command = 0x0C' swap='0' >
											<flowline >
												<command class_type='call' title='Call Macro' macro='ReadRegister' >
													<return exp='.n' />
													<argument exp='0x0A' />
												</command>
												<command class_type='call' title='Call Macro' macro='ReadRegister' >
													<return exp='.lastBits' />
													<argument exp='0x0C' />
												</command>
												<command class_type='calculation' title='Calculation' >
													<exp exp='.lastBits = .lastBits &amp; 0x07' />
												</command>
												<command class_type='decision' title='Decision' exp='.lastBits' swap='0' >
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='BackLen = (.n - 1) * 8 + .lastBits' />
														</command>
													</flowline>
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='BackLen = .n * 8' />
														</command>
													</flowline>
												</command>
												<command class_type='decision' title='Decision' exp='.n = 0' swap='0' >
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='.n = 1' />
														</command>
													</flowline>
													<flowline />
												</command>
												<command class_type='decision' title='Decision' exp='.n &gt; 16' swap='0' >
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='.n = 16' />
														</command>
													</flowline>
													<flowline />
												</command>
												<command class_type='calculation' title='Calculation' >
													<exp exp='.i = 0' />
												</command>
												<command class_type='loop' title='Loop' type='0' exp='.i &lt; .n' >
													<flowline >
														<command class_type='call' title='Call Macro' macro='ReadRegister' >
															<return exp='BackData[.i]' />
															<argument exp='0x09' />
														</command>
														<command class_type='calculation' title='Calculation' >
															<exp exp='.i = .i + 1' />
														</command>
													</flowline>
												</command>
											</flowline>
											<flowline />
										</command>
									</flowline>
									<flowline >
										<command class_type='calculation' title='Error' >
											<exp exp='.Return = 255' />
										</command>
									</flowline>
								</command>
							</flowline>
							<flowline />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Request' description='' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='ReqMode' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='Call Macro' macro='WriteRegister' >
							<argument exp='0x0D' />
							<argument exp='0x07' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='SendData[0] = .ReqMode' />
						</command>
						<command class_type='call' title='Call Macro' macro='ToCard' >
							<return exp='.Return' />
							<argument exp='0x0C' />
							<argument exp='1' />
						</command>
						<command class_type='decision' title='Decision' exp='.Return != 0' swap='0' >
							<flowline >
								<command class_type='calculation' title='Error' >
									<exp exp='.Return = 255' />
								</command>
							</flowline>
							<flowline />
						</command>
						<command class_type='decision' title='Decision' exp='BackLen != 0x10' swap='0' >
							<flowline >
								<command class_type='calculation' title='Error' >
									<exp exp='.Return = 255' />
								</command>
							</flowline>
							<flowline />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='ReadRegister' description='Returns a value from a register onboard the MFRC522 device' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Address' type='u8' description='Register Address' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='CS = 0' />
						</command>
						<command class_type='call' title='Call Component Macro' component='cal_spi1' macro='Master_Byte' >
							<argument exp='((.Address &lt;&lt; 1) &amp; 0x7E) | 0x80' />
						</command>
						<command class_type='call' title='Call Component Macro' component='cal_spi1' macro='Master_Byte' >
							<return exp='.Return' />
							<argument exp='0' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='CS = 1' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='CalculateCRC' description='' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<param name='Offset' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='i' type='u8' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<local name='n' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='Call Macro' macro='ClearBitMask' >
							<argument exp='0x05' />
							<argument exp='0x04' />
						</command>
						<command class_type='call' title='Call Macro' macro='SetBitMask' >
							<argument exp='0x0A' />
							<argument exp='0x80' />
						</command>
						<command class_type='loop' title='Loop' type='0' exp='.i &lt; .Offset' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='WriteRegister' >
									<argument exp='0x09' />
									<argument exp='SendData[.i]' />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.i = .i + 1' />
								</command>
							</flowline>
						</command>
						<command class_type='call' title='Call Macro' macro='WriteRegister' >
							<argument exp='0x01' />
							<argument exp='0x03' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.i = 255' />
						</command>
						<command class_type='loop' title='Loop' type='0' exp='.i &gt; 0' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='ReadRegister' >
									<return exp='.n' />
									<argument exp='0x05' />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.i = .i - 1' />
								</command>
								<command class_type='decision' title='Decision' exp='.n &amp; 0x04' swap='0' >
									<flowline >
										<command class_type='goto' title='Goto Connection Point' labelid='0' labelname='' />
									</flowline>
									<flowline />
								</command>
							</flowline>
						</command>
						<command class_type='label' title='Connection Point' labelid='0' labelname='A' />
						<command class_type='call' title='Call Macro' macro='ReadRegister' >
							<return exp='SendData[.Offset]' />
							<argument exp='0x22' />
						</command>
						<command class_type='call' title='Call Macro' macro='ReadRegister' >
							<return exp='SendData[.Offset + 1]' />
							<argument exp='0x21' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='AntennaOn' description='Switches on the RFID antenna' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<local name='RegVal' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='Read Register' macro='ReadRegister' >
							<return exp='.RegVal' />
							<argument exp='0x14' />
						</command>
						<command class_type='decision' title='Decision' exp='! (.RegVal &amp; 0x03)' swap='0' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='SetBitMask' >
									<argument exp='0x14' />
									<argument exp='0x03' />
								</command>
							</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='call' title='Call Component Macro' component='lcd_eb005' macro='Start' />
						<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintString' >
							<argument exp='&quot;Init ... &quot;' />
						</command>
						<command class_type='call' title='Call Macro' macro='Initialise' />
						<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintString' >
							<argument exp='&quot;OK&quot;' />
						</command>
						<command class_type='delay' title='Delay' exp='1' type='2' />
						<command class_type='loop' title='Loop' type='0' exp='1' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='Check' >
									<return exp='Card' />
								</command>
								<command class_type='decision' title='Decision' exp='Card = 0' swap='0' >
									<flowline >
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='Clear' />
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintString' >
											<argument exp='&quot;Detected&quot;' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='Cursor' >
											<argument exp='0' />
											<argument exp='1' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintNumber' >
											<argument exp='BackData[0]' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintAscii' >
											<argument exp='&apos;,&apos;' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintNumber' >
											<argument exp='BackData[1]' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintAscii' >
											<argument exp='&apos;,&apos;' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintNumber' >
											<argument exp='BackData[2]' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintAscii' >
											<argument exp='&apos;,&apos;' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintNumber' >
											<argument exp='BackData[3]' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintAscii' >
											<argument exp='&apos;,&apos;' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintNumber' >
											<argument exp='BackData[4]' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintAscii' >
											<argument exp='&apos;,&apos;' />
										</command>
										<command class_type='delay' title='Delay' exp='200' type='1' />
									</flowline>
									<flowline >
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='Clear' />
									</flowline>
								</command>
							</flowline>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='WriteRegister' description='Writes a value to a register onboard the MFRC522 device' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<param name='Address' type='u8' description='Register Address' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Value' type='u8' description='Data to write to the register' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='CS = 0' />
						</command>
						<command class_type='call' title='Call Component Macro' component='cal_spi1' macro='Master_Byte' >
							<argument exp='(.Address &lt;&lt; 1) &amp; 0x7E' />
						</command>
						<command class_type='call' title='Call Component Macro' component='cal_spi1' macro='Master_Byte' >
							<argument exp='.Value' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='CS = 1' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Compare' description='Compares the read address from the Check macro with a fixed 5 bytes address.
Returns 0 if the addresses match.' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Add0' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Add1' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Add2' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Add3' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='Add4' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='i' type='u8' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Return = 255' />
						</command>
						<command class_type='decision' title='Decision' exp='.Add0 = BackData[0]' swap='0' >
							<flowline >
								<command class_type='decision' title='Decision' exp='.Add1 = BackData[1]' swap='0' >
									<flowline >
										<command class_type='decision' title='Decision' exp='.Add2 = BackData[2]' swap='0' >
											<flowline >
												<command class_type='decision' title='Decision' exp='.Add3 = BackData[3]' swap='0' >
													<flowline >
														<command class_type='decision' title='Decision' exp='.Add4 = BackData[4]' swap='0' >
															<flowline >
																<command class_type='calculation' title='Calculation' >
																	<exp exp='.Return = 0' />
																</command>
															</flowline>
															<flowline />
														</command>
													</flowline>
													<flowline />
												</command>
											</flowline>
											<flowline />
										</command>
									</flowline>
									<flowline />
								</command>
							</flowline>
							<flowline />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Initialise' description='Initialises the RFID module ready for interaction with RFID tags.' >
						<return name='Return' type='v0' description='' isconst='0' isinit='0' usrinit='' setinit='' />
						<command class_type='calculation' title='Bring device out of reset' >
							<exp exp='cs = 1' />
							<exp exp='reset = 1' />
						</command>
						<command class_type='delay' title='Delay' exp='1' type='1' />
						<command class_type='calculation' title='Force reset' >
							<exp exp='reset = 0' />
						</command>
						<command class_type='delay' title='Delay' exp='100' type='1' />
						<command class_type='call' title='Call Component Macro' component='cal_spi1' macro='Master_Init' />
						<command class_type='calculation' title='Force reset' >
							<exp exp='reset = 1' />
						</command>
						<command class_type='delay' title='Delay' exp='100' type='1' />
						<command class_type='call' title='Reset Module' macro='Reset' />
						<command class_type='call' title='Set TModeReg' macro='WriteRegister' >
							<argument exp='0x2A' />
							<argument exp='0x8D' />
						</command>
						<command class_type='call' title='Set TPrescalerReg' macro='WriteRegister' >
							<argument exp='0x2B' />
							<argument exp='0x3E' />
						</command>
						<command class_type='call' title='Set TReloadRegH' macro='WriteRegister' >
							<argument exp='0x2D' />
							<argument exp='30' />
						</command>
						<command class_type='call' title='Set TReloadRegL' macro='WriteRegister' >
							<argument exp='0x2C' />
							<argument exp='0' />
						</command>
						<command class_type='call' title='Set TxAutoReg' macro='WriteRegister' >
							<argument exp='0x26' />
							<argument exp='0x70' />
						</command>
						<command class_type='call' title='Set TxAutoReg' macro='WriteRegister' >
							<argument exp='0x15' />
							<argument exp='0x40' />
						</command>
						<command class_type='call' title='Set ModeReg' macro='WriteRegister' >
							<argument exp='0x11' />
							<argument exp='0x3D' />
						</command>
						<command class_type='call' title='Switch on Antenna' macro='AntennaOn' />
					</flowline>
				</macro>
				<macro >
					<flowline name='Check' description='' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='Call Macro' macro='Request' >
							<return exp='.Return' />
							<argument exp='0x26' />
						</command>
						<command class_type='decision' title='Decision' exp='.Return = 0' swap='0' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='AntiColl' >
									<return exp='.Return' />
								</command>
							</flowline>
							<flowline />
						</command>
						<command class_type='call' title='Call Macro' macro='Halt' />
					</flowline>
				</macro>
			</macros>
			<component class_type='ref' guid='c67171df-0ad6-4b11-8361-cfe14b072847' vmin='1' vmaj='1' codename='cal_spi1' x='27.8744' y='44.0841' z='0' xsz='16' ysz='16' zsz='16' 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='ENABLED' data='1' />
					<value target='REF' data='1' />
					<value target='CHANNEL' data='001' />
					<value target='MOSI' data='$PORTB.10' />
					<value target='MOSIPins' data='010' />
					<value target='MISO' data='$PORTB.11' />
					<value target='MISOPins' data='011' />
					<value target='CLK' data='$PORTB.9' />
					<value target='CLKPins' data='009' />
					<value target='SS' data='' />
					<value target='PR_SCALE' data='016' />
					<value target='BMODE' data='5' />
					<value target='CKP' data='001' />
					<value target='CKE' data='000' />
					<value target='SMP' data='001' />
					<value target='MOSI_PORT' data='$PORTB.10' />
					<value target='MOSI_TRIS' data='$PORTB.10' />
					<value target='MOSI_PIN' data='10' />
					<value target='MISO_PORT' data='$PORTB.11' />
					<value target='MISO_TRIS' data='$PORTB.11' />
					<value target='MISO_PIN' data='11' />
					<value target='SCK_PORT' data='$PORTB.9' />
					<value target='SCK_TRIS' data='$PORTB.9' />
					<value target='SCK_PIN' data='9' />
					<value target='SS_PORT' data='' />
					<value target='SS_TRIS' data='' />
					<value target='SS_PIN' data='0' />
					<value target='Remappable' data='1' />
					<value target='MOSIReg' data='010' />
					<value target='CLKREG' data='009' />
					<value target='MOSIRPNUM' data='7' />
					<value target='CLKRPNUM' data='8' />
					<value target='MISORPREG' data='RPINR20bits.SDI1R' />
					<value target='CS_PORT' data='' />
					<value target='ScopeTraces' data='0' />
					<value target='ConsoleData' data='0' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
			<component class_type='ref' guid='d29dda88-17de-4008-991a-c881890d4c57' vmin='1' vmaj='1' codename='lcd_eb005' x='28.4763' y='74.7779' z='3.575' 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>
	</components>
	<keymap />
	<panel2d shadows='0' lighting='2' brightness='0' perspective='0' >
		<background rgb='5767167' 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='28' />
		<camera xe='29' ye='64' ze='108.345' xt='29' yt='64' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
	</panel3d>
	<layout >
		<view type='0' name='Main' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='SelectTag' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Auth' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='ToCard' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='1522' flags='0' />
		<view type='0' name='Compare' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='30' flags='0' />
		<view type='0' name='ReadBlock' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='WriteBlock' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Check' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='AntiColl' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Request' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='WriteRegister' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='WriteDataBuffer' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='ReadDataBuffer' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='CalculateCRC' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Halt' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAANgQAALkDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
	</layout>
</document>
</root>
