<root>
<document schema='101' license='1,Ben Rowland,XHZ9AR' 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='monitor' value='1' />
			<data name='ictloop' value='1' />
			<data name='ictrate' value='1000' />
			<data name='ictmask' 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' 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' 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 />
			<variables >
				<variable public='0' >
					<def class_type='variable' name='Tag' 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='SerialNumber' type='u8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='5' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='TxControlReg' type='s16' description='' isconst='1' isinit='1' usrinit='20' setinit='0x14' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='Buffer' type='T8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
						<array size='18' />
					</def>
				</variable>
				<variable public='0' >
					<def class_type='variable' name='RetCount' type='u16' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
				</variable>
				<variable public='0' >
					<def class_type='variable' name='true' type='b1' description='' isconst='1' isinit='1' usrinit='1' setinit='1' />
				</variable>
			</variables>
			<macros >
				<macro >
					<flowline name='ClearBitReg' description='Clears the specified bits in a register onboard the MFRC522 device' >
						<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='ReadReg' >
							<return exp='.RegVal' />
							<argument exp='.Address' />
						</command>
						<command class_type='call' title='Write Register with modified value' macro='WriteReg' >
							<argument exp='.Address' />
							<argument exp='.RegVal &amp; (~.Mask)' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Reset' description='Resets the MFRC522 device' >
						<command class_type='call' title='CommandReg' macro='WriteReg' >
							<argument exp='0x01' />
							<argument exp='0x0F' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='CheckTag' description='Checks to see if a tag is detected by the RFID module' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='status' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='PICC_REQIDL' macro='RequestTagType' >
							<return exp='.status' />
							<argument exp='0x26' />
						</command>
						<command class_type='decision' title='Decision' exp='.Status = 0' swap='0' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Return = 1' />
								</command>
							</flowline>
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Return = 0' />
								</command>
							</flowline>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='RequestTagType' description='Checks to see what type of tag has been detected by the module.
Returns 0 for success and 1 for error.
Populates the TagType string with the tag code.
' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='RequestMode' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='Status' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='BitFramingReg' macro='WriteReg' >
							<argument exp='0x0D' />
							<argument exp='0x07' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='Buffer[0] = .RequestMode' />
						</command>
						<command class_type='call' title='PCD_TRANSCEIVE' macro='SendToTag' >
							<return exp='.Status' />
							<argument exp='0x0C' />
							<argument exp='1' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='SerialNumber[0] = Buffer[0]' />
							<exp exp='SerialNumber[1] = Buffer[1]' />
							<exp exp='SerialNumber[2] = Buffer[2]' />
							<exp exp='SerialNumber[3] = Buffer[3]' />
							<exp exp='SerialNumber[4] = Buffer[4]' />
						</command>
						<command class_type='decision' title='Decision' exp='(.Status != 0) || (RetCount != 0x10)' swap='0' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Return = 1' />
								</command>
							</flowline>
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Return = 0' />
								</command>
							</flowline>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='AntennaOff' description='Switches off the RFID antenna' >
						<local name='RegVal' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='Call Macro' macro='ClearBitReg' >
							<argument exp='TxControlReg' />
							<argument exp='0x03' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='ReadReg' 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='0xFF' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='CS = 1' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='WriteReg' description='Writes a value to a register onboard the MFRC522 device' >
						<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='SendToTag' description='Sends data to the tag' >
						<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='SendLength' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='Status' type='u8' description='' isconst='0' isinit='1' usrinit='1' setinit='1' />
						<local name='IrqEn' type='u8' 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='LastBits' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='IrqCheck' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='Index' type='u16' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='Error' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='Calculation' >
							<exp exp='.status = 1' />
						</command>
						<command class_type='switch' title='Switch' textarea='36,25,36,25' exp='.Command' >
							<case >
								<flowline />
							</case>
							<case exp='0x0E' >
								<flowline >
									<command class_type='calculation' title='Calculation' >
										<exp exp='.IrqEn = 0x12' />
										<exp exp='.WaitIrq = 0x10' />
									</command>
								</flowline>
							</case>
							<case exp='0x0C' >
								<flowline >
									<command class_type='calculation' title='Calculation' >
										<exp exp='.IrqEn = 0x77' />
										<exp exp='.WaitIrq = 0x30' />
									</command>
								</flowline>
							</case>
						</command>
						<command class_type='call' title='CommIEnReg' macro='WriteReg' >
							<argument exp='0x02' />
							<argument exp='.IrqEn | 0x80' />
						</command>
						<command class_type='call' title='CommIrqReg' macro='ClearBitReg' >
							<argument exp='0x04' />
							<argument exp='0x80' />
						</command>
						<command class_type='call' title='FIFOLevelReg' macro='SetBitReg' >
							<argument exp='0x0A' />
							<argument exp='0x80' />
						</command>
						<command class_type='call' title='CommandReg' macro='WriteReg' >
							<argument exp='0x01' />
							<argument exp='0x00' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Index = 0' />
						</command>
						<command class_type='loop' title='Loop' exp='.Index &lt; .SendLength' type='0' start='1' count='1' breakend='0' >
							<flowline >
								<command class_type='call' title='FIFODataReg' macro='WriteReg' >
									<argument exp='0x09' />
									<argument exp='Buffer[.Index]' />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Index = .Index + 1' />
								</command>
							</flowline>
						</command>
						<command class_type='call' title='Call Macro' macro='WriteReg' >
							<argument exp='0x01' />
							<argument exp='.Command' />
						</command>
						<command class_type='decision' title='PCD_TRANSCEIVE?' exp='.Command = 0x0C' swap='0' >
							<flowline >
								<command class_type='call' title='BitFramingReg' macro='SetBitReg' >
									<argument exp='0x0D' />
									<argument exp='0x80' />
								</command>
							</flowline>
							<flowline />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Index = 2000' />
						</command>
						<command class_type='loop' title='Loop' exp='((.Index != 0) &amp;&amp; ! (.IrqCheck &amp; 0x01) &amp;&amp; ! (.IrqCheck &amp; .WaitIrq))' type='0' start='0' count='1' breakend='0' >
							<flowline >
								<command class_type='call' title='CommIrqReg' macro='ReadReg' >
									<return exp='.IrqCheck' />
									<argument exp='0x04' />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Index = .Index - 1' />
								</command>
							</flowline>
						</command>
						<command class_type='call' title='BitFramingReg' macro='ClearBitReg' >
							<argument exp='0x0D' />
							<argument exp='0x80' />
						</command>
						<command class_type='decision' title='Decision' exp='.Index != 0' swap='0' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='ReadReg' >
									<return exp='.Error' />
									<argument exp='0x06' />
								</command>
								<command class_type='decision' title='Decision' exp='! (.Error &amp; 0x1B)' swap='0' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.Status = 0' />
										</command>
										<command class_type='decision' title='Decision' exp='.IrqCheck &amp; .IrqEn &amp; 0x01' swap='0' >
											<flowline >
												<command class_type='calculation' title='Calculation' >
													<exp exp='.Status = 1' />
												</command>
											</flowline>
											<flowline />
										</command>
										<command class_type='decision' title='PCD_TRANSCEIVE' exp='.Command = 0x0C' swap='0' >
											<flowline >
												<command class_type='call' title='FIFOLevelReg' macro='ReadReg' >
													<return exp='.IrqCheck' />
													<argument exp='0x0A' />
												</command>
												<command class_type='call' title='ControlReg' macro='ReadReg' >
													<return exp='.LastBits' />
													<argument exp='0x0C' />
												</command>
												<command class_type='decision' title='Decision' exp='.LastBits &amp; 0x07' swap='0' >
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='RetCount = (.IrqCheck - 1) * 8 + (.LastBits &amp; 0x07)' />
														</command>
													</flowline>
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='RetCount = .IrqCheck * 8' />
														</command>
													</flowline>
												</command>
												<command class_type='decision' title='Decision' exp='.IrqCheck = 0' swap='0' >
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='.IrqCheck = 1' />
														</command>
													</flowline>
													<flowline />
												</command>
												<command class_type='decision' title='Decision' exp='.IrqCheck &gt; 16' swap='0' >
													<flowline >
														<command class_type='calculation' title='Calculation' >
															<exp exp='.IrqCheck = 16' />
														</command>
													</flowline>
													<flowline />
												</command>
												<command class_type='calculation' title='Calculation' >
													<exp exp='.Index = 0' />
												</command>
												<command class_type='loop' title='Loop' exp='.Index &lt; .IrqCheck' type='0' start='1' count='1' breakend='0' >
													<flowline >
														<command class_type='call' title='FIFODataReg' macro='ReadReg' >
															<return exp='Buffer[.Index]' />
															<argument exp='0x09' />
														</command>
														<command class_type='calculation' title='Calculation' >
															<exp exp='.Index = .Index + 1' />
														</command>
													</flowline>
												</command>
											</flowline>
											<flowline />
										</command>
									</flowline>
									<flowline />
								</command>
							</flowline>
							<flowline />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Return = .Status' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Read' description='Reads a data block from the tag
Returns 0 for success and 1 for failure' >
						<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='Status' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='Buffer' type='T8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='18' />
						</local>
						<command class_type='calculation' title='PICC_READ' >
							<exp exp='Buffer[0] = 0x30' />
							<exp exp='Buffer[1] = .BlockAddress' />
						</command>
						<command class_type='call' title='Call Macro' macro='CalculateCRC' >
							<argument exp='2' />
						</command>
						<command class_type='call' title='PCD_TRANSCEIVE' macro='SendToTag' >
							<return exp='.Status' />
							<argument exp='0x0C' />
							<argument exp='4' />
						</command>
						<command class_type='decision' title='Decision' exp='(.Status != 0) || (RetCount != 0x90)' swap='0' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Return = 1' />
								</command>
							</flowline>
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Return = 0' />
								</command>
							</flowline>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Sleep' description='Temporarily powers down the MFRC522 device into low power mode' >
						<local name='Status' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='PICC_HALT' >
							<exp exp='Buffer[0] = 0x50' />
							<exp exp='Buffer[1] = 0' />
						</command>
						<command class_type='call' title='Call Macro' macro='CalculateCRC' >
							<argument exp='2' />
						</command>
						<command class_type='call' title='PCD_TRANSCEIVE' macro='SendToTag' >
							<return exp='.Status' />
							<argument exp='0x0C' />
							<argument exp='4' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='SetBitReg' description='Sets the specified bits in a register onboard the MFRC522 device' >
						<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='ReadReg' >
							<return exp='.RegVal' />
							<argument exp='.Address' />
						</command>
						<command class_type='call' title='Write Register with modified value' macro='WriteReg' >
							<argument exp='.Address' />
							<argument exp='.RegVal | .Mask' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='AntiCollision' description='Anti-collision detection, reading the serial number of the card board
Returns the number of bytes serial card 4, the first 5 bytes of parity bytes
Returns 0 for success and 1 for failure' >
						<return name='Return' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<param name='SerialNumber' type='T8*' description='Variable to store the returned serial number data' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='20' />
						</param>
						<local name='Status' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='Index' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='SerialNumberCheck' type='u8' description='' isconst='0' isinit='1' usrinit='0' setinit='0' />
						<local name='Length' type='u16' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='BitFramingReg' macro='WriteReg' >
							<argument exp='0x0D' />
							<argument exp='0x00' />
						</command>
						<command class_type='calculation' title='PICC_ANTICOLL' >
							<exp exp='Buffer[0] = 0x93' />
							<exp exp='Buffer[1] = 0x20' />
						</command>
						<command class_type='call' title='PCD_TRANSCEIVE' macro='SendToTag' >
							<return exp='.Status' />
							<argument exp='0x0C' />
							<argument exp='2' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Return = 1' />
						</command>
						<command class_type='decision' title='Decision' exp='.Status = 0' swap='0' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Index = 0' />
								</command>
								<command class_type='loop' title='Loop' exp='.Index &lt; 4' type='0' start='1' count='1' breakend='0' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.SerialNumberCheck = .SerialNumberCheck ^ Buffer[.Index]' />
										</command>
										<command class_type='calculation' title='Calculation' >
											<exp exp='.Index = .Index + 1' />
											<exp exp='' />
										</command>
									</flowline>
								</command>
								<command class_type='decision' title='Decision' exp='.SerialNumberCheck != Buffer[.Index]' swap='0' >
									<flowline />
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.Return = 0' />
										</command>
									</flowline>
								</command>
							</flowline>
							<flowline />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Authenticate' description='Check card password
Returns 0 for success and 1 for failure
' >
						<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='SectorKey' type='T8*' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='20' />
						</param>
						<param name='SerialNumber' type='T8*' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='20' />
						</param>
						<local name='Status' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='Index' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='ReceiveBits' type='u16' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='Buffer' type='T8' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='20' />
						</local>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Buffer[0] = .AuthMode' />
							<exp exp='.Buffer[1] = .BlockAddress' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Index = 0' />
						</command>
						<command class_type='loop' title='Loop' exp='.Index &lt; 6' type='0' start='1' count='1' breakend='0' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Buffer[.Index + 2] = .SectorKey[.Index]' />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Index = .Index + 1' />
									<exp exp='' />
								</command>
							</flowline>
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Index = 0' />
						</command>
						<command class_type='loop' title='Loop' exp='.Index &lt; 4' type='0' start='1' count='1' breakend='0' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Buffer[.Index + 8] = .SerialNumber[.Index]' />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Index = .Index + 1' />
									<exp exp='' />
								</command>
							</flowline>
						</command>
						<command class_type='call' title='PCD_AUTHENT' macro='SendToTag' >
							<return exp='.Status' />
							<argument exp='0x0E' />
							<argument exp='12' />
						</command>
						<command class_type='call' title='Call Macro' macro='ReadReg' >
							<return exp='.Index' />
							<argument exp='0x08' />
						</command>
						<command class_type='decision' title='Decision' exp='(.Status != 0) || (! (.Index &amp; 0x08))' swap='0' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Return = 1' />
								</command>
							</flowline>
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Return = 0' />
								</command>
							</flowline>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Write' description='Writes a data block to the tag
Returns 0 for success and 1 for failure' >
						<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='' />
						<param name='WriteData' type='T8*' description='' isconst='0' isinit='0' usrinit='&quot;&quot;' setinit='' >
							<array size='20' />
						</param>
						<local name='Status' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='Index' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='calculation' title='PICC_WRITE' >
							<exp exp='Buffer[0] = 0xA0' />
							<exp exp='Buffer[1] = .BlockAddress' />
						</command>
						<command class_type='call' title='Call Macro' macro='CalculateCRC' >
							<argument exp='2' />
						</command>
						<command class_type='call' title='PCD_TRANSCEIVE' macro='SendToTag' >
							<return exp='.Status' />
							<argument exp='0x0C' />
							<argument exp='4' />
						</command>
						<command class_type='decision' title='Decision' exp='((.Status != 0) || (RetCount != 4) || ((Buffer[0] &amp; 0x0F) != 0x0A))' swap='0' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Status = 1' />
								</command>
							</flowline>
							<flowline />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Return = 1' />
						</command>
						<command class_type='decision' title='Decision' exp='.Status = 0' swap='0' >
							<flowline >
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Index = 0' />
								</command>
								<command class_type='loop' title='Loop' exp='.Index &lt; 16' type='0' start='1' count='1' breakend='0' >
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='Buffer[.Index] = .WriteData[.Index]' />
										</command>
										<command class_type='calculation' title='Calculation' >
											<exp exp='.Index = .Index + 1' />
										</command>
									</flowline>
								</command>
								<command class_type='call' title='Call Macro' macro='CalculateCRC' >
									<argument exp='16' />
								</command>
								<command class_type='call' title='PCD_TRANSCEIVE' macro='SendToTag' >
									<return exp='.Status' />
									<argument exp='0x0C' />
									<argument exp='18' />
								</command>
								<command class_type='decision' title='Decision' exp='((.Status != 0) || (RetCount != 4) || ((Buffer[0] &amp; 0x0F) != 0x0A))' swap='0' >
									<flowline />
									<flowline >
										<command class_type='calculation' title='Calculation' >
											<exp exp='.Return = 0' />
										</command>
									</flowline>
								</command>
							</flowline>
							<flowline />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='CalculateCRC' description='Works out the correct CRC based on data in and out of the module' >
						<param name='Length' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<local name='Index' type='u8' description='' 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='DivIrqReg' macro='ClearBitReg' >
							<argument exp='0x05' />
							<argument exp='0x04' />
						</command>
						<command class_type='call' title='FIFOLevelReg' macro='SetBitReg' >
							<argument exp='0x0A' />
							<argument exp='0x80' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Index = 0' />
						</command>
						<command class_type='loop' title='Loop' exp='.Index &lt; .Length' type='0' start='1' count='1' breakend='0' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='WriteReg' >
									<argument exp='0x09' />
									<argument exp='Buffer[.Index]' />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Index = .Index + 1' />
								</command>
							</flowline>
						</command>
						<command class_type='call' title='CommandReg' macro='WriteReg' >
							<argument exp='0x01' />
							<argument exp='0x03' />
						</command>
						<command class_type='calculation' title='Calculation' >
							<exp exp='.Index = 0xFF' />
							<exp exp='' />
						</command>
						<command class_type='loop' title='Loop' exp='.Index &gt; 0' type='0' start='1' count='1' breakend='0' >
							<flowline >
								<command class_type='call' title='DivIrqReg' macro='ReadReg' >
									<return exp='.RegVal' />
									<argument exp='0x05' />
								</command>
								<command class_type='decision' title='Decision' exp='.RegVal &amp; 0x04' swap='0' >
									<flowline >
										<command class_type='goto' title='Goto Connection Point' labelid='0' labelname='' />
									</flowline>
									<flowline />
								</command>
								<command class_type='calculation' title='Calculation' >
									<exp exp='.Index = .Index - 1' />
								</command>
							</flowline>
						</command>
						<command class_type='label' title='Connection Point' labelid='0' labelname='A' />
						<command class_type='call' title='CRCResultRegL' macro='ReadReg' >
							<return exp='Buffer[.Length]' />
							<argument exp='0x22' />
						</command>
						<command class_type='call' title='CRCResultRegM' macro='ReadReg' >
							<return exp='Buffer[.Length + 1]' />
							<argument exp='0x21' />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='AntennaOn' description='Switches on the RFID antenna' >
						<local name='RegVal' type='u8' description='' isconst='0' isinit='0' usrinit='0' setinit='' />
						<command class_type='call' title='Read Register' macro='ReadReg' >
							<return exp='.RegVal' />
							<argument exp='TxControlReg' />
						</command>
						<command class_type='decision' title='Decision' exp='! (.RegVal &amp; 0x03)' swap='0' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='SetBitReg' >
									<argument exp='TxControlReg' />
									<argument exp='0x03' />
								</command>
							</flowline>
							<flowline />
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Main' description='' >
						<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;Done&quot;' />
						</command>
						<command class_type='delay' title='Delay' exp='1' type='2' />
						<command class_type='loop' title='Loop' exp='1' type='0' start='1' count='1' breakend='0' >
							<flowline >
								<command class_type='call' title='Call Macro' macro='CheckTag' >
									<return exp='Tag' />
								</command>
								<command class_type='decision' title='Decision' exp='Tag' 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='PrintNumber' >
											<argument exp='Buffer[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='Buffer[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='Buffer[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='Buffer[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='Buffer[4]' />
										</command>
										<command class_type='call' title='Call Macro' macro='Read' >
											<return exp='Tag' />
											<argument exp='1' />
										</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='Tag' />
										</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='Buffer[0]' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintAscii' >
											<argument exp='&apos;,&apos;' />
										</command>
										<command class_type='calculation' title='Calculation' >
											<exp exp='Buffer[0] = Buffer[0] + 1' />
										</command>
										<command class_type='call' title='Call Macro' macro='Write' >
											<return exp='Tag' />
											<argument exp='1' />
											<argument exp='Buffer' />
										</command>
										<command class_type='call' title='Call Component Macro' component='lcd_eb005' macro='PrintNumber' >
											<argument exp='Tag' />
										</command>
									</flowline>
									<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;No Tag&quot;' />
										</command>
									</flowline>
								</command>
								<command class_type='call' title='Call Macro' macro='Sleep' />
								<command class_type='delay' title='Delay' exp='100' type='1' />
							</flowline>
						</command>
					</flowline>
				</macro>
				<macro >
					<flowline name='Initialise' description='Initialises the RFID module ready for interaction with RFID tags.' >
						<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='WriteReg' >
							<argument exp='0x2A' />
							<argument exp='0x8D' />
						</command>
						<command class_type='call' title='Set TPrescalerReg' macro='WriteReg' >
							<argument exp='0x2B' />
							<argument exp='0x3E' />
						</command>
						<command class_type='call' title='Set TReloadRegL' macro='WriteReg' >
							<argument exp='0x2D' />
							<argument exp='0x30' />
						</command>
						<command class_type='call' title='Set TReloadRegH' macro='WriteReg' >
							<argument exp='0x2C' />
							<argument exp='0x00' />
						</command>
						<command class_type='call' title='Set TxAutoReg' macro='WriteReg' >
							<argument exp='0x15' />
							<argument exp='0x40' />
						</command>
						<command class_type='call' title='Set ModeReg' macro='WriteReg' >
							<argument exp='0x2A' />
							<argument exp='0x3D' />
						</command>
						<command class_type='call' title='Switch on Antenna' macro='AntennaOn' />
					</flowline>
				</macro>
			</macros>
			<component class_type='ref' guid='c67171df-0ad6-4b11-8361-cfe14b072847' vmin='0' vmaj='1' codename='cal_spi1' x='55.8115' y='18.1268' 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='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='0' />
					<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' />
				</values>
				<events />
				<apis />
				<variables />
				<macros />
			</component>
			<component class_type='ref' guid='d29dda88-17de-4008-991a-c881890d4c57' vmin='1' vmaj='1' codename='lcd_eb005' x='52.2338' y='47.9407' z='3.775' 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='36' ye='42' ze='156.666' xt='36' yt='42' zt='0' xquat='0' yquat='0' zquat='0' wquat='1' />
	</panel3d>
	<layout >
		<view type='0' name='Main' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Read' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='RequestTagType' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='CheckTag' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='CalculateCRC' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Write' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='506' flags='0' />
		<view type='0' name='Authenticate' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='AntiCollision' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='184' flags='0' />
		<view type='0' name='Sleep' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='SendToTag' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='186' flags='0' />
		<view type='0' name='AntennaOn' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='AntennaOff' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='ReadReg' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='ClearBitReg' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='WriteReg' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='SetBitReg' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
		<view type='0' name='Initialise' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='248' flags='0' />
		<view type='0' name='Reset' mode='0' placement='LAAAAAAAAAABAAAA---------------------wAAAAAUAAAASwUAAJEDAAA' zoom='75' scrollx='0' scrolly='0' flags='0' />
	</layout>
</document>
</root>
